JDK-8324969 : C2: prevent elimination of unbalanced coarsened locking regions
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17.0.10,21,23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-01-25
  • Updated: 2024-06-18
  • Resolved: 2024-02-28
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 23
21.0.5-oracleFixed 23 b12Fixed
Related Reports
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
# JRE version: OpenJDK Runtime Environment (17.0.11) (fastdebug build 17.0.11-internal+0-adhoc.user.jdk17u-dev)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 17.0.11-internal+0-adhoc.user.jdk17u-dev, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)

A DESCRIPTION OF THE PROBLEM :
Running the following test case with the fastdebug version of jdk17u-dev results in a crash without any additional options. This situation occurs approximately once in every 10 executions.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
java Test

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Runs normally and finishes within one second.
ACTUAL -
[0.375s][error][monitorinflation] ERROR: ObjectMonitor::exit(): thread=0x00007fc98c029930 is exiting an ObjectMonitor it does not own.
[0.376s][error][monitorinflation] The imbalance is possibly caused by JNI locking.
[0.376s][error][monitorinflation] (ObjectMonitor*) 0x00007fc98c6a48e0 = {
[0.376s][error][monitorinflation]   _header = 0x0000007f63425a01
[0.376s][error][monitorinflation]   _object = 0x0000000101f19200
[0.376s][error][monitorinflation]   _pad_buf0 = {
[0.376s][error][monitorinflation]     [0] = '\0'
[0.376s][error][monitorinflation]     ...
[0.376s][error][monitorinflation]     [47] = '\0'
[0.376s][error][monitorinflation]   }
[0.376s][error][monitorinflation]   _owner = 0x0000000000000000
[0.376s][error][monitorinflation]   _previous_owner_tid = 0
[0.376s][error][monitorinflation]   _pad_buf1 = {
[0.376s][error][monitorinflation]     [0] = '\0'
[0.376s][error][monitorinflation]     ...
[0.376s][error][monitorinflation]     [47] = '\0'
[0.376s][error][monitorinflation]   }
[0.376s][error][monitorinflation]   _next_om = 0x00007fc8e8000fd0
[0.376s][error][monitorinflation]   _recursions = 0
[0.376s][error][monitorinflation]   _EntryList = 0x0000000000000000
[0.376s][error][monitorinflation]   _cxq = 0x0000000000000000
[0.376s][error][monitorinflation]   _succ = 0x0000000000000000
[0.376s][error][monitorinflation]   _Responsible = 0x0000000000000000
[0.376s][error][monitorinflation]   _Spinner = 0
[0.376s][error][monitorinflation]   _SpinDuration = 5000
[0.376s][error][monitorinflation]   _contentions = 0
[0.376s][error][monitorinflation]   _WaitSet = 0x0000000000000000
[0.376s][error][monitorinflation]   _waiters = 0
[0.376s][error][monitorinflation]   _WaitSetLock = 0
[0.376s][error][monitorinflation] }
# To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/objectMonitor.cpp:1158
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/data/user/jdk17u-dev/src/hotspot/share/runtime/objectMonitor.cpp:1158), pid=17712, tid=17713
#  assert(false) failed: Non-balanced monitor enter/exit!
#
# JRE version: OpenJDK Runtime Environment (17.0.11) (fastdebug build 17.0.11-internal+0-adhoc.xiezf.jdk17u-dev)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 17.0.11-internal+0-adhoc.xiezf.jdk17u-dev, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x138952f]  ObjectMonitor::exit(JavaThread*, bool)+0x54f
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /data/user/proj/toreport/Test2887_01_22_13_20_15/reduce/hs_err_pid17712.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#


---------- BEGIN SOURCE ----------
class Test {
   public static final int N = 256;
   public long instanceCount;
   static short sFld = 32330;

   static void vMeth() {
      short[] sArr = new short[N];
   }

   long lMeth(int i11, long l) {
      int i12;
      for (i12 = 1; 204 > i12; ++i12)
         vMeth();
      long meth_res = i11;
      return meth_res;
   }

   static synchronized int method47(int var1, int var2) {
      return var1;
   }

   static synchronized int method71(int var) {
      return var;
   }

   boolean bMeth(int i2, int i3) {
      int i4;
      synchronized (Test.class) {
         int i7 = 4;
         int i8;
         for (i4 = 5; i4 < 118; i4++)
            for (i8 = 1; i8 < 5; i8++)
               switch (63) {
                  case 63:
                     int var18 = 0;
                     while (var18 < 20000)
                        var18++;
                  case 64:
                     switch (48) {
                        case 48:
                           sFld = (short) lMeth(i7, instanceCount);
                        case 50:
                           for (int var27 = 2; var27 < 8; var27 += 2)
                              for (int var28 = 1;;) {
                                 int var29 = method47(var27, var28);
                                 int var30 = var27 + method71(var28);
                                 break;
                              }
                     }
               }
         long meth_res = i3;
         return meth_res > 0;
      }
   }

