Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java
64474 views
1
/*
2
* Copyright (c) 2021, 2022, 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
* @requires !vm.graal.enabled & vm.opt.final.UseVtableBasedCHA == true
27
* @modules java.base/jdk.internal.org.objectweb.asm
28
* java.base/jdk.internal.misc
29
* java.base/jdk.internal.vm.annotation
30
* @library /test/lib /
31
* @compile Utils.java
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
*
35
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
36
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
37
* -XX:CompileCommand=compileonly,*::m
38
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
39
* -Xbatch -Xmixed -XX:+WhiteBoxAPI
40
* -XX:-TieredCompilation
41
* compiler.cha.AbstractRootMethod
42
*
43
* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
44
* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet
45
* -XX:CompileCommand=compileonly,*::m
46
* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test
47
* -Xbatch -Xmixed -XX:+WhiteBoxAPI
48
* -XX:+TieredCompilation -XX:TieredStopAtLevel=1
49
* compiler.cha.AbstractRootMethod
50
*/
51
package compiler.cha;
52
53
import java.lang.invoke.MethodHandle;
54
import java.lang.invoke.MethodHandles;
55
56
import static compiler.cha.Utils.*;
57
58
public class AbstractRootMethod {
59
public static void main(String[] args) {
60
run(AbstractClass.class);
61
run(AbstractInterface.class);
62
63
// Implementation limitation: CHA is not performed by C1 during inlining through MH linkers.
64
if (!sun.hotspot.code.Compiler.isC1Enabled()) {
65
run(AbstractClass.TestMH.class, AbstractClass.class);
66
run(AbstractInterface.TestMH.class, AbstractInterface.class);
67
}
68
69
System.out.println("TEST PASSED");
70
}
71
72
public static class AbstractClass extends ATest<AbstractClass.C> {
73
public AbstractClass() {
74
super(C.class, D.class);
75
}
76
77
interface I1 { Object m(); }
78
interface I2 { default Object m() { return "I2.m"; } }
79
80
static abstract class C { public abstract Object m(); }
81
82
static abstract class D extends C {
83
final Object ret = CORRECT;
84
public Object m() {
85
return ret;
86
}
87
}
88
89
static abstract class E1 extends C { /* empty */ }
90
static abstract class E2 extends C { public abstract Object m(); }
91
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
92
93
static abstract class F1 extends C implements I1 { }
94
static abstract class F2 extends C implements I2 { }
95
96
static class G extends C { public Object m() { return CORRECT; } }
97
98
@Override
99
public Object test(C obj) {
100
return obj.m(); // invokevirtual C.m()
101
}
102
103
@Override
104
public void checkInvalidReceiver() {
105
// nothing to do: concrete class types are enforced by the verifier
106
}
107
108
@TestCase
109
public void test() {
110
// 0. Trigger compilation of a megamorphic call site
111
compile(megamorphic()); // Dn <: D.m <: C.m ABSTRACT
112
assertCompiled();
113
114
// Dependency: type = unique_concrete_method, context = C, method = D.m
115
116
// 1. No invalidation: abstract classes don't participate in CHA.
117
initialize(E1.class, // ABSTRACT E1 <: C.m ABSTRACT
118
E2.class, // ABSTRACT E2.m ABSTRACT <: C.m ABSTRACT
119
E3.class, // ABSTRACT E3.m <: C.m ABSTRACT
120
F1.class, // ABSTRACT F1 <: C.m ABSTRACT, I1.m ABSTRACT
121
F2.class); // ABSTRACT F2 <: C.m ABSTRACT, I2.m DEFAULT
122
assertCompiled();
123
124
// 2. Dependency invalidation: G.m <: C.m ABSTRACT
125
load(G.class);
126
assertCompiled();
127
128
// 3. Dependency invalidation: G.m <: C.m ABSTRACT
129
initialize(G.class);
130
assertNotCompiled();
131
132
// 4. Recompilation: no inlining, no dependencies
133
compile(megamorphic());
134
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C.m ABSTRACT
135
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C.m ABSTRACT
136
assertCompiled();
137
}
138
139
public static class TestMH extends AbstractClass {
140
static final MethodHandle TEST_MH = findVirtualHelper(C.class, "m", Object.class, MethodHandles.lookup());
141
142
@Override
143
public Object test(C obj) {
144
try {
145
return TEST_MH.invokeExact(obj); // invokevirtual C.m()
146
} catch (Throwable e) {
147
throw new InternalError(e);
148
}
149
}
150
}
151
}
152
153
public static class AbstractInterface extends ATest<AbstractInterface.C> {
154
public AbstractInterface() {
155
super(C.class, D.class);
156
}
157
158
interface I1 { Object m(); }
159
interface I2 extends I { default Object m() { return "I2.m"; } }
160
161
interface I { Object m(); }
162
163
static abstract class C implements I { /* inherited from I */}
164
165
static abstract class D extends C {
166
final Object ret = CORRECT;
167
public Object m() {
168
return ret;
169
}
170
}
171
172
static abstract class E1 extends C { /* empty */ }
173
static abstract class E2 extends C { public abstract Object m(); }
174
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
175
176
static abstract class F1 extends C implements I1 { }
177
static abstract class F2 extends C implements I2 { }
178
179
static class G extends C { public Object m() { return CORRECT; } }
180
181
@Override
182
public Object test(C obj) {
183
return obj.m(); // invokevirtual C.m()
184
}
185
186
@Override
187
public void checkInvalidReceiver() {
188
// nothing to do: concrete class types are enforced by the verifier
189
}
190
191
@TestCase
192
public void test() {
193
// 0. Trigger compilation of a megamorphic call site
194
compile(megamorphic()); // Dn <: D.m <: C <: I.m ABSTRACT
195
assertCompiled();
196
197
// Dependency: type = unique_concrete_method, context = C, method = D.m
198
199
// 1. No invalidation: abstract classes don't participate in CHA.
200
initialize(E1.class, // ABSTRACT E1 <: C <: I.m ABSTRACT
201
E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m ABSTRACT
202
E3.class, // ABSTRACT E3.m <: C <: I.m ABSTRACT
203
F1.class, // ABSTRACT F1 <: C <: I.m ABSTRACT, I1.m ABSTRACT
204
F2.class); // ABSTRACT F2 <: C <: I.m ABSTRACT, I2.m DEFAULT
205
assertCompiled();
206
207
// 2. Dependency invalidation: G.m <: C <: I.m ABSTRACT
208
load(G.class);
209
assertCompiled();
210
211
// 3. Dependency invalidation: G.m <: C <: I.m ABSTRACT
212
initialize(G.class);
213
assertNotCompiled();
214
215
// 4. Recompilation: no inlining, no dependencies
216
compile(megamorphic());
217
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m ABSTRACT
218
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m ABSTRACT
219
assertCompiled();
220
}
221
222
public static class TestMH extends AbstractInterface {
223
static final MethodHandle TEST_MH = findVirtualHelper(C.class, "m", Object.class, MethodHandles.lookup());
224
225
@Override
226
public Object test(C obj) {
227
try {
228
return TEST_MH.invokeExact(obj); // invokevirtual C.m()
229
} catch (Throwable e) {
230
throw new InternalError(e);
231
}
232
}
233
}
234
}
235
}
236
237