JDK-8314580 : PhaseIdealLoop::transform_long_range_checks fails with assert "was tested before"
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-08-18
  • Updated: 2024-01-09
  • Resolved: 2023-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22
21.0.2Fixed 22 b14Fixed
Related Reports
Relates :  
Description
This code crashes the JVM:

public class CrashExample {
    private static final VarHandle byteHandle = MethodHandles.memorySegmentViewVarHandle(ValueLayout.JAVA_BYTE);
    private static final long len = 100;
    private static final byte CR = (byte) '\r';
    private static final byte LF = (byte) '\n';

    public static void main(String[] args) {
        for(int round = 0; round < 1000; round++) {
            try(Arena arena = Arena.ofConfined()) {
                MemorySegment memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE, len);
                for(int i = 0; i < 100000; i++) {
                    int index = i % 99;
                    byteHandle.set(memorySegment, index, CR);
                    byteHandle.set(memorySegment, index + 1, LF);
                    byte[] bytes = readUntil(memorySegment, CR, LF);
                }
            }
        }
    }

    private static byte[] readUntil(MemorySegment segment, byte... separators) {
        for(long cur = 0; cur <= segment.byteSize() - separators.length; cur++) {
            if(matches(segment, cur, separators)) {
                return segment.asSlice(0, cur).toArray(ValueLayout.JAVA_BYTE);
            }
        }
        return null;
    }

    public static boolean matches(MemorySegment m, long offset, byte[] bytes) {
        for(int index = 0; index < bytes.length; index++) {
            if ((byte) byteHandle.get(m, offset + index) != bytes[index]) {
                return false;
            }
        }
        return true;
    }
}

# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/oracle/jdk/open/src/hotspot/share/opto/loopnode.cpp:1269), pid=1045773, tid=1045790
#  assert(ok) failed: inconsistent: was tested before
#
# JRE version: Java(TM) SE Runtime Environment (22.0) (fastdebug build 22-internal-2023-08-07-1346088.tobias...)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-internal-2023-08-07-1346088.tobias..., mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x1292fe2]  PhaseIdealLoop::transform_long_range_checks(int, Node_List const&, Node*, Node*, Node*, Node*, LoopNode*)+0x1272

Current CompileTask:
C2:    752  589 % !   4       CrashExample::main @ 29 (136 bytes)

Stack: [0x00007f072267e000,0x00007f072277f000],  sp=0x00007f0722779b20,  free space=1006k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x1292fe2]  PhaseIdealLoop::transform_long_range_checks(int, Node_List const&, Node*, Node*, Node*, Node*, LoopNode*)+0x1272  (loopnode.cpp:1269)
V  [libjvm.so+0x129862e]  PhaseIdealLoop::create_loop_nest(IdealLoopTree*, Node_List&)+0xf4e  (loopnode.cpp:1047)
V  [libjvm.so+0x126f388]  IdealLoopTree::iteration_split_impl(PhaseIdealLoop*, Node_List&)+0x318  (loopTransform.cpp:3602)
V  [libjvm.so+0x126f6b7]  IdealLoopTree::iteration_split(PhaseIdealLoop*, Node_List&)+0x117  (loopTransform.cpp:3726)
V  [libjvm.so+0x126f5d3]  IdealLoopTree::iteration_split(PhaseIdealLoop*, Node_List&)+0x33  (loopTransform.cpp:3710)
V  [libjvm.so+0x129d6d7]  PhaseIdealLoop::build_and_optimize()+0xca7  (loopnode.cpp:4604)
V  [libjvm.so+0x9eff5e]  PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x3ce  (loopnode.hpp:1114)
V  [libjvm.so+0x9ec9ef]  Compile::Optimize()+0xdaf  (compile.cpp:2166)
V  [libjvm.so+0x9eed10]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b60  (compile.cpp:850)
V  [libjvm.so+0x84a5db]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x13b  (c2compiler.cpp:119)
V  [libjvm.so+0x9fac37]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x977  (compileBroker.cpp:2276)
V  [libjvm.so+0x9fb978]  CompileBroker::compiler_thread_loop()+0x5f8  (compileBroker.cpp:1944)
V  [libjvm.so+0xeb883c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:720)
V  [libjvm.so+0x179b04a]  Thread::call_run()+0xba  (thread.cpp:217)
V  [libjvm.so+0x1499d01]  thread_native_entry(Thread*)+0x121  (os_linux.cpp:783)

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f3f941154b7, pid=1045889, tid=1045906
#
# JRE version: Java(TM) SE Runtime Environment (22.0) (build 22-internal-2023-08-09-1155514.tobias...)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (22-internal-2023-08-09-1155514.tobias..., mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x4084b7]  AddNode::IdealIL(PhaseGVN*, bool, BasicType)+0x37