   void mainTest(String[] strArr1) {
      int i1 = -9;
      for (int i = 0; i < 1000; ++i) {
         if (bMeth(6, i1))
            break;
      }
   }

   public static void main(String[] strArr) {
      Test _instance = new Test();
      _instance.mainTest(strArr);
   }
}
---------- END SOURCE ----------

FREQUENCY : often



Comments
[jdk21u-fix-request] Approval Request from Martin Should get backported for parity with 21.0.25-oracle. It is recognized as clean backport and tier 1-4 have passed.
13-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/700 Date: 2024-06-12 10:19:55 +0000
12-06-2024

Changeset: b938a5c9 Author: Vladimir Kozlov <kvn@openjdk.org> Date: 2024-02-28 16:04:47 +0000 URL: https://git.openjdk.org/jdk/commit/b938a5c9edd53821a52b43a8e342b76adb341a3f
28-02-2024

Performance testing finished. I don't see anything alarming.
25-02-2024

Got failure because after loop unroll we can find again coarsened locks in Unbalanced locking regions.
21-02-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17697 Date: 2024-02-03 21:56:25 +0000
03-02-2024

I attached simplified test.
03-02-2024

ILW = Same as JDK-8322743 = P3
31-01-2024

With JDK 23 I'm hitting (fails since JDK-8286957 in JDK 20): # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/workspace/open/src/hotspot/share/runtime/javaThread.cpp:1953), pid=339206, tid=339207 # assert(_held_monitor_count >= 0) failed: Must always be greater than 0: -45185988 # # JRE version: Java(TM) SE Runtime Environment (23.0+4) (fastdebug build 23-ea+4-173) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 23-ea+4-173, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0xebbedc] JavaThread::inc_held_monitor_count(long, bool)+0x8c Stack: [0x00007fa818ee8000,0x00007fa818fe9000], sp=0x00007fa818fe7c20, free space=1023k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0xebbedc] JavaThread::inc_held_monitor_count(long, bool)+0x8c (javaThread.cpp:1953) V [libjvm.so+0x173ae0a] ObjectSynchronizer::enter(Handle, BasicLock*, JavaThread*)+0xba V [libjvm.so+0xec0855] JavaThread::exit(bool, JavaThread::ExitType)+0x405 V [libjvm.so+0xf9416a] jni_DetachCurrentThread+0xda C [libjli.so+0x4a1f] JavaMain+0xdef C [libjli.so+0x7ca9] ThreadJavaMain+0x9 The proposed fix for JDK-8324174 does not seem to fix the issue.
31-01-2024

No, it is not JDK-8324174 and not JDK-8322743. I tested both fixes and test still fail. With JDK 23 the assert is different (we have monitors count now): # Internal Error (/Users/vkozlov/work/leyden/src/hotspot/share/runtime/javaThread.cpp:1961), pid=24650, tid=7939 # assert(_held_monitor_count >= 0) failed: Must always be greater than 0: -450192 Test passed with -XX:-EliminateNestedLocks. Looking on -XX:+PrintEliminatedLocks show that C2 eliminates one Nested lock but there is not corresponding unlock: === Coarsened 1 unlocks and 1 locks === Coarsened 1 unlocks and 1 locks === Coarsened 1 unlocks and 1 locks ++++ Eliminated: 729 Unlock 'Coarsened' ++++ Eliminated: 722 Unlock 'Coarsened' ++++ Eliminated: 708 Lock 'Coarsened' ++++ Eliminated: 699 Lock 'Coarsened' ++++ Eliminated: 670 Unlock 'Coarsened' ++++ Eliminated: 663 Unlock 'Coarsened' ++++ Eliminated: 649 Lock 'Coarsened' ++++ Eliminated: 475 Lock 'Coarsened' ++++ Eliminated: 460 Unlock 'Coarsened' ++++ Eliminated: 446 Lock 'Coarsened' ++++ Eliminated: 640 Lock 'Nested' Running with -Xbatch test passed and eliminate locks do not have `Nested` eliminated.
31-01-2024

This seems similar to a number of compiler issues related to escape-analysis and lock-elision where deopt is not locking things properly. e.g. JDK-8324174
31-01-2024

