Suppose I have 2 adjacent synchronized blocks with a call to Thread.holdsLock() between them:
final Object lock = new Object(); // ... synchronized (lock) { // do stuff } if (Thread.holdsLock(lock)) { throw new IllegalStateException(); } synchronized (lock) { // do more stuff }
Now, what if at some point the JVM decides to coarsen the lock and merge the above synchronized blocks? Will the call to Thread.holdsLock() still return false , or will the code fail with an exception?
source share