Current CompileTask:
C2:    405  632 % !   4       CrashExample::main @ 29 (136 bytes)

Stack: [0x00007f3f65eff000,0x00007f3f66000000],  sp=0x00007f3f65ffb7e0,  free space=1009k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x4084b7]  AddNode::IdealIL(PhaseGVN*, bool, BasicType)+0x37  (addnode.cpp:265)
V  [libjvm.so+0xd11bde]  PhaseIterGVN::transform_old(Node*)+0x9e  (phaseX.cpp:667)
V  [libjvm.so+0xd0db09]  PhaseIterGVN::optimize()+0xf9  (phaseX.cpp:1045)
V  [libjvm.so+0x6445af]  Compile::Optimize()+0x151f  (loopnode.hpp:1199)
V  [libjvm.so+0x6456c2]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0xed2  (compile.cpp:850)
V  [libjvm.so+0x574079]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x159  (c2compiler.cpp:119)
V  [libjvm.so+0x64b2fe]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0xa9e  (compileBroker.cpp:2276)
V  [libjvm.so+0x64e558]  CompileBroker::compiler_thread_loop()+0x698  (compileBroker.cpp:1944)
V  [libjvm.so+0x8f8038]  JavaThread::thread_main_inner() [clone .part.0]+0xb8  (javaThread.cpp:720)
V  [libjvm.so+0xe9aa18]  Thread::call_run()+0xa8  (thread.cpp:217)
V  [libjvm.so+0xcbfaaa]  thread_native_entry(Thread*)+0xda  (os_linux.cpp:783)
Comments
[jdk21u-fix-request] Approval Request from Aleksey Shipilëv Clean backport to improve C2 stability. Applies cleanly. Testing passed.
02-11-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/316 Date: 2023-11-01 16:53:00 +0000
01-11-2023

Changeset: 9def4538 Author: Roland Westrelin <roland@openjdk.org> Date: 2023-09-04 15:18:39 +0000 URL: https://git.openjdk.org/jdk/commit/9def4538ab5456d689fd289bdef66fd1655773bc
04-09-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15411 Date: 2023-08-24 07:57:34 +0000
24-08-2023

Looks like an issue with JDK-8259609, we hit an assert in debug. I attached the test and hs_err file. ILW = Assert/crash during C2 compilation, reproducible with preview feature, no workaround but disabled compilation of affected method = HLM = P3
21-08-2023

A dump can be found here: https://mail.openjdk.org/pipermail/panama-dev/attachments/20230818/66bd174d/hs_err_pid5133-0001.log
18-08-2023

This fails with: ``` # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007fb978353e7b, pid=460689, tid=460729 # # JRE version: OpenJDK Runtime Environment (22.0) (build 22-internal-adhoc.maurizio.dev) # Java VM: OpenJDK 64-Bit Server VM (22-internal-adhoc.maurizio.dev, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x42fe7b] AddNode::IdealIL(PhaseGVN*, bool, BasicType)+0x3b # # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /w/misc/panama-test/MemAccess/core.460689) ```
18-08-2023