Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java
41149 views
1
/*
2
* Copyright (c) 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
* @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 static compiler.cha.Utils.*;
54
55
public class AbstractRootMethod {
56
public static void main(String[] args) {
57
run(AbstractClass.class);
58
run(AbstractInterface.class);
59
}
60
61
public static class AbstractClass extends ATest<AbstractClass.C> {
62
public AbstractClass() {
63
super(C.class, D.class);
64
}
65
66
interface I1 { Object m(); }
67
interface I2 { default Object m() { return "I2.m"; } }
68
69
static abstract class C { public abstract Object m(); }
70
71
static abstract class D extends C {
72
final Object ret = CORRECT;
73
public Object m() {
74
return ret;
75
}
76
}
77
78
static abstract class E1 extends C { /* empty */ }
79
static abstract class E2 extends C { public abstract Object m(); }
80
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
81
82
static abstract class F1 extends C implements I1 { }
83
static abstract class F2 extends C implements I2 { }
84
85
static class G extends C { public Object m() { return CORRECT; } }
86
87
@Override
88
public Object test(C obj) {
89
return obj.m(); // invokevirtual C.m()
90
}
91
92
@Override
93
public void checkInvalidReceiver() {
94
// nothing to do: concrete class types are enforced by the verifier
95
}
96
97
@TestCase
98
public void test() {
99
// 0. Trigger compilation of a megamorphic call site
100
compile(megamorphic()); // Dn <: D.m <: C.m ABSTRACT
101
assertCompiled();
102
103
// Dependency: type = unique_concrete_method, context = C, method = D.m
104
105
// 1. No invalidation: abstract classes don't participate in CHA.
106
initialize(E1.class, // ABSTRACT E1 <: C.m ABSTRACT
107
E2.class, // ABSTRACT E2.m ABSTRACT <: C.m ABSTRACT
108
E3.class, // ABSTRACT E3.m <: C.m ABSTRACT
109
F1.class, // ABSTRACT F1 <: C.m ABSTRACT, I1.m ABSTRACT
110
F2.class); // ABSTRACT F2 <: C.m ABSTRACT, I2.m DEFAULT
111
assertCompiled();
112
113
// 2. Dependency invalidation: G.m <: C.m ABSTRACT
114
load(G.class);
115
assertCompiled();
116
117
// 3. Dependency invalidation: G.m <: C.m ABSTRACT
118
initialize(G.class);
119
assertNotCompiled();
120
121
// 4. Recompilation: no inlining, no dependencies
122
compile(megamorphic());
123
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C.m ABSTRACT
124
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C.m ABSTRACT
125
assertCompiled();
126
}
127
}
128
public static class AbstractInterface extends ATest<AbstractInterface.C> {
129
public AbstractInterface() {
130
super(C.class, D.class);
131
}
132
133
interface I1 { Object m(); }
134
interface I2 extends I { default Object m() { return "I2.m"; } }
135
136
interface I { Object m(); }
137
138
static abstract class C implements I { /* inherited from I */}
139
140
static abstract class D extends C {
141
final Object ret = CORRECT;
142
public Object m() {
143
return ret;
144
}
145
}
146
147
static abstract class E1 extends C { /* empty */ }
148
static abstract class E2 extends C { public abstract Object m(); }
149
static abstract class E3 extends C { public Object m() { return "E3.m"; } }
150
151
static abstract class F1 extends C implements I1 { }
152
static abstract class F2 extends C implements I2 { }
153
154
static class G extends C { public Object m() { return CORRECT; } }
155
156
@Override
157
public Object test(C obj) {
158
return obj.m(); // invokevirtual C.m()
159
}
160
161
@Override
162
public void checkInvalidReceiver() {
163
// nothing to do: concrete class types are enforced by the verifier
164
}
165
166
@TestCase
167
public void test() {
168
// 0. Trigger compilation of a megamorphic call site
169
compile(megamorphic()); // Dn <: D.m <: C <: I.m ABSTRACT
170
assertCompiled();
171
172
// Dependency: type = unique_concrete_method, context = C, method = D.m
173
174
// 1. No invalidation: abstract classes don't participate in CHA.
175
initialize(E1.class, // ABSTRACT E1 <: C <: I.m ABSTRACT
176
E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m ABSTRACT
177
E3.class, // ABSTRACT E3.m <: C <: I.m ABSTRACT
178
F1.class, // ABSTRACT F1 <: C <: I.m ABSTRACT, I1.m ABSTRACT
179
F2.class); // ABSTRACT F2 <: C <: I.m ABSTRACT, I2.m DEFAULT
180
assertCompiled();
181
182
// 2. Dependency invalidation: G.m <: C <: I.m ABSTRACT
183
load(G.class);
184
assertCompiled();
185
186
// 3. Dependency invalidation: G.m <: C <: I.m ABSTRACT
187
initialize(G.class);
188
assertNotCompiled();
189
190
// 4. Recompilation: no inlining, no dependencies
191
compile(megamorphic());
192
call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m ABSTRACT
193
call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m ABSTRACT
194
assertCompiled();
195
}
196
}
197
}
198
199