Impossible (?) code path resulting in IllegalStateException on jdk14+

Dawid Weiss dawid.weiss at gmail.com
Thu Dec 10 16:25:15 UTC 2020


Hello,

I'm scratching my head again over a bug we encountered in randomized
tests. The code is quite complex so before I start to try to isolate I
thought I'd ask if it rings a bell for anybody.

The bug is reproducible for certain seeds but happens only after some
VM warmup - the same test is executed a few dozen times, then the
problem starts showing up. This only happens on jdk 14 and jdk 15
(didn't test on jdk 16 branch). Looks like something related to OSR/
compilation races.

In the end, we get this exception:

java.lang.IllegalMonitorStateException
at java.base/java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:175)
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1006)
at java.base/java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:494)
at java.base/java.util.concurrent.ArrayBlockingQueue.put(ArrayBlockingQueue.java:373)
[stack omitted]

This doesn't seem possible from Java code alone -- it's this snippet
in ArrayBlockingQueue:

lock.lockInterruptibly();
try {
    while (count == items.length)
        notFull.await();
    enqueue(e);
} finally {
   lock.unlock();     // <<< bam...
}

If the code entered the lock-protected block it should never throw
IllegalMonitorStateException, right?

I'll start digging in spare moments but hints at how to isolate this/
verify what this can be (other than bisecting git repo) would be very
welcome!

Dawid


More information about the hotspot-dev mailing list