RFR: 8322743: assert(held_monitor_count() == jni_monitor_count()) failed

Vladimir Kozlov kvn at openjdk.org
Tue Jan 9 23:36:40 UTC 2024


Corner case with a local (not escaped) object used for synchronization. C2 Escape Analysis thinks that it can eliminate locks for it. In most cases it is true but not in this case.


        for (int i = 0; i < 2; ++i) {
            Object o = new Object();
            synchronized (o) { // monitorenter
                // Trigger OSR compilation
                for (int j = 0; j < 100_000; ++j) {

The test has nested loop which trigger OSR compilation. The locked object comes from Interpreter into compiled OSR code. During parsing C2 creates an other non escaped object and correctly merge both together (with Phi node) so that non escaped object is not scalar replaceable. Because it does not globally escapes EA still removes locks for it and, as result, also for merged locked object from Interpreter which is the bug.

The fix is to check that synchronized block does not have any associated escaped objects when EA decides if locks can be eliminated.

Added regression test prepared by @TobiHartmann. Tested tier1-5, xcomp and stress.
Performance testing show no difference.

-------------

Commit messages:
 - Fix trailing and other spaces.
 - 8322743: assert(held_monitor_count() == jni_monitor_count()) failed

Changes: https://git.openjdk.org/jdk/pull/17331/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17331&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8322743
  Stats: 132 lines in 6 files changed: 115 ins; 2 del; 15 mod
  Patch: https://git.openjdk.org/jdk/pull/17331.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17331/head:pull/17331

PR: https://git.openjdk.org/jdk/pull/17331


More information about the hotspot-compiler-dev mailing list