8341819: LightweightSynchronizer::enter_for races with deflation

Reviewed-by: pchilanomate, rkennke
This commit is contained in:
Axel Boldt-Christmas 2024-10-10 17:02:54 +00:00
parent 4beb77192f
commit 6fad6af0de
2 changed files with 18 additions and 2 deletions

View File

@ -635,8 +635,11 @@ void LightweightSynchronizer::enter_for(Handle obj, BasicLock* lock, JavaThread*
bool entered = monitor->enter_for(locking_thread);
assert(entered, "recursive ObjectMonitor::enter_for must succeed");
} else {
// It is assumed that enter_for must enter on an object without contention.
monitor = inflate_and_enter(obj(), ObjectSynchronizer::inflate_cause_monitor_enter, locking_thread, current);
do {
// It is assumed that enter_for must enter on an object without contention.
monitor = inflate_and_enter(obj(), ObjectSynchronizer::inflate_cause_monitor_enter, locking_thread, current);
// But there may still be a race with deflation.
} while (monitor == nullptr);
}
assert(monitor != nullptr, "LightweightSynchronizer::enter_for must succeed");

View File

@ -158,6 +158,19 @@
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=0
* -XX:GuaranteedAsyncDeflationInterval=1000
*
* @bug 8341819
* @comment Regression test for re-locking racing with deflation with LM_LIGHTWEIGHT.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* -XX:GuaranteedAsyncDeflationInterval=1
*/
/**