Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/stress/OverloadCompileQueueTest.java
41153 views
1
/*
2
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test OverloadCompileQueueTest
26
* @key stress randomness
27
* @summary stressing code cache by overloading compile queues
28
* @library /test/lib /
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
*
32
* @build sun.hotspot.WhiteBox
33
* compiler.codecache.stress.TestCaseImpl
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
36
* -XX:+WhiteBoxAPI
37
* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
38
* -XX:-SegmentedCodeCache
39
* compiler.codecache.stress.OverloadCompileQueueTest
40
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
41
* -XX:+WhiteBoxAPI
42
* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
43
* -XX:+SegmentedCodeCache
44
* compiler.codecache.stress.OverloadCompileQueueTest
45
*/
46
47
package compiler.codecache.stress;
48
49
import jdk.test.lib.Platform;
50
import jdk.test.lib.Utils;
51
52
import java.lang.reflect.Method;
53
import java.util.stream.IntStream;
54
import java.util.Random;
55
56
class LockUnlockThread extends Thread {
57
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 {
84
private static final String METHOD_TO_ENQUEUE = "method";
85
private static final int LEVEL_SIMPLE = 1;
86
private static final int LEVEL_FULL_OPTIMIZATION = 4;
87
private static final boolean TIERED_COMPILATION
88
= Helper.WHITE_BOX.getBooleanVMFlag("TieredCompilation");
89
private static final int TIERED_STOP_AT_LEVEL
90
= Helper.WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();
91
private static final int[] AVAILABLE_LEVELS;
92
static {
93
if (TIERED_COMPILATION) {
94
AVAILABLE_LEVELS = IntStream
95
.rangeClosed(LEVEL_SIMPLE, TIERED_STOP_AT_LEVEL)
96
.toArray();
97
} else if (Platform.isServer() && !Platform.isEmulatedClient()) {
98
AVAILABLE_LEVELS = new int[] { LEVEL_FULL_OPTIMIZATION };
99
} else if (Platform.isClient() || Platform.isMinimal() || Platform.isEmulatedClient()) {
100
AVAILABLE_LEVELS = new int[] { LEVEL_SIMPLE };
101
} else {
102
throw new Error("TESTBUG: unknown VM: " + Platform.vmName);
103
}
104
}
105
106
public static void main(String[] args) throws InterruptedException {
107
LockUnlockThread lockUnlockThread = new LockUnlockThread();
108
lockUnlockThread.start();
109
110
if (Platform.isInt()) {
111
throw new Error("TESTBUG: test can not be run in interpreter");
112
}
113
new CodeCacheStressRunner(new OverloadCompileQueueTest()).runTest();
114
115
lockUnlockThread.isActive = false;
116
lockUnlockThread.interrupt();
117
lockUnlockThread.join();
118
}
119
120
@Override
121
public void run() {
122
Helper.TestCase obj = Helper.TestCase.get();
123
Class clazz = obj.getClass();
124
Method mEnqueue;
125
try {
126
mEnqueue = clazz.getMethod(METHOD_TO_ENQUEUE);
127
} catch (NoSuchMethodException | SecurityException e) {
128
throw new Error(String.format(
129
"TESTBUG: cannot get method '%s' of class %s",
130
METHOD_TO_ENQUEUE, clazz.getName()), e);
131
}
132
for (int compLevel : AVAILABLE_LEVELS) {
133
Helper.WHITE_BOX.enqueueMethodForCompilation(mEnqueue, compLevel);
134
}
135
}
136
137
}
138
139