Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jsr292/PollutedTrapCounts.java
41149 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 8074551
27
*
28
* @requires vm.flagless
29
* @modules java.base/jdk.internal.misc
30
* @library /test/lib
31
*
32
* @run driver compiler.jsr292.PollutedTrapCounts
33
*/
34
35
package compiler.jsr292;
36
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.process.ProcessTools;
39
40
import java.lang.invoke.MethodHandle;
41
import java.lang.invoke.MethodHandles;
42
import java.lang.invoke.MethodType;
43
44
public class PollutedTrapCounts {
45
public static void main(String[] args) throws Exception {
46
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
47
"-XX:+IgnoreUnrecognizedVMOptions",
48
"-XX:-TieredCompilation", "-Xbatch",
49
"-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
50
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
51
Test.class.getName());
52
53
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
54
55
analyzer.shouldHaveExitValue(0);
56
57
analyzer.shouldNotContain("not compilable (disabled)");
58
}
59
60
static class Test {
61
public static final MethodHandle test1;
62
public static final MethodHandle test2;
63
public static final MethodHandle empty;
64
65
static {
66
try {
67
Class<?> THIS_CLASS = Test.class;
68
MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
69
test1 = LOOKUP.findStatic(THIS_CLASS, "test1", MethodType.methodType(boolean.class, boolean.class));
70
test2 = LOOKUP.findStatic(THIS_CLASS, "test2", MethodType.methodType(boolean.class, boolean.class));
71
empty = LOOKUP.findStatic(THIS_CLASS, "empty", MethodType.methodType(void.class, boolean.class));
72
} catch(Throwable e) {
73
throw new Error(e);
74
}
75
}
76
77
static boolean test1(boolean b) {
78
return b;
79
}
80
static boolean test2(boolean b) {
81
return true;
82
}
83
static void empty(boolean b) {}
84
85
static void test(boolean freqValue, boolean removeInlineBlocker) throws Throwable {
86
MethodHandle innerGWT = MethodHandles.guardWithTest(test1, empty, empty);
87
MethodHandle outerGWT = MethodHandles.guardWithTest(test2, innerGWT, innerGWT);
88
89
// Trigger compilation
90
for (int i = 0; i < 20_000; i++) {
91
outerGWT.invokeExact(freqValue);
92
}
93
94
// Trigger deopt & nmethod invalidation
95
outerGWT.invokeExact(!freqValue);
96
97
// Force inline blocker removal on rare-taken path
98
if (removeInlineBlocker) {
99
for (int i = 0; i < 100; i++) {
100
outerGWT.invokeExact(!freqValue);
101
}
102
}
103
104
// Trigger recompilation
105
for (int i = 0; i < 20_000; i++) {
106
outerGWT.invokeExact(freqValue);
107
}
108
}
109
110
public static void main(String[] args) throws Throwable {
111
boolean freqValue = true;
112
boolean removeInlineBlocker = false;
113
for (int i = 0; i < 20; i++) {
114
test(freqValue, removeInlineBlocker);
115
freqValue = !freqValue;
116
removeInlineBlocker = !removeInlineBlocker;
117
}
118
}
119
}
120
}
121
122