Skip to content

Commit

Permalink
Improve EARelockingNestedInflated_03 for LM_LIGHTWEIGHT
Browse files Browse the repository at this point in the history
  • Loading branch information
reinrich committed Feb 2, 2024
1 parent be717d5 commit 01a592a
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions test/jdk/com/sun/jdi/EATests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1986,26 +1986,40 @@ public void runTestCase() throws Exception {
class EARelockingNestedInflated_03Target extends EATestCaseBaseTarget {

public XYVal lockInflatedByContention;
public volatile boolean doLockNow;
public boolean doLockNow;
public EATestCaseBaseTarget testCase;

@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
lockInflatedByContention = new XYVal(1, 1);
Thread contendingThread = DebuggeeWrapper.newThread(() -> {
while(!doLockNow) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { /* ignored */ }
testCase = this;
}

@Override
public void warmupDone() {
super.warmupDone();
// Use new lock. lockInflatedByContention might have been inflated because of recursion.
lockInflatedByContention = new XYVal(1, 1);
// Start thread that tries to enter lockInflatedByContention while the main thread owns it -> inflation
DebuggeeWrapper.newThread(() -> {
while(true) {
synchronized(testCase) {
try {
if (doLockNow) {
doLockNow = false; // reset for main thread
testCase.notify();
break;
}
testCase.wait();
} catch (InterruptedException e) { /* ignored */ }
}
}
doLockNow = false; // reset for main thread
synchronized(lockInflatedByContention) { // will block and trigger inflation
msg(Thread.currentThread().getName() + ": acquired lockInflatedByContention");
}
}, testCaseName + ": Lock Contender (test thread)");
contendingThread.setDaemon(true);
contendingThread.start();
}, testCaseName + ": Lock Contender (test thread)").start();
}

public void dontinline_testMethod() {
Expand All @@ -2019,18 +2033,24 @@ public void dontinline_testMethod() {

public void testMethod_inlined(XYVal l2) {
synchronized (l2) { // eliminated nested locking
dontinline_setDoLockNow();
dontinline_notifyOtherThread();
dontinline_brkpt();
}
}

public void dontinline_setDoLockNow() {
doLockNow = warmupDone;
public void dontinline_notifyOtherThread() {
if (!warmupDone) {
return;
}
// wait for other thread to reset doLockNow
while(doLockNow) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { /* ignored */ }
synchronized(testCase) {
doLockNow = true;
while(doLockNow) {
testCase.notify();
try {
testCase.wait();
} catch (InterruptedException e) { /* ignored */ }
}
}
}
}
Expand Down

0 comments on commit 01a592a

Please sign in to comment.