Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.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
* @bug 8136421
27
*
28
* @requires vm.jvmci & vm.compMode == "Xmixed"
29
* @requires vm.opt.final.EliminateAllocations == true
30
*
31
* @comment no "-Xcomp -XX:-TieredCompilation" combination allowed until JDK-8140018 is resolved
32
* @requires vm.opt.TieredCompilation == null | vm.opt.TieredCompilation == true
33
*
34
* @library / /test/lib
35
* @library ../common/patches
36
* @modules java.base/jdk.internal.misc
37
* @modules java.base/jdk.internal.org.objectweb.asm
38
* java.base/jdk.internal.org.objectweb.asm.tree
39
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
40
* jdk.internal.vm.ci/jdk.vm.ci.code
41
* jdk.internal.vm.ci/jdk.vm.ci.code.stack
42
* jdk.internal.vm.ci/jdk.vm.ci.meta
43
*
44
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
45
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
46
* @run main/othervm -Xbatch -Xbootclasspath/a:.
47
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
48
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
49
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
50
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
51
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
52
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
53
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame3
54
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
55
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=true
56
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
57
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
58
* @run main/othervm -Xbatch -Xbootclasspath/a:.
59
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
60
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
61
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
62
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
63
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
64
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
65
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame3
66
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
67
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=false
68
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
69
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
70
* @run main/othervm -Xbatch -Xbootclasspath/a:.
71
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
72
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
73
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
74
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
75
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
76
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
77
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame3
78
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
79
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=true
80
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
81
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
82
* @run main/othervm -Xbatch -Xbootclasspath/a:.
83
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
84
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
85
* -XX:CompileCommand=exclude,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::check
86
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame
87
* -XX:CompileCommand=dontinline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame2
88
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::recurse
89
* -XX:CompileCommand=inline,compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest::testFrame3
90
* -XX:+DoEscapeAnalysis -XX:-UseCounterDecay
91
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst=false
92
* -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
93
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
94
*/
95
96
package compiler.jvmci.compilerToVM;
97
98
import compiler.jvmci.common.CTVMUtilities;
99
import compiler.testlibrary.CompilerUtils;
100
import compiler.whitebox.CompilerWhiteBoxTest;
101
import jdk.test.lib.Asserts;
102
import jdk.vm.ci.code.stack.InspectedFrame;
103
import jdk.vm.ci.hotspot.CompilerToVMHelper;
104
import jdk.vm.ci.hotspot.HotSpotStackFrameReference;
105
import jdk.vm.ci.meta.ResolvedJavaMethod;
106
import jtreg.SkippedException;
107
import sun.hotspot.WhiteBox;
108
109
import java.lang.reflect.Method;
110
111
public class MaterializeVirtualObjectTest {
112
private static final WhiteBox WB;
113
private static final boolean INVALIDATE;
114
private static final int COMPILE_THRESHOLD;
115
private static final Method MATERIALIZED_METHOD;
116
private static final Method NOT_MATERIALIZED_METHOD;
117
private static final Method FRAME3_METHOD;
118
private static final ResolvedJavaMethod MATERIALIZED_RESOLVED;
119
private static final ResolvedJavaMethod NOT_MATERIALIZED_RESOLVED;
120
private static final ResolvedJavaMethod FRAME2_RESOLVED;
121
private static final ResolvedJavaMethod FRAME3_RESOLVED;
122
private static final boolean MATERIALIZE_FIRST;
123
124
static {
125
Method method1;
126
Method method2;
127
WB = WhiteBox.getWhiteBox();
128
try {
129
method1 = MaterializeVirtualObjectTest.class.getDeclaredMethod("testFrame",
130
String.class, int.class);
131
method2 = MaterializeVirtualObjectTest.class.getDeclaredMethod("testFrame2",
132
String.class, int.class);
133
FRAME3_METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod("testFrame3",
134
Helper.class, int.class);
135
} catch (NoSuchMethodException e) {
136
throw new Error("Can't get executable for test method", e);
137
}
138
ResolvedJavaMethod resolved1;
139
resolved1 = CTVMUtilities.getResolvedMethod(method1);
140
FRAME2_RESOLVED = CTVMUtilities.getResolvedMethod(method2);
141
FRAME3_RESOLVED = CTVMUtilities.getResolvedMethod(FRAME3_METHOD);
142
INVALIDATE = Boolean.getBoolean(
143
"compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
144
COMPILE_THRESHOLD = CompilerWhiteBoxTest.THRESHOLD;
145
MATERIALIZE_FIRST = Boolean.getBoolean(
146
"compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.materializeFirst");
147
MATERIALIZED_RESOLVED = MATERIALIZE_FIRST ? resolved1 : FRAME2_RESOLVED;
148
NOT_MATERIALIZED_RESOLVED = MATERIALIZE_FIRST ? FRAME2_RESOLVED : resolved1;
149
MATERIALIZED_METHOD = MATERIALIZE_FIRST ? method1 : method2;
150
NOT_MATERIALIZED_METHOD = MATERIALIZE_FIRST ? method2 : method1;
151
}
152
153
public static void main(String[] args) {
154
int levels[] = CompilerUtils.getAvailableCompilationLevels();
155
// we need compilation level 4 to use EscapeAnalysis
156
if (levels.length < 1 || levels[levels.length - 1] != 4) {
157
throw new SkippedException("Test needs compilation level 4");
158
}
159
160
new MaterializeVirtualObjectTest().test();
161
}
162
163
private static String getName() {
164
return "CASE: invalidate=" + INVALIDATE + ", materializedMethod="
165
+ (MATERIALIZE_FIRST ? "testFrame" : "testFrame2")
166
+ ", notMaterializedMethod="
167
+ (MATERIALIZE_FIRST ? "testFrame2" : "testFrame");
168
}
169
170
private void test() {
171
System.out.println(getName());
172
Asserts.assertFalse(WB.isMethodCompiled(MATERIALIZED_METHOD),
173
getName() + " : materialized method is compiled");
174
Asserts.assertFalse(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
175
getName() + " : not materialized method is compiled");
176
for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {
177
testFrame("someString", i);
178
}
179
Asserts.assertTrue(WB.isMethodCompiled(MATERIALIZED_METHOD), getName()
180
+ " : materialized method not compiled");
181
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
182
getName() + " : not materialized method not compiled");
183
testFrame("someString", /* materialize */ CompilerWhiteBoxTest.THRESHOLD);
184
185
// run second test types
186
for (int i = 0; i < CompilerWhiteBoxTest.THRESHOLD; i++) {
187
testFrame("someString", i);
188
}
189
Asserts.assertTrue(WB.isMethodCompiled(MATERIALIZED_METHOD), getName()
190
+ " : materialized method not compiled");
191
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
192
getName() + " : not materialized method not compiled");
193
testFrame("someString", /* materialize */ CompilerWhiteBoxTest.THRESHOLD + 1);
194
}
195
196
private void testFrame(String str, int iteration) {
197
Helper helper = new Helper(str);
198
testFrame2(str, iteration);
199
Asserts.assertTrue((helper.string != null) && (this != null)
200
&& (helper != null), String.format("%s : some locals are null", getName()));
201
}
202
203
private void testFrame2(String str, int iteration) {
204
Helper helper = new Helper(str);
205
Helper helper2 = new Helper("bar");
206
testFrame3(helper, iteration);
207
Asserts.assertTrue((helper.string != null) && (this != null) && helper.string == str
208
&& (helper != null), String.format("%s : some locals are null", getName()));
209
Asserts.assertTrue((helper2.string != null) && (this != null)
210
&& (helper2 != null), String.format("%s : some locals are null", getName()));
211
}
212
213
private void testFrame3(Helper outerHelper, int iteration) {
214
Helper innerHelper = new Helper("foo");
215
recurse(2, iteration);
216
Asserts.assertTrue((innerHelper.string != null) && (this != null)
217
&& (innerHelper != null), String.format("%s : some locals are null", getName()));
218
Asserts.assertTrue((outerHelper.string != null) && (this != null)
219
&& (outerHelper != null), String.format("%s : some locals are null", getName()));
220
}
221
222
private void recurse(int depth, int iteration) {
223
if (depth == 0) {
224
check(iteration);
225
} else {
226
Integer s = new Integer(depth);
227
recurse(depth - 1, iteration);
228
Asserts.assertEQ(s.intValue(), depth,
229
String.format("different values: %s != %s", s.intValue(), depth));
230
}
231
}
232
233
private void checkStructure(boolean materialize) {
234
boolean[] framesSeen = new boolean[2];
235
Object[] helpers = new Object[1];
236
CompilerToVMHelper.iterateFrames(
237
new ResolvedJavaMethod[] {FRAME3_RESOLVED},
238
null, /* any */
239
0,
240
f -> {
241
if (!framesSeen[1]) {
242
Asserts.assertTrue(f.isMethod(FRAME3_RESOLVED),
243
"Expected testFrame3 first");
244
framesSeen[1] = true;
245
Asserts.assertTrue(f.getLocal(0) != null, "this should not be null");
246
Asserts.assertTrue(f.getLocal(1) != null, "outerHelper should not be null");
247
Asserts.assertTrue(f.getLocal(3) != null, "innerHelper should not be null");
248
Asserts.assertEQ(((Helper) f.getLocal(3)).string, "foo", "innerHelper.string should be foo");
249
helpers[0] = f.getLocal(1);
250
if (materialize) {
251
f.materializeVirtualObjects(false);
252
}
253
return null; //continue
254
} else {
255
Asserts.assertFalse(framesSeen[0], "frame3 can not have been seen");
256
Asserts.assertTrue(f.isMethod(FRAME2_RESOLVED),
257
"Expected testFrame2 second");
258
framesSeen[0] = true;
259
Asserts.assertTrue(f.getLocal(0) != null, "this should not be null");
260
Asserts.assertTrue(f.getLocal(1) != null, "str should not be null");
261
Asserts.assertTrue(f.getLocal(3) != null, "helper should not be null");
262
Asserts.assertTrue(f.getLocal(4) != null, "helper2 should not be null");
263
Asserts.assertEQ(((Helper) f.getLocal(3)).string, f.getLocal(1), "helper.string should be the same as str");
264
Asserts.assertEQ(((Helper) f.getLocal(4)).string, "bar", "helper2.string should be foo");
265
if (!materialize) {
266
Asserts.assertEQ(f.getLocal(3), helpers[0], "helper should be the same as frame3's outerHelper");
267
}
268
return f; // stop
269
}
270
});
271
Asserts.assertTrue(framesSeen[1], "frame3 should have been seen");
272
Asserts.assertTrue(framesSeen[0], "frame2 should have been seen");
273
}
274
275
private void check(int iteration) {
276
// Materialize virtual objects on last invocation
277
if (iteration == COMPILE_THRESHOLD) {
278
// get frames and check not-null
279
HotSpotStackFrameReference materialized = CompilerToVMHelper.iterateFrames(
280
new ResolvedJavaMethod[] {MATERIALIZED_RESOLVED},
281
null /* any */,
282
0,
283
f -> (HotSpotStackFrameReference) f);
284
Asserts.assertNotNull(materialized, getName()
285
+ " : got null frame for materialized method");
286
Asserts.assertTrue(materialized.isMethod(MATERIALIZED_RESOLVED),
287
"Expected materialized method but got " + materialized);
288
InspectedFrame notMaterialized = CompilerToVMHelper.iterateFrames(
289
new ResolvedJavaMethod[] {NOT_MATERIALIZED_RESOLVED},
290
null /* any */,
291
0,
292
f -> f);
293
Asserts.assertNE(materialized, notMaterialized,
294
"Got same frame pointer for both tested frames");
295
Asserts.assertTrue(notMaterialized.isMethod(NOT_MATERIALIZED_RESOLVED),
296
"Expected notMaterialized method but got " + notMaterialized);
297
Asserts.assertNotNull(notMaterialized, getName()
298
+ " : got null frame for not materialized method");
299
Asserts.assertTrue(WB.isMethodCompiled(MATERIALIZED_METHOD), getName()
300
+ " : materialized method not compiled");
301
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD),
302
getName() + " : not materialized method not compiled");
303
// check that frames has virtual objects before materialization stage
304
Asserts.assertTrue(materialized.hasVirtualObjects(), getName()
305
+ ": materialized frame has no virtual object before materialization");
306
Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
307
+ ": notMaterialized frame has no virtual object before materialization");
308
// materialize
309
CompilerToVMHelper.materializeVirtualObjects(materialized, INVALIDATE);
310
// check that only not materialized frame has virtual objects
311
Asserts.assertFalse(materialized.hasVirtualObjects(), getName()
312
+ " : materialized has virtual object after materialization");
313
Asserts.assertTrue(notMaterialized.hasVirtualObjects(), getName()
314
+ " : notMaterialized has no virtual object after materialization");
315
// check that materialized frame was deoptimized in case invalidate=true
316
Asserts.assertEQ(WB.isMethodCompiled(MATERIALIZED_METHOD), !INVALIDATE, getName()
317
+ " : materialized method has unexpected compiled status");
318
// check that not materialized frame wasn't deoptimized
319
Asserts.assertTrue(WB.isMethodCompiled(NOT_MATERIALIZED_METHOD), getName()
320
+ " : not materialized method has unexpected compiled status");
321
} else if (iteration == COMPILE_THRESHOLD + 1) {
322
checkStructure(false);
323
checkStructure(true);
324
}
325
}
326
327
private class Helper {
328
public String string;
329
330
public Helper(String s) {
331
this.string = s;
332
}
333
}
334
}
335
336