With fast debug issue is intermittent. # ./fastdebug/bin/java -showversion Test java version "17.0.11-ea" 2024-04-16 LTS Java(TM) SE Runtime Environment (fastdebug build 17.0.11-ea+2-LTS-178) Java HotSpot(TM) 64-Bit Server VM (fastdebug build 17.0.11-ea+2-LTS-178, mixed mode, sharing) # ./fastdebug/bin/java -showversion Test java version "17.0.11-ea" 2024-04-16 LTS Java(TM) SE Runtime Environment (fastdebug build 17.0.11-ea+2-LTS-178) Java HotSpot(TM) 64-Bit Server VM (fastdebug build 17.0.11-ea+2-LTS-178, mixed mode, sharing) [0.265s][error][monitorinflation] ERROR: ObjectMonitor::exit(): thread=0x00007f4540027bd0 is exiting an ObjectMonitor it does not own. [0.265s][error][monitorinflation] The imbalance is possibly caused by JNI locking. [0.265s][error][monitorinflation] (ObjectMonitor*) 0x00007f45401870e0 = { [0.265s][error][monitorinflation] _header = 0x0000002c7b84de09 [0.265s][error][monitorinflation] _object = 0x00000000c79704c8 [0.265s][error][monitorinflation] _pad_buf0 = { [0.265s][error][monitorinflation] [0] = '\0' [0.265s][error][monitorinflation] ... [0.265s][error][monitorinflation] [47] = '\0' [0.265s][error][monitorinflation] } [0.265s][error][monitorinflation] _owner = 0x0000000000000000 [0.265s][error][monitorinflation] _previous_owner_tid = 0 [0.265s][error][monitorinflation] _pad_buf1 = { [0.265s][error][monitorinflation] [0] = '\0' [0.265s][error][monitorinflation] ... [0.265s][error][monitorinflation] [47] = '\0' [0.265s][error][monitorinflation] } [0.265s][error][monitorinflation] _next_om = 0x00007f44d8000e50 [0.265s][error][monitorinflation] _recursions = 0 [0.265s][error][monitorinflation] _EntryList = 0x0000000000000000 [0.265s][error][monitorinflation] _cxq = 0x0000000000000000 [0.265s][error][monitorinflation] _succ = 0x0000000000000000 [0.265s][error][monitorinflation] _Responsible = 0x0000000000000000 [0.265s][error][monitorinflation] _Spinner = 0 [0.265s][error][monitorinflation] _SpinDuration = 0 [0.265s][error][monitorinflation] _contentions = 0 [0.265s][error][monitorinflation] _WaitSet = 0x0000000000000000 [0.265s][error][monitorinflation] _waiters = 0 [0.265s][error][monitorinflation] _WaitSetLock = 0 [0.265s][error][monitorinflation] } # To suppress the following error report, specify this argument # after -XX: or in .hotspotrc: SuppressErrorAt=/objectMonitor.cpp:1171 # # A fatal error has been detected by the Java Runtime Environment: # # Internal Error (/opt/mach5/mesos/work_dir/slaves/0db9c48f-6638-40d0-9a4b-bd9cc7533eb8-S9871/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/f91d9a46-974d-4557-9d6c-a78a6ab54a5f/runs/13c30673-1462-4e78-9ca1-2c9854a3a18a/workspace/open/src/hotspot/share/runtime/objectMonitor.cpp:1171), pid=4047, tid=4048 # assert(false) failed: Non-balanced monitor enter/exit! # # JRE version: Java(TM) SE Runtime Environment (17.0.11+2) (fastdebug build 17.0.11-ea+2-LTS-178) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 17.0.11-ea+2-LTS-178, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, serial gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x1583fb5] ObjectMonitor::exit(JavaThread*, bool)+0x615 # # Core dump will be written. Default location: Core dumps may be processed with "/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e %P %I %h" (or dumping to /webbug/core.4047) # # An error report file with more information is saved as: # /webbug/hs_err_pid4047.log # # If you would like to submit a bug report, please visit: # https://bugreport.java.com/bugreport/crash.jsp # Aborted (core dumped) # ./fastdebug/bin/java -showversion Test (no Crash) java version "17.0.11-ea" 2024-04-16 LTS Java(TM) SE Runtime Environment (fastdebug build 17.0.11-ea+2-LTS-178) Java HotSpot(TM) 64-Bit Server VM (fastdebug build 17.0.11-ea+2-LTS-178, mixed mode, sharing) # # ./fastdebug/bin/java -showversion -XX:SuppressErrorAt=/objectMonitor.cpp:1171 Test (No crash) java version "17.0.11-ea" 2024-04-16 LTS Java(TM) SE Runtime Environment (fastdebug build 17.0.11-ea+2-LTS-178) Java HotSpot(TM) 64-Bit Server VM (fastdebug build 17.0.11-ea+2-LTS-178, mixed mode, sharing) # ./fastdebug/bin/java -showversion -XX:SuppressErrorAt=/objectMonitor.cpp:1171 Test java version "17.0.11-ea" 2024-04-16 LTS Java(TM) SE Runtime Environment (fastdebug build 17.0.11-ea+2-LTS-178) Java HotSpot(TM) 64-Bit Server VM (fastdebug build 17.0.11-ea+2-LTS-178, mixed mode, sharing) # Need to confirm if there is a too restrictive assertion ?
26-01-2024