Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8329726

Use non-short forward jumps in lightweight locking

XMLWordPrintable

    • 23
    • b18

      The following Dacapo run triggers a guarantee very quickly. Dacapo may be found at https://www.dacapobench.org/.

      Command:
      ```
      $JAVA_HOME/bin/java -XX:+ShowMessageBoxOnError -Xms2g -Xmx2g -XX:CICompilerCount=2 -jar dacapo-23.11-chopin.jar --scratch-directory ./tmp/dacapo-scratch/eclipse4 --no-validation --iterations 5 eclipse
      ```

      Guarantee violation:
      ```
      Version: eclipse 4.27 (use -p to print nominal benchmark stats)
      ==============================================================================
      Unexpected Error
      ------------------------------------------------------------------------------
      Internal Error at macroAssembler_x86.hpp:122, pid=51834, tid=51849
      guarantee(this->is8bit(imm8)) failed: Short forward jump exceeds 8-bit offset at src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp:1011

      Do you want to debug the problem?

      To debug, run 'gdb /proc/51834/exe 51834'; then switch to thread 51849 (0x000000000000ca89)
      Enter 'yes' to launch gdb automatically (PATH must include gdb)
      Otherwise, press RETURN to abort...

      ```


      Stack Retrace:
      ```
      #0 0x00007f85698d95f3 in __libc_read (fd=0, buf=0x7f853e3df1f0, nbytes=16) at ../sysdeps/unix/sysv/linux/read.c:26
      #1 0x00007f8567d6692c in os::message_box (title=0x7f8568a0b1ab "Unexpected Error",
          message=0x7f856950f7a0 <VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)::buffer> "Internal Error at macroAssembler_x86.hpp:122, pid=51834, tid=51849\nguarantee(this->is8bit(imm8)) failed: Short forward jump exceeds 8-bit offset at src/hotsp"...) at src/hotspot/os/posix/os_posix.cpp:1983
      #2 0x00007f8567d5b0c0 in os::start_debugging (
          buf=0x7f856950f7a0 <VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)::buffer> "Internal Error at macroAssembler_x86.hpp:122, pid=51834, tid=51849\nguarantee(this->is8bit(imm8)) failed: Short forward jump exceeds 8-bit offset at src/hotsp"..., buflen=2000) at src/hotspot/os/linux/os_linux.cpp:5392
      #3 0x00007f856811319d in VMError::show_message_box (
          buf=0x7f856950f7a0 <VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)::buffer> "Internal Error at macroAssembler_x86.hpp:122, pid=51834, tid=51849\nguarantee(this->is8bit(imm8)) failed: Short forward jump exceeds 8-bit offset at src/hotsp"..., buflen=2000) at src/hotspot/share/utilities/vmError.cpp:2003
      #4 0x00007f856811233f in VMError::report_and_die (id=-536870912, message=0x7f8568311a60 "guarantee(this->is8bit(imm8)) failed",
          detail_fmt=0x7f8568311a28 "Short forward jump exceeds 8-bit offset at %s:%d", detail_args=0x7f853e3df518, thread=0x7f8560af1440, pc=0x0, siginfo=0x0,
          context=0x7f85694a77c0 <g_stored_assertion_context>, filename=0x7f85683119c8 "src/hotspot/cpu/x86/macroAssembler_x86.hpp",
          lineno=122, size=0) at src/hotspot/share/utilities/vmError.cpp:1691
      #5 0x00007f8568112073 in VMError::report_and_die (thread=0x7f8560af1440, context=0x7f85694a77c0 <g_stored_assertion_context>,
          filename=0x7f85683119c8 "src/hotspot/cpu/x86/macroAssembler_x86.hpp", lineno=122,
          message=0x7f8568311a60 "guarantee(this->is8bit(imm8)) failed", detail_fmt=0x7f8568311a28 "Short forward jump exceeds 8-bit offset at %s:%d", detail_args=0x7f853e3df518)
          at src/hotspot/share/utilities/vmError.cpp:1610
      #6 0x00007f8567485ed4 in report_vm_error (file=0x7f85683119c8 "src/hotspot/cpu/x86/macroAssembler_x86.hpp", line=122,
          error_msg=0x7f8568311a60 "guarantee(this->is8bit(imm8)) failed", detail_fmt=0x7f8568311a28 "Short forward jump exceeds 8-bit offset at %s:%d")
          at src/hotspot/share/utilities/debug.cpp:193
      #7 0x00007f85670d77be in MacroAssembler::pd_patch_instruction (this=0x7f853e3dfa50, branch=0x7f8558793d71 "u",
          target=0x7f8558793df7 '\314' <repeats 199 times>, <incomplete sequence \314>...,
          file=0x7f85683c09d0 "src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp", line=1011)
          at src/hotspot/cpu/x86/macroAssembler_x86.hpp:122
      #8 0x00007f85670d6e3d in Label::patch_instructions (this=0x7f853e3df860, masm=0x7f853e3dfa50)
          at src/hotspot/share/asm/assembler.cpp:201
      #9 0x00007f85670d6af6 in AbstractAssembler::bind (this=0x7f853e3dfa50, L=...) at src/hotspot/share/asm/assembler.cpp:120
      #10 0x00007f8567299f76 in C2_MacroAssembler::fast_lock_lightweight (this=0x7f853e3dfa50, obj=..., box=..., rax_reg=..., t=..., thread=...)
          at src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp:1029
      #11 0x00007f8566e94a3e in cmpFastLockLightweightNode::emit (this=0x7f85613cab68, cbuf=..., ra_=0x7f853e3e0090)
          at src/hotspot/cpu/x86/x86_64.ad:12292
      #12 0x00007f8567d7153c in PhaseOutput::fill_buffer (this=0x7f853e3e0290, cb=0x7f853e3e02a8, blk_starts=0x7f85007b5270)
          at src/hotspot/share/opto/output.cpp:1698
      #13 0x00007f8567d6b732 in PhaseOutput::Output (this=0x7f853e3e0290) at src/hotspot/share/opto/output.cpp:366
      #14 0x00007f85673f378e in Compile::Code_Gen (this=0x7f853e3e18a0) at src/hotspot/share/opto/compile.cpp:3031
      #15 0x00007f85673e9987 in Compile::Compile (this=0x7f853e3e18a0, ci_env=0x7f853e3e26f0, target=0x7f8500791ef0, osr_bci=-1, options=..., directive=0x7f85609c5310)
          at src/hotspot/share/opto/compile.cpp:894
      #16 0x00007f85672b9e11 in C2Compiler::compile_method (this=0x7f8560af0e50, env=0x7f853e3e26f0, target=0x7f8500791ef0, entry_bci=-1, install_code=true,
          directive=0x7f85609c5310) at src/hotspot/share/opto/c2compiler.cpp:142
      #17 0x00007f856740b94b in CompileBroker::invoke_compiler_on_method (task=0x7f8560bf4140)
          at src/hotspot/share/compiler/compileBroker.cpp:2304
      #18 0x00007f856740a461 in CompileBroker::compiler_thread_loop () at src/hotspot/share/compiler/compileBroker.cpp:1963
      #19 0x00007f8567428b9a in CompilerThread::thread_entry (thread=0x7f8560af1440, __the_thread__=0x7f8560af1440)
          at src/hotspot/share/compiler/compilerThread.cpp:68
      #20 0x00007f8567851706 in JavaThread::thread_main_inner (this=0x7f8560af1440) at src/hotspot/share/runtime/javaThread.cpp:759
      #21 0x00007f85678515ac in JavaThread::run (this=0x7f8560af1440) at src/hotspot/share/runtime/javaThread.cpp:744
      #22 0x00007f8568064a2e in Thread::call_run (this=0x7f8560af1440) at src/hotspot/share/runtime/thread.cpp:221
      #23 0x00007f8567d5016e in thread_native_entry (thread=0x7f8560af1440) at src/hotspot/os/linux/os_linux.cpp:853
      #24 0x00007f85698d044b in start_thread (arg=0x7f853e3e3700) at pthread_create.c:465
      #25 0x00007f856960b52f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      ```

      Fix: Roughly like:

      ```
      diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
      index b6ecde62af6..84ba7261f56 100644
      --- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
      +++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
      @@ -1008,7 +1008,8 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist
       
           // Check if recursive.
           cmpptr(thread, rax_reg);
      - jccb(Assembler::notEqual, slow_path);
      + // ysr: jccb(Assembler::notEqual, slow_path);
      + jcc(Assembler::notEqual, slow_path);
       
           // Recursive.
           increment(Address(tagged_monitor, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions)));
      @@ -1022,7 +1023,8 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist
       #ifdef ASSERT
         // Check that locked label is reached with ZF set.
         Label zf_correct;
      - jccb(Assembler::zero, zf_correct);
      + // ysr: jccb(Assembler::zero, zf_correct);
      + jcc(Assembler::zero, zf_correct);
         stop("Fast Lock ZF != 1");
       #endif
       
      @@ -1161,7 +1163,8 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax,
       #ifdef ASSERT
         // Check that unlocked label is reached with ZF set.
         Label zf_correct;
      - jccb(Assembler::zero, zf_correct);
      + // ysr: jccb(Assembler::zero, zf_correct);
      + jcc(Assembler::zero, zf_correct);
         stop("Fast Unlock ZF != 1");
       #endif
      ```

      I was a bit surprised this hasn't been flagged in earlier testing already. I don't know how long it has been in JDK tip, but we became aware of it this week in the GenShen project upon sync'ing from tip jdk.

      The fix was suggested by Roman and fixed the issue. I am assigning it to Roman as he's aware of the report and the fix, and the error proximately fingers fast-locking from my naive examination of the backtrace.

      Thanks!

            rkennke Roman Kennke
            ysr Y. Ramakrishna
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: