Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestDivZeroCheckControl.java
41149 views
1
/*
2
* Copyright (c) 2019, 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
/*
26
* @test
27
* @bug 8229496
28
* @summary Verify that zero check is executed before division/modulo operation.
29
* @requires vm.compiler2.enabled
30
* @run main/othervm -Xbatch -XX:LoopUnrollLimit=0
31
* -XX:CompileCommand=dontinline,compiler.loopopts.TestDivZeroCheckControl::test*
32
* compiler.loopopts.TestDivZeroCheckControl
33
*/
34
35
/*
36
* @test
37
* @summary Verify that zero check is executed before division/modulo operation.
38
* @requires vm.graal.enabled
39
* @run main/othervm -Xbatch
40
* -XX:CompileCommand=dontinline,compiler.loopopts.TestDivZeroCheckControl::test*
41
* compiler.loopopts.TestDivZeroCheckControl
42
*/
43
44
package compiler.loopopts;
45
46
public class TestDivZeroCheckControl {
47
48
public static int test1(int div, int array[]) {
49
int res = 0;
50
for (int i = 0; i < 256; i++) {
51
int j = 0;
52
do {
53
array[i] = i;
54
try {
55
res = 1 % div;
56
} catch (ArithmeticException ex) { }
57
} while (++j < 9);
58
}
59
return res;
60
}
61
62
// Same as test1 but with division instead of modulo
63
public static int test2(int div, int array[]) {
64
int res = 0;
65
for (int i = 0; i < 256; i++) {
66
int j = 0;
67
do {
68
array[i] = i;
69
try {
70
res = 1 / div;
71
} catch (ArithmeticException ex) { }
72
} while (++j < 9);
73
}
74
return res;
75
}
76
77
// Same as test1 but with long
78
public static long test3(long div, int array[]) {
79
long res = 0;
80
for (int i = 0; i < 256; i++) {
81
int j = 0;
82
do {
83
array[i] = i;
84
try {
85
res = 1L % div;
86
} catch (ArithmeticException ex) { }
87
} while (++j < 9);
88
}
89
return res;
90
}
91
92
// Same as test2 but with long
93
public static long test4(long div, int array[]) {
94
long res = 0;
95
for (int i = 0; i < 256; i++) {
96
int j = 0;
97
do {
98
array[i] = i;
99
try {
100
res = 1L / div;
101
} catch (ArithmeticException ex) { }
102
} while (++j < 9);
103
}
104
return res;
105
}
106
107
public static void main(String[] args) {
108
int array[] = new int[256];
109
for (int i = 0; i < 50_000; ++i) {
110
test1(0, array);
111
test2(0, array);
112
test3(0, array);
113
test4(0, array);
114
}
115
}
116
}
117
118