Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/mathexact/SubExactIRepeatTest.java
41153 views
1
/*
2
* Copyright (c) 2013, 2020, 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
* @key randomness
27
* @bug 8026844
28
* @summary Test repeating subtractExact
29
* @library /test/lib /
30
* @modules java.base/jdk.internal.misc
31
* java.management
32
*
33
* @run main compiler.intrinsics.mathexact.SubExactIRepeatTest
34
*/
35
36
package compiler.intrinsics.mathexact;
37
38
import jdk.test.lib.Utils;
39
40
import java.util.Random;
41
42
public class SubExactIRepeatTest {
43
public static void main(String[] args) {
44
runTest(new Verify.SubExactI());
45
}
46
47
public static int nonExact(int x, int y, Verify.BinaryMethod method) {
48
int result = method.unchecked(x, y);
49
result += method.unchecked(x, y);
50
result += method.unchecked(x, y);
51
result += method.unchecked(x, y);
52
return result;
53
}
54
55
public static void runTest(Verify.BinaryMethod method) {
56
Random rnd = Utils.getRandomInstance();
57
for (int i = 0; i < 50000; ++i) {
58
int x = Integer.MIN_VALUE + 10;
59
int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
60
61
int c = rnd.nextInt() / 2;
62
int d = rnd.nextInt() / 2;
63
64
int a = catchingExact(x, y, method);
65
66
if (a != 36) {
67
throw new RuntimeException("a != 36 : " + a);
68
}
69
70
int b = nonExact(c, d, method);
71
int n = exact(c, d, method);
72
73
74
if (n != b) {
75
throw new RuntimeException("n != b : " + n + " != " + b);
76
}
77
}
78
}
79
80
public static int exact(int x, int y, Verify.BinaryMethod method) {
81
int result = 0;
82
result += method.checkMethod(x, y);
83
result += method.checkMethod(x, y);
84
result += method.checkMethod(x, y);
85
result += method.checkMethod(x, y);
86
return result;
87
}
88
89
public static int catchingExact(int x, int y, Verify.BinaryMethod method) {
90
int result = 0;
91
try {
92
result += 5;
93
result = method.checkMethod(x, y);
94
} catch (ArithmeticException e) {
95
result += 1;
96
}
97
try {
98
result += 6;
99
100
result += method.checkMethod(x, y);
101
} catch (ArithmeticException e) {
102
result += 2;
103
}
104
try {
105
result += 7;
106
result += method.checkMethod(x, y);
107
} catch (ArithmeticException e) {
108
result += 3;
109
}
110
try {
111
result += 8;
112
result += method.checkMethod(x, y);
113
} catch (ArithmeticException e) {
114
result += 4;
115
}
116
return result;
117
}
118
}
119
120