Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/inlining/ResolvedClassTest.java
64474 views
1
/*
2
* Copyright (c) 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
* @bug 8279515
27
*
28
* @requires vm.flagless & vm.compiler1.enabled & vm.compiler2.enabled
29
* @modules java.base/jdk.internal.misc
30
* @library /test/lib /
31
*
32
* @run driver compiler.jsr292.ResolvedClassTest
33
*/
34
35
package compiler.jsr292;
36
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.process.ProcessTools;
39
40
import java.io.IOException;
41
42
public class ResolvedClassTest {
43
/* ======================================================================== */
44
static void testStatic() throws IOException {
45
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
46
"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
47
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
48
"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestStatic.class.getName() + "::test",
49
TestStatic.class.getName());
50
51
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
52
53
analyzer.shouldHaveExitValue(0);
54
55
analyzer.shouldNotContain("TestStatic$A::m (1 bytes) not inlineable");
56
analyzer.shouldNotContain("TestStatic$A::m (1 bytes) no static binding");
57
58
analyzer.shouldContain("TestStatic$A::m (1 bytes) inline");
59
}
60
61
static class TestStatic {
62
static class A {
63
static void m() {}
64
}
65
static class B extends A {}
66
67
// @DontInline
68
static void test() {
69
B.m(); // invokestatic B "m" => A::m
70
}
71
72
public static void main(String[] args) {
73
for (int i = 0; i < 20_000; i++) {
74
test();
75
}
76
}
77
}
78
79
/* ======================================================================== */
80
static void testStaticInit() throws IOException {
81
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
82
"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
83
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
84
"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestStaticInit.class.getName() + "::test",
85
TestStaticInit.class.getName());
86
87
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
88
89
analyzer.shouldHaveExitValue(0);
90
91
analyzer.shouldContain("TestStaticInit$A::m (1 bytes) no static binding");
92
}
93
94
static class TestStaticInit {
95
static class A {
96
static {
97
for (int i = 0; i < 20_000; i++) {
98
TestStaticInit.test();
99
}
100
}
101
102
static void m() {}
103
}
104
static class B extends A {}
105
106
// @DontInline
107
static void test() {
108
B.m(); // A::<clinit> => test() => A::m()
109
}
110
111
public static void main(String[] args) {
112
A.m(); // trigger initialization of A
113
}
114
}
115
116
/* ======================================================================== */
117
static void testIndy() throws IOException {
118
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
119
"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
120
"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
121
"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestIndy.class.getName() + "::test",
122
TestIndy.class.getName());
123
124
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
125
126
analyzer.shouldHaveExitValue(0);
127
128
analyzer.shouldNotMatch("java\\.lang\\.invoke\\..+::linkToTargetMethod \\(9 bytes\\) not inlineable");
129
130
analyzer.shouldMatch("java\\.lang\\.invoke\\..+::linkToTargetMethod \\(9 bytes\\) force inline by annotation");
131
analyzer.shouldContain("java/lang/invoke/MethodHandle::invokeBasic (not loaded) not inlineable");
132
}
133
134
static class TestIndy {
135
static String str = "";
136
137
// @DontInline
138
static void test() {
139
String s1 = "" + str; // indy (linked)
140
141
for (int i = 0; i < 200_000; i++) {} // trigger OSR compilation
142
143
String s2 = "" + str; // indy (not linked)
144
}
145
146
public static void main(String[] args) {
147
test();
148
}
149
}
150
151
/* ======================================================================== */
152
153
public static void main(String[] args) throws IOException {
154
testStatic();
155
testStaticInit();
156
testIndy();
157
}
158
}
159
160