Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/compiler/CodelistTest.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 CodelistTest
26
* @bug 8054889
27
* @library /test/lib /
28
* @modules java.base/jdk.internal.misc
29
* java.compiler
30
* java.management
31
* jdk.internal.jvmstat/sun.jvmstat.monitor
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
* @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -Xmixed -XX:-BackgroundCompilation CodelistTest
35
* @run testng/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-UseCodeCacheFlushing -Xint CodelistTest
36
* @summary Test of diagnostic command Compiler.codelist
37
*
38
* Flag comment:
39
* -XX:-UseCodeCacheFlushing - to prevent methods from being removed from the code cache before we have checked the results
40
*
41
* This test should never run in the same VM as other tests - the code cache may get huge which will
42
* create an enormous amount of output to parse. Same for -Xcomp.
43
*/
44
45
import compiler.testlibrary.CompilerUtils;
46
import compiler.whitebox.CompilerWhiteBoxTest;
47
import jdk.test.lib.process.OutputAnalyzer;
48
import jdk.test.lib.dcmd.CommandExecutor;
49
import jdk.test.lib.dcmd.JMXExecutor;
50
import org.testng.annotations.Test;
51
import org.testng.Assert;
52
import sun.hotspot.WhiteBox;
53
54
import java.lang.reflect.Method;
55
import java.util.Iterator;
56
57
public class CodelistTest {
58
59
/**
60
* This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output,
61
* making sure that the first methods in the list is valid by reflection.
62
*
63
* Output example:
64
*
65
* 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30]
66
* 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490]
67
* 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338]
68
* 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698]
69
* 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
70
* 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
71
*
72
*/
73
74
protected static final WhiteBox WB = WhiteBox.getWhiteBox();
75
76
public void run(CommandExecutor executor) {
77
78
TestCase[] testcases = {
79
new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE, "testcaseMethod1"),
80
new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_LIMITED_PROFILE, "testcaseMethod2"),
81
new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_PROFILE, "testcaseMethod3"),
82
new TestCase(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION, "testcaseMethod4"),
83
};
84
85
String directive = "{ match: \"CodelistTest.testcaseMethod*\", " +
86
"BackgroundCompilation: false }";
87
Assert.assertTrue(
88
WB.addCompilerDirective(directive) == 1,
89
"Must succeed");
90
91
try {
92
// Enqueue one test method for each available level
93
int[] complevels = CompilerUtils.getAvailableCompilationLevels();
94
for (int level : complevels) {
95
// Only test comp level 1 and 4 - level 1, 2 and 3 may interfere with each other
96
if (level == 1 || level == 4) {
97
TestCase testcase = testcases[level - 1];
98
WB.enqueueMethodForCompilation(testcase.method, testcase.level);
99
// Set results to false for those methods we must to find
100
// We will also assert if we find any test method we don't expect
101
testcase.check = false;
102
}
103
}
104
} finally {
105
WB.removeCompilerDirective(1);
106
}
107
108
// Get output from dcmd (diagnostic command)
109
OutputAnalyzer output = executor.execute("Compiler.codelist");
110
Iterator<String> lines = output.asLines().iterator();
111
112
// Loop over output set result for all found methods
113
while (lines.hasNext()) {
114
String line = lines.next();
115
116
// Fast check for common part of method name
117
if (line.contains("CodelistTest.testcaseMethod")) {
118
String[] parts = line.split(" ");
119
int compileID = Integer.parseInt(parts[0]);
120
Assert.assertTrue(compileID > 0, "CompileID must be positive");
121
122
int compileLevel = Integer.parseInt(parts[1]);
123
Assert.assertTrue(compileLevel >= -1, "CompileLevel must be at least -1 (Any)");
124
Assert.assertTrue(compileLevel <= 4, "CompileLevel must be at most 4 (C2)");
125
126
int codeState = Integer.parseInt(parts[2]);
127
Assert.assertTrue(codeState >= 0, "CodeState must be at least 0 (In Use)");
128
Assert.assertTrue(codeState <= 4, "CodeState must be at most 4 (Unloaded)");
129
130
String str = parts[3];
131
for (TestCase testcase : testcases) {
132
if (str.contains(testcase.methodName)) {
133
Assert.assertFalse(testcase.check, "Must not be found or already found.");
134
Assert.assertTrue(testcase.level == compileLevel, "Must have correct level");
135
testcase.check = true;
136
}
137
}
138
}
139
}
140
141
// Check all testcases that was run
142
for (TestCase testcase : testcases) {
143
Assert.assertTrue(testcase.check, "Missing testcase " + testcase.methodName);
144
}
145
}
146
147
@Test
148
public void jmx() {
149
run(new JMXExecutor());
150
}
151
152
public void testcaseMethod1() {
153
}
154
155
public void testcaseMethod2() {
156
}
157
158
public void testcaseMethod3() {
159
}
160
161
public void testcaseMethod4() {
162
}
163
164
public static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {
165
try {
166
return klass.getDeclaredMethod(name, parameterTypes);
167
} catch (NoSuchMethodException | SecurityException e) {
168
throw new RuntimeException("exception on getting method Helper." + name, e);
169
}
170
}
171
172
class TestCase {
173
Method method;
174
int level;
175
String methodName;
176
Boolean check;
177
178
public TestCase(int level, String methodName) {
179
this.method = getMethod(CodelistTest.class, methodName);
180
this.level = level;
181
this.methodName = methodName;
182
this.check = true;
183
}
184
}
185
}
186
187