Skip to content

Commit 2cceeed

Browse files
Evgeny Nikitinshipilev
authored andcommitted
8166554: Avoid compilation blocking in OverloadCompileQueueTest.java
Reviewed-by: shade
1 parent 188b0bc commit 2cceeed

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

test/hotspot/jtreg/compiler/codecache/stress/OverloadCompileQueueTest.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* java.management
3131
*
3232
* @build sun.hotspot.WhiteBox
33+
* compiler.codecache.stress.TestCaseImpl
3334
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
3435
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
3536
* -XX:+WhiteBoxAPI
@@ -52,8 +53,34 @@
5253
import java.util.stream.IntStream;
5354
import java.util.Random;
5455

55-
public class OverloadCompileQueueTest implements Runnable {
56+
class LockUnlockThread extends Thread {
5657
private static final int MAX_SLEEP = 10000;
58+
private static final int DELAY_BETWEEN_LOCKS = 100;
59+
private final Random rng = Utils.getRandomInstance();
60+
61+
public volatile boolean isActive = true;
62+
63+
@Override
64+
public void run() {
65+
try {
66+
while (isActive) {
67+
int timeInLockedState = rng.nextInt(MAX_SLEEP);
68+
Helper.WHITE_BOX.lockCompilation();
69+
Thread.sleep(timeInLockedState);
70+
Helper.WHITE_BOX.unlockCompilation();
71+
Thread.sleep(DELAY_BETWEEN_LOCKS);
72+
}
73+
} catch (InterruptedException e) {
74+
if (isActive) {
75+
throw new Error("TESTBUG: LockUnlockThread was unexpectedly interrupted", e);
76+
}
77+
} finally {
78+
Helper.WHITE_BOX.unlockCompilation();
79+
}
80+
}
81+
}
82+
83+
public class OverloadCompileQueueTest implements Runnable {
5784
private static final String METHOD_TO_ENQUEUE = "method";
5885
private static final int LEVEL_SIMPLE = 1;
5986
private static final int LEVEL_FULL_OPTIMIZATION = 4;
@@ -62,7 +89,6 @@ public class OverloadCompileQueueTest implements Runnable {
6289
private static final int TIERED_STOP_AT_LEVEL
6390
= Helper.WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();
6491
private static final int[] AVAILABLE_LEVELS;
65-
private final Random rng = Utils.getRandomInstance();
6692
static {
6793
if (TIERED_COMPILATION) {
6894
AVAILABLE_LEVELS = IntStream
@@ -77,15 +103,18 @@ public class OverloadCompileQueueTest implements Runnable {
77103
}
78104
}
79105

80-
public static void main(String[] args) {
106+
public static void main(String[] args) throws InterruptedException {
107+
LockUnlockThread lockUnlockThread = new LockUnlockThread();
108+
lockUnlockThread.start();
109+
81110
if (Platform.isInt()) {
82111
throw new Error("TESTBUG: test can not be run in interpreter");
83112
}
84113
new CodeCacheStressRunner(new OverloadCompileQueueTest()).runTest();
85-
}
86114

87-
public OverloadCompileQueueTest() {
88-
Helper.startInfiniteLoopThread(this::lockUnlock, 100L);
115+
lockUnlockThread.isActive = false;
116+
lockUnlockThread.interrupt();
117+
lockUnlockThread.join();
89118
}
90119

91120
@Override
@@ -105,16 +134,4 @@ public void run() {
105134
}
106135
}
107136

108-
private void lockUnlock() {
109-
try {
110-
int sleep = rng.nextInt(MAX_SLEEP);
111-
Helper.WHITE_BOX.lockCompilation();
112-
Thread.sleep(sleep);
113-
} catch (InterruptedException e) {
114-
throw new Error("TESTBUG: lockUnlocker thread was unexpectedly interrupted", e);
115-
} finally {
116-
Helper.WHITE_BOX.unlockCompilation();
117-
}
118-
}
119-
120137
}

0 commit comments

Comments
 (0)