Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/AllocateCompileIdTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 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
26
* @key randomness
27
* @bug 8136421
28
* @requires vm.jvmci
29
* @library /test/lib /
30
* @library ../common/patches
31
* @modules java.base/jdk.internal.misc
32
* @modules java.base/jdk.internal.org.objectweb.asm
33
* java.base/jdk.internal.org.objectweb.asm.tree
34
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
35
* jdk.internal.vm.ci/jdk.vm.ci.code
36
* jdk.internal.vm.ci/jdk.vm.ci.meta
37
* jdk.internal.vm.ci/jdk.vm.ci.runtime
38
*
39
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
40
* sun.hotspot.WhiteBox sun.hotspot.parser.DiagnosticCommand
41
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
42
* sun.hotspot.parser.DiagnosticCommand
43
* @run main/othervm -Xbootclasspath/a:.
44
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
45
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
46
* -XX:-BackgroundCompilation
47
* compiler.jvmci.compilerToVM.AllocateCompileIdTest
48
*/
49
50
package compiler.jvmci.compilerToVM;
51
52
import compiler.jvmci.common.CTVMUtilities;
53
import jdk.test.lib.Asserts;
54
import jdk.test.lib.util.Pair;
55
import jdk.test.lib.Utils;
56
import jdk.vm.ci.hotspot.CompilerToVMHelper;
57
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
58
import sun.hotspot.code.NMethod;
59
60
import java.lang.reflect.Executable;
61
import java.lang.reflect.Method;
62
import java.util.ArrayList;
63
import java.util.HashSet;
64
import java.util.List;
65
import java.util.stream.Collectors;
66
import java.util.stream.Stream;
67
68
public class AllocateCompileIdTest {
69
70
private static final int SOME_REPEAT_VALUE = 5;
71
private final HashSet<Integer> ids = new HashSet<>();
72
73
public static void main(String[] args) {
74
AllocateCompileIdTest test = new AllocateCompileIdTest();
75
createTestCasesCorrectBci().forEach(test::runSanityCorrectTest);
76
createTestCasesIncorrectBci().forEach(test::runSanityIncorrectTest);
77
}
78
79
private static List<CompileCodeTestCase> createTestCasesCorrectBci() {
80
List<CompileCodeTestCase> result = new ArrayList<>();
81
try {
82
Class<?> aClass = DummyClass.class;
83
Method method = aClass.getMethod("withLoop");
84
Object receiver = new DummyClass();
85
result.add(new CompileCodeTestCase(receiver, method, 17));
86
result.add(new CompileCodeTestCase(receiver, method, -1));
87
} catch (NoSuchMethodException e) {
88
throw new Error("TEST BUG : " + e, e);
89
}
90
return result;
91
}
92
93
private static List<Pair<CompileCodeTestCase, Class<? extends Throwable>>>
94
createTestCasesIncorrectBci() {
95
List<Pair<CompileCodeTestCase, Class<? extends Throwable>>> result
96
= new ArrayList<>();
97
try {
98
Class<?> aClass = DummyClass.class;
99
Object receiver = new DummyClass();
100
Method method = aClass.getMethod("dummyInstanceFunction");
101
// greater than bytecode.length
102
byte[] bytecode = CompilerToVMHelper.getBytecode(CTVMUtilities
103
.getResolvedMethod(method));
104
Stream.of(
105
// greater than bytecode.length
106
bytecode.length + 4,
107
bytecode.length + 50,
108
bytecode.length + 200,
109
// negative cases
110
-4, -50, -200)
111
.map(bci -> new Pair<CompileCodeTestCase,
112
Class<? extends Throwable>>(
113
new CompileCodeTestCase(receiver, method, bci),
114
IllegalArgumentException.class))
115
.collect(Collectors.toList());
116
} catch (NoSuchMethodException e) {
117
throw new Error("TEST BUG : " + e.getMessage(), e);
118
}
119
return result;
120
}
121
122
private void runSanityCorrectTest(CompileCodeTestCase testCase) {
123
System.out.println(testCase);
124
Executable aMethod = testCase.executable;
125
// to generate ciTypeFlow
126
testCase.invoke(Utils.getNullValues(aMethod.getParameterTypes()));
127
int bci = testCase.bci;
128
HotSpotResolvedJavaMethod method = CTVMUtilities
129
.getResolvedMethod(aMethod);
130
for (int i = 0; i < SOME_REPEAT_VALUE; ++i) {
131
int wbCompileID = getWBCompileID(testCase);
132
int id = CompilerToVMHelper.allocateCompileId(method, bci);
133
Asserts.assertNE(id, 0, testCase + " : zero compile id");
134
Asserts.assertGT(id, wbCompileID, testCase
135
+ " : allocated 'compile id' not greater than existed");
136
Asserts.assertTrue(ids.add(wbCompileID), testCase
137
+ " : vm compilation allocated existing id " + id);
138
Asserts.assertTrue(ids.add(id), testCase
139
+ " : allocateCompileId returned existing id " + id);
140
}
141
}
142
143
private void runSanityIncorrectTest(
144
Pair<CompileCodeTestCase, Class<? extends Throwable>> testCase) {
145
System.out.println(testCase);
146
Class<? extends Throwable> exception = testCase.second;
147
Executable aMethod = testCase.first.executable;
148
int bci = testCase.first.bci;
149
HotSpotResolvedJavaMethod method = CTVMUtilities
150
.getResolvedMethod(aMethod);
151
Utils.runAndCheckException(
152
() -> CompilerToVMHelper.allocateCompileId(method, bci),
153
exception);
154
}
155
156
private int getWBCompileID(CompileCodeTestCase testCase) {
157
NMethod nm = testCase.deoptimizeAndCompile();
158
if (nm == null || nm.compile_id <= 0) {
159
throw new Error("TEST BUG : cannot compile method " + testCase);
160
}
161
return nm.compile_id;
162
}
163
}
164
165