Skip to content

Commit

Permalink
Reproducer for JDK-8337318
Browse files Browse the repository at this point in the history
  • Loading branch information
reinrich committed Aug 12, 2024
1 parent 692f5cb commit 8863ffc
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions test/jdk/com/sun/jdi/EATests.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public static void main(String[] args) {

// Relocking test cases
new EARelockingSimpleTarget() .run();
new EARelockingWithManyLightweightLocksTarget() .run();
new EARelockingSimpleWithAccessInOtherThreadTarget() .run();
new EARelockingSimpleWithAccessInOtherThread_02_DynamicCall_Target() .run();
new EARelockingRecursiveTarget() .run();
Expand Down Expand Up @@ -413,6 +414,7 @@ protected void runTests() throws Exception {

// Relocking test cases
new EARelockingSimple() .run(this);
new EARelockingWithManyLightweightLocks() .run(this);
new EARelockingSimpleWithAccessInOtherThread() .run(this);
new EARelockingSimpleWithAccessInOtherThread_02_DynamicCall() .run(this);
new EARelockingRecursive() .run(this);
Expand Down Expand Up @@ -1797,6 +1799,86 @@ public void dontinline_testMethod() {

/////////////////////////////////////////////////////////////////////////////

/**
* Like {@link EARelockingSimple}. The difference is that there are many
* lightweight locked objects when the relocking is done. With
* <code>-XX:LockingMode=2</code> the lock stack of the thread will be full
* because of this.
*/

class EARelockingWithManyLightweightLocks extends EATestCaseBaseDebugger {

public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "l1");
}
}

class EARelockingWithManyLightweightLocksTarget extends EATestCaseBaseTarget {

static class Lock {
}

public static Lock L0, L1, L2, L3, L4, L5, L6, L7, L8, L9;


void allocateLocks() {
L0 = new Lock();
L1 = new Lock();
L2 = new Lock();
L3 = new Lock();
L4 = new Lock();
L5 = new Lock();
L6 = new Lock();
L7 = new Lock();
L8 = new Lock();
L9 = new Lock();
}

@Override
public void setUp() {
super.setUp();
allocateLocks();
}

@Override
public void warmupDone() {
super.warmupDone();
allocateLocks(); // get rid of already inflated ones
}

public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized(L0) {
synchronized(L1) {
synchronized(L2) {
synchronized(L3) {
synchronized(L4) {
synchronized(L5) {
synchronized(L6) {
synchronized(L7) {
synchronized(L8) {
synchronized(L9) {
synchronized (l1) {
dontinline_brkpt();
}
}
}
}
}
}
}
}
}
}
}
}
}

/////////////////////////////////////////////////////////////////////////////

// The debugger reads and publishes an object with eliminated locking to an instance field.
// A 2nd thread in the debuggee finds it there and changes its state using a synchronized method.
// Without eager relocking the accesses are unsynchronized which can be observed.
Expand Down

0 comments on commit 8863ffc

Please sign in to comment.