Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jsr292/ContinuousCallSiteTargetChange.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
* @library /test/lib /
27
* @requires vm.flagless
28
*
29
* @build sun.hotspot.WhiteBox
30
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
31
* @run driver compiler.jsr292.ContinuousCallSiteTargetChange
32
*/
33
34
package compiler.jsr292;
35
36
import jdk.test.lib.Asserts;
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.process.ProcessTools;
39
import sun.hotspot.WhiteBox;
40
41
import java.lang.invoke.CallSite;
42
import java.lang.invoke.MethodHandle;
43
import java.lang.invoke.MethodHandles;
44
import java.lang.invoke.MethodType;
45
import java.lang.invoke.MutableCallSite;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.List;
49
50
public class ContinuousCallSiteTargetChange {
51
static final int ITERATIONS = Integer.parseInt(System.getProperty("iterations", "50"));
52
53
static void runTest(Class<?> test, String... extraArgs) throws Exception {
54
List<String> argsList = new ArrayList<>(
55
List.of("-XX:+IgnoreUnrecognizedVMOptions",
56
"-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
57
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining"));
58
59
argsList.addAll(Arrays.asList(extraArgs));
60
61
argsList.add(test.getName());
62
argsList.add(Integer.toString(ITERATIONS));
63
64
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(argsList);
65
66
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
67
68
analyzer.shouldHaveExitValue(0);
69
70
analyzer.shouldNotContain("made not compilable");
71
analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
72
73
}
74
75
static void testServer(Class<?> test, String... args) throws Exception {
76
List<String> extraArgsList = new ArrayList<>(
77
List.of("-server", "-XX:-TieredCompilation", "-Xbootclasspath/a:.",
78
"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"));
79
extraArgsList.addAll(Arrays.asList(args));
80
81
runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
82
}
83
84
static void testClient(Class<?> test, String... args) throws Exception {
85
List<String> extraArgsList = new ArrayList<>(
86
List.of("-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1",
87
"-Xbootclasspath/a:.", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI"));
88
extraArgsList.addAll(Arrays.asList(args));
89
90
runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
91
}
92
93
public static void main(String[] args) throws Exception {
94
testServer(RecompilationTest.class, "-Xbatch");
95
testClient(RecompilationTest.class, "-Xbatch");
96
97
testServer(PingPongTest.class);
98
testClient(PingPongTest.class);
99
}
100
101
static MethodHandle findStatic(Class<?> cls, String name, MethodType mt) {
102
try {
103
return MethodHandles.lookup().findStatic(cls, name, mt);
104
} catch (Exception e) {
105
throw new Error(e);
106
}
107
}
108
109
static class RecompilationTest {
110
static final MethodType mt = MethodType.methodType(void.class);
111
static final CallSite cs = new MutableCallSite(mt);
112
113
static final MethodHandle mh = cs.dynamicInvoker();
114
115
static void f() {
116
}
117
118
static void test1() throws Throwable {
119
mh.invokeExact();
120
}
121
122
static void test2() throws Throwable {
123
cs.getTarget().invokeExact();
124
}
125
126
static void iteration() throws Throwable {
127
MethodHandle mh1 = findStatic(RecompilationTest.class, "f", mt);
128
cs.setTarget(mh1);
129
for (int i = 0; i < 20_000; i++) {
130
test1();
131
test2();
132
}
133
}
134
135
public static void main(String[] args) throws Throwable {
136
int iterations = Integer.parseInt(args[0]);
137
for (int i = 0; i < iterations; i++) {
138
iteration();
139
}
140
}
141
}
142
143
static class PingPongTest {
144
static final MethodType mt = MethodType.methodType(void.class);
145
static final CallSite cs = new MutableCallSite(mt);
146
147
static final MethodHandle mh = cs.dynamicInvoker();
148
149
static final MethodHandle ping = findStatic(PingPongTest.class, "ping", mt);
150
static final MethodHandle pong = findStatic(PingPongTest.class, "pong", mt);
151
152
static void ping() {
153
Asserts.assertEQ(cs.getTarget(), ping, "wrong call site target");
154
cs.setTarget(pong);
155
}
156
157
static void pong() {
158
Asserts.assertEQ(cs.getTarget(), pong, "wrong call site target");
159
cs.setTarget(ping);
160
}
161
162
static void iteration() throws Throwable {
163
cs.setTarget(ping);
164
for (int i = 0; i < 20_000; i++) {
165
mh.invokeExact();
166
}
167
}
168
169
public static void main(String[] args) throws Throwable {
170
int iterations = Integer.parseInt(args[0]);
171
WhiteBox whiteBox = WhiteBox.getWhiteBox();
172
for (int i = 0; i < iterations; i++) {
173
iteration();
174
whiteBox.forceNMethodSweep();
175
}
176
}
177
}
178
}
179
180