Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jsr292/MHInlineTest.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 8062280
27
* @summary C2: inlining failure due to access checks being too strict
28
*
29
* @requires vm.flagless
30
* @modules java.base/jdk.internal.misc
31
* @library /test/lib /
32
*
33
* @run driver compiler.jsr292.MHInlineTest
34
*/
35
36
package compiler.jsr292;
37
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
40
import jtreg.SkippedException;
41
42
import java.lang.invoke.MethodHandle;
43
import java.lang.invoke.MethodHandles;
44
import java.lang.invoke.MethodType;
45
46
import static jdk.test.lib.Asserts.assertEquals;
47
48
public class MHInlineTest {
49
public static void main(String[] args) throws Exception {
50
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
51
"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
52
"-XX:-TieredCompilation", "-Xbatch",
53
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
54
"-XX:CompileCommand=dontinline,compiler.jsr292.MHInlineTest::test*",
55
Launcher.class.getName());
56
57
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
58
59
analyzer.shouldHaveExitValue(0);
60
61
// The test is applicable only to C2 (present in Server VM).
62
if (analyzer.getStderr().contains("Server VM")) {
63
analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::public_x (3 bytes) inline (hot)");
64
analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::protected_x (3 bytes) inline (hot)");
65
analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::package_x (3 bytes) inline (hot)");
66
analyzer.shouldContain("compiler.jsr292.MHInlineTest$A::package_final_x (3 bytes) inline (hot)");
67
analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::private_x (3 bytes) inline (hot)");
68
analyzer.shouldContain("compiler.jsr292.MHInlineTest$B::private_static_x (3 bytes) inline (hot)");
69
analyzer.shouldContain("compiler.jsr292.MHInlineTest$A::package_static_x (3 bytes) inline (hot)");
70
} else {
71
throw new SkippedException("The test is applicable only to C2 (present in Server VM)");
72
}
73
}
74
75
static class A {
76
public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
77
78
public Class<?> public_x() { return A.class; }
79
protected Class<?> protected_x() { return A.class; }
80
Class<?> package_x() { return A.class; }
81
final Class<?> package_final_x() { return A.class; }
82
83
static Class<?> package_static_x() { return A.class; }
84
}
85
86
static class B extends A {
87
public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
88
89
@Override public Class<?> public_x() { return B.class; }
90
@Override protected Class<?> protected_x() { return B.class; }
91
@Override Class<?> package_x() { return B.class; }
92
93
private Class<?> private_x() { return B.class; }
94
static Class<?> private_static_x() { return B.class; }
95
}
96
97
static final MethodHandle A_PUBLIC_X;
98
static final MethodHandle A_PROTECTED_X;
99
static final MethodHandle A_PACKAGE_X;
100
static final MethodHandle A_PACKAGE_STATIC_X;
101
static final MethodHandle A_PACKAGE_FINAL_X;
102
103
static final MethodHandle B_PRIVATE_X;
104
static final MethodHandle B_PRIVATE_STATIC_X;
105
106
static {
107
try {
108
MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
109
110
A_PUBLIC_X = LOOKUP.findVirtual(
111
A.class, "public_x", MethodType.methodType(Class.class));
112
A_PROTECTED_X = LOOKUP.findVirtual(
113
A.class, "protected_x", MethodType.methodType(Class.class));
114
A_PACKAGE_X = LOOKUP.findVirtual(
115
A.class, "package_x", MethodType.methodType(Class.class));
116
A_PACKAGE_FINAL_X = LOOKUP.findVirtual(
117
A.class, "package_final_x", MethodType.methodType(Class.class));
118
A_PACKAGE_STATIC_X = LOOKUP.findStatic(
119
A.class, "package_static_x", MethodType.methodType(Class.class));
120
121
B_PRIVATE_X = B.LOOKUP.findVirtual(
122
B.class, "private_x", MethodType.methodType(Class.class));
123
B_PRIVATE_STATIC_X = B.LOOKUP.findStatic(
124
B.class, "private_static_x", MethodType.methodType(Class.class));
125
} catch (Exception e) {
126
throw new Error(e);
127
}
128
}
129
130
static final A a = new B();
131
132
private static void testPublicMH() {
133
try {
134
Class<?> r = (Class<?>)A_PUBLIC_X.invokeExact(a);
135
assertEquals(r, B.class);
136
} catch (Throwable throwable) {
137
throw new Error(throwable);
138
}
139
}
140
141
private static void testProtectedMH() {
142
try {
143
Class<?> r = (Class<?>)A_PROTECTED_X.invokeExact(a);
144
assertEquals(r, B.class);
145
} catch (Throwable throwable) {
146
throw new Error(throwable);
147
}
148
}
149
150
private static void testPackageMH() {
151
try {
152
Class<?> r = (Class<?>)A_PACKAGE_X.invokeExact(a);
153
assertEquals(r, B.class);
154
} catch (Throwable throwable) {
155
throw new Error(throwable);
156
}
157
}
158
159
private static void testPackageFinalMH() {
160
try {
161
Class<?> r = (Class<?>)A_PACKAGE_FINAL_X.invokeExact(a);
162
assertEquals(r, A.class);
163
} catch (Throwable throwable) {
164
throw new Error(throwable);
165
}
166
}
167
168
private static void testPackageStaticMH() {
169
try {
170
Class<?> r = (Class<?>)A_PACKAGE_STATIC_X.invokeExact();
171
assertEquals(r, A.class);
172
} catch (Throwable throwable) {
173
throw new Error(throwable);
174
}
175
}
176
177
private static void testPrivateMH() {
178
try {
179
Class<?> r = (Class<?>)B_PRIVATE_X.invokeExact((B)a);
180
assertEquals(r, B.class);
181
} catch (Throwable throwable) {
182
throw new Error(throwable);
183
}
184
}
185
186
private static void testPrivateStaticMH() {
187
try {
188
Class<?> r = (Class<?>)B_PRIVATE_STATIC_X.invokeExact();
189
assertEquals(r, B.class);
190
} catch (Throwable throwable) {
191
throw new Error(throwable);
192
}
193
}
194
195
static class Launcher {
196
public static void main(String[] args) throws Exception {
197
for (int i = 0; i < 20_000; i++) {
198
testPublicMH();
199
}
200
for (int i = 0; i < 20_000; i++) {
201
testProtectedMH();
202
}
203
for (int i = 0; i < 20_000; i++) {
204
testPackageMH();
205
}
206
for (int i = 0; i < 20_000; i++) {
207
testPackageFinalMH();
208
}
209
for (int i = 0; i < 20_000; i++) {
210
testPackageStaticMH();
211
}
212
for (int i = 0; i < 20_000; i++) {
213
testPrivateMH();
214
}
215
for (int i = 0; i < 20_000; i++) {
216
testPrivateStaticMH();
217
}
218
}
219
}
220
}
221
222