Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.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.DefaultRootMethod
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.DefaultRootMethod
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 DefaultRootMethod {
59
public static void main(String[] args) {
60
run(DefaultRoot.class);
61
run(InheritedDefault.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(DefaultRoot.TestMH.class, DefaultRoot.class);
66
run(InheritedDefault.TestMH.class, InheritedDefault.class);
67
}
68
69
System.out.println("TEST PASSED");
70
}
71
72
public static class DefaultRoot extends ATest<DefaultRoot.C> {
73
public DefaultRoot() {
74
super(C.class, D.class);
75
}
76
77
interface I { default Object m() { return CORRECT; } }
78
79
static class C implements I { /* inherited I.m */}
80
81
static class D extends C { /* inherited I.m */ }
82
83
static abstract class E1 extends C { /* empty */ }
84
static abstract class E2 extends C { public abstract Object m(); }
85
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
86
87
interface I1 extends I { Object m(); }
88
interface I2 extends I { default Object m() { return "I2.m"; } }
89
90
static abstract class F1 extends C implements I1 { }
91
static abstract class F2 extends C implements I2 { }
92
93
static class G extends C { public Object m() { return CORRECT; } }
94
95
@Override
96
public Object test(C obj) throws Throwable {
97
return obj.m(); // invokevirtual C.m()
98
}
99
100
@Override
101
public void checkInvalidReceiver() {
102
// nothing to do: concrete class types are enforced by the verifier
103
}
104
105
@TestCase
106
public void test() {
107
// 0. Trigger compilation of a megamorphic call site
108
compile(megamorphic()); // Dn <: D.m <: C <: I.m DEFAULT
109
assertCompiled();
110
111
// Dependency: type = unique_concrete_method, context = C, method = D.m
112
113
// 1. No invalidation: abstract classes don't participate in CHA.
114
initialize(E1.class, // ABSTRACT E1 <: C <: I.m DEFAULT
115
E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m DEFAULT
116
E3.class, // ABSTRACT E3.m <: C <: I.m DEFAULT
117
F1.class, // ABSTRACT F1 <: C <: I.m DEFAULT, I1.m ABSTRACT
118
F2.class); // ABSTRACT F2 <: C <: I.m DEFAULT, I2.m DEFAULT
119
assertCompiled();
120
121
// 2. Dependency invalidation: G.m <: C <: I.m DEFAULT
122
load(G.class);
123
assertCompiled();
124
125
// 3. Dependency invalidation: G.m <: C <: I.m DEFAULT
126
initialize(G.class);
127
assertNotCompiled();
128
129
// 4. Recompilation: no inlining, no dependencies
130
compile(megamorphic());
131
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m DEFAULT
132
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m DEFAULT
133
assertCompiled();
134
}
135
136
public static class TestMH extends DefaultRoot {
137
static final MethodHandle TEST_MH = findVirtualHelper(C.class, "m", Object.class, MethodHandles.lookup());
138
139
@Override
140
public Object test(C obj) throws Throwable {
141
return TEST_MH.invokeExact(obj); // invokevirtual C.m()
142
}
143
}
144
}
145
146
public static class InheritedDefault extends ATest<InheritedDefault.C> {
147
public InheritedDefault() {
148
super(C.class, D.class);
149
}
150
151
interface I { Object m(); }
152
interface J extends I { default Object m() { return CORRECT; } }
153
154
static abstract class C implements I { /* inherits I.m ABSTRACT */}
155
156
// NB! The class is marked abstract to avoid abstract_with_unique_concrete_subtype dependency
157
static abstract class D extends C implements J { /* inherits J.m DEFAULT*/ }
158
159
static abstract class E1 extends C { /* empty */ }
160
static abstract class E2 extends C { public abstract Object m(); }
161
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
162
163
interface I1 extends I { Object m(); }
164
interface I2 extends I { default Object m() { return "I2.m"; } }
165
166
static abstract class F1 extends C implements I1 { }
167
static abstract class F2 extends C implements I2 { }
168
169
interface K extends I { default Object m() { return CORRECT; } }
170
static class G extends C implements K { /* inherits K.m DEFAULT */ }
171
172
@Override
173
public Object test(C obj) throws Throwable {
174
return obj.m(); // invokevirtual C.m()
175
}
176
177
@Override
178
public void checkInvalidReceiver() {
179
// nothing to do: concrete class types are enforced by the verifier
180
}
181
182
@TestCase
183
public void test() {
184
// 0. Trigger compilation of a megamorphic call site
185
compile(megamorphic()); // Dn <: D.m <: C <: I.m ABSTRACT, J.m DEFAULT
186
assertCompiled();
187
188
// Dependency: type = unique_concrete_method, context = C, method = D.m
189
190
// 1. No invalidation: abstract classes don't participate in CHA.
191
initialize(E1.class, // ABSTRACT E1 <: C <: I.m ABSTRACT
192
E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m ABSTRACT
193
E3.class, // ABSTRACT E3.m <: C <: I.m ABSTRACT
194
F1.class, // ABSTRACT F1 <: C <: I.m ABSTRACT, I1.m ABSTRACT
195
F2.class); // ABSTRACT F2 <: C <: I.m ABSTRACT, I2.m DEFAULT
196
assertCompiled();
197
198
// 2. No invalidation: not yet linked classes don't participate in CHA.
199
load(G.class);
200
assertCompiled();
201
202
// 3. Dependency invalidation: G.m <: C <: I.m DEFAULT
203
initialize(G.class);
204
assertNotCompiled();
205
206
// 4. Recompilation: no inlining, no dependencies
207
compile(megamorphic());
208
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m DEFAULT
209
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m DEFAULT
210
assertCompiled();
211
}
212
213
public static class TestMH extends InheritedDefault {
214
static final MethodHandle TEST_MH = findVirtualHelper(C.class, "m", Object.class, MethodHandles.lookup());
215
216
@Override
217
public Object test(C obj) throws Throwable {
218
return TEST_MH.invokeExact(obj); // invokevirtual C.m()
219
}
220
}
221
}
222
}
223
224