Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/c1/TestRangeCheckEliminated.java
64474 views
1
/*
2
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
3
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/*
26
* @test
27
* @bug 8263707
28
* @summary Test range check for constant array and NewMultiArray is removed properly
29
* @author Hui Shi
30
*
31
* @requires vm.flagless
32
* @requires vm.debug == true & vm.compiler1.enabled
33
*
34
* @library /test/lib
35
*
36
* @run driver compiler.c1.TestRangeCheckEliminated
37
*/
38
39
package compiler.c1;
40
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.process.ProcessTools;
43
44
public class TestRangeCheckEliminated {
45
static final String eliminated = "can be fully eliminated";
46
public static void main(String[] args) throws Throwable {
47
boolean error = false;
48
String[] procArgs = new String[] {
49
"-XX:CompileCommand=compileonly,*test_constant_array::constant_array_rc",
50
"-XX:TieredStopAtLevel=1",
51
"-XX:+TraceRangeCheckElimination",
52
"-XX:-BackgroundCompilation",
53
"-XX:CompileThreshold=500",
54
test_constant_array.class.getName()
55
};
56
57
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);
58
String output = new OutputAnalyzer(pb.start()).getOutput();
59
// should have 2 "can be fully eliminated"
60
System.out.println(output);
61
if ((output.split(eliminated, -1).length - 1) == 2) {
62
System.out.println("test_constant_array pass");
63
} else {
64
System.out.println("test_constant_array fail");
65
error = true;
66
}
67
68
procArgs = new String[] {
69
"-XX:CompileCommand=compileonly,*test_multi_constant_array::multi_constant_array_rc",
70
"-XX:TieredStopAtLevel=1",
71
"-XX:+TraceRangeCheckElimination",
72
"-XX:-BackgroundCompilation",
73
"-XX:CompileThreshold=500",
74
test_multi_constant_array.class.getName()
75
};
76
77
pb = ProcessTools.createJavaProcessBuilder(procArgs);
78
output = new OutputAnalyzer(pb.start()).getOutput();
79
// should have 1 "can be fully eliminated"
80
System.out.println(output);
81
if ((output.split(eliminated, -1).length - 1) == 1) {
82
System.out.println("test_multi_constant_array pass");
83
} else {
84
System.out.println("test_multi_constant_array fail");
85
error = true;
86
}
87
88
procArgs = new String[] {
89
"-XX:CompileCommand=compileonly,*test_multi_new_array::multi_new_array_rc",
90
"-XX:TieredStopAtLevel=1",
91
"-XX:+TraceRangeCheckElimination",
92
"-XX:-BackgroundCompilation",
93
"-XX:CompileThreshold=500",
94
test_multi_new_array.class.getName()
95
};
96
97
pb = ProcessTools.createJavaProcessBuilder(procArgs);
98
output = new OutputAnalyzer(pb.start()).getOutput();
99
// should have 2 "can be fully eliminated"
100
System.out.println(output);
101
if ((output.split(eliminated, -1).length - 1) == 2) {
102
System.out.println("test_multi_new_array pass");
103
} else {
104
System.out.println("test_multi_new_array fail");
105
error = true;
106
}
107
108
if (error) {
109
throw new InternalError();
110
}
111
}
112
113
public static class test_constant_array {
114
static final int constant_array[] =
115
{50,60,55,67,70,62,65,70,70,81,72,66,77,80,69};
116
static void constant_array_rc() {
117
constant_array[1] += 5;
118
}
119
120
public static void main(String[] args) {
121
for(int i = 0; i < 1_000; i++) {
122
constant_array_rc();
123
}
124
}
125
}
126
127
public static class test_multi_constant_array {
128
static final int constant_multi_array[][] = {
129
{50,60,55,67,70}, {62,65,70,70,81}, {72,66,77,80,69}};
130
static void multi_constant_array_rc() {
131
constant_multi_array[2][3] += 5;
132
}
133
134
public static void main(String[] args) {
135
for(int i = 0; i < 1_000; i++) {
136
multi_constant_array_rc();
137
}
138
}
139
}
140
141
public static class test_multi_new_array {
142
static void foo(int i) {}
143
static void multi_new_array_rc(int index) {
144
int na[] = new int[800];
145
int nma[][] = new int[600][2];
146
nma[20][1] += 5; // optimize rc on NewMultiArray first dimension
147
nma[index][0] = 0; // index < 600 after this statement
148
foo(na[index]); // index must < 800, remove rc
149
}
150
151
public static void main(String[] args) {
152
for(int i = 0; i < 600; i++) {
153
multi_new_array_rc(i);
154
}
155
}
156
}
157
}
158
159