Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java
41159 views
1
/*
2
* Copyright (c) 2013, 2015, 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
package compiler.intrinsics.mathexact.sanity;
25
26
import compiler.testlibrary.intrinsics.Verifier;
27
import compiler.whitebox.CompilerWhiteBoxTest;
28
import jdk.test.lib.Platform;
29
30
import java.io.FileOutputStream;
31
import java.lang.reflect.Executable;
32
import java.util.Properties;
33
34
public abstract class IntrinsicBase extends CompilerWhiteBoxTest {
35
protected String useMathExactIntrinsics;
36
37
protected IntrinsicBase(TestCase testCase) {
38
super(testCase);
39
useMathExactIntrinsics = getVMOption("UseMathExactIntrinsics");
40
}
41
42
@Override
43
protected void test() throws Exception {
44
//java.lang.Math should be loaded to allow a compilation of the methods that use Math's method
45
System.out.println("class java.lang.Math should be loaded. Proof: " + Math.class);
46
printEnvironmentInfo();
47
if (Platform.isInt()) {
48
throw new Error("TESTBUG: test can not be run in interpreter");
49
}
50
51
int expectedIntrinsicCount = 0;
52
53
if (Platform.isServer() && !Platform.isEmulatedClient()) {
54
if (TIERED_COMPILATION) {
55
int max_level = TIERED_STOP_AT_LEVEL;
56
expectedIntrinsicCount = (max_level == COMP_LEVEL_MAX) ? 1 : 0;
57
for (int i = COMP_LEVEL_SIMPLE; i <= max_level; ++i) {
58
deoptimize();
59
compileAtLevel(i);
60
}
61
} else {
62
expectedIntrinsicCount = 1;
63
deoptimize();
64
compileAtLevel(COMP_LEVEL_MAX);
65
}
66
} else {
67
deoptimize();
68
compileAtLevel(COMP_LEVEL_SIMPLE);
69
}
70
71
if (!isIntrinsicAvailable()) {
72
expectedIntrinsicCount = 0;
73
}
74
75
System.out.println("Expected intrinsic count is " + expectedIntrinsicCount + " name " + getIntrinsicId());
76
77
final FileOutputStream out = new FileOutputStream(getVMOption("LogFile") + Verifier.PROPERTY_FILE_SUFFIX);
78
Properties expectedProps = new Properties();
79
expectedProps.setProperty(Verifier.INTRINSIC_NAME_PROPERTY, getIntrinsicId());
80
expectedProps.setProperty(Verifier.INTRINSIC_EXPECTED_COUNT_PROPERTY, String.valueOf(expectedIntrinsicCount));
81
expectedProps.store(out, null);
82
83
out.close();
84
}
85
86
protected void printEnvironmentInfo() {
87
System.out.println("os.arch=" + Platform.getOsArch());
88
System.out.println("java.vm.info=" + Platform.vmInfo);
89
System.out.println("useMathExactIntrinsics=" + useMathExactIntrinsics);
90
}
91
92
protected void compileAtLevel(int level) {
93
WHITE_BOX.enqueueMethodForCompilation(method, level);
94
waitBackgroundCompilation();
95
checkCompilation(method, level);
96
}
97
98
protected void checkCompilation(Executable executable, int level) {
99
if (!WHITE_BOX.isMethodCompiled(executable)) {
100
throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but not compiled");
101
}
102
final int compilationLevel = WHITE_BOX.getMethodCompilationLevel(executable);
103
if (compilationLevel != level) {
104
if (!(TIERED_COMPILATION && level == COMP_LEVEL_FULL_PROFILE && compilationLevel == COMP_LEVEL_LIMITED_PROFILE)) { //possible case
105
throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but level: " + compilationLevel);
106
}
107
}
108
}
109
110
// An intrinsic is available if:
111
// - the intrinsic is enabled (by using the appropriate command-line flag) and
112
// - the intrinsic is supported by the VM (i.e., the platform on which the VM is
113
// running provides the instructions necessary for the VM to generate the intrinsic).
114
protected abstract boolean isIntrinsicAvailable();
115
116
protected abstract String getIntrinsicId();
117
118
static class IntTest extends IntrinsicBase {
119
120
protected boolean isIntrinsicAvailable; // The tested intrinsic is available on the current platform.
121
122
protected IntTest(MathIntrinsic.IntIntrinsic testCase) {
123
super(testCase);
124
// Only the C2 compiler intrinsifies exact math methods
125
// so check if the intrinsics are available with C2.
126
isIntrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(testCase.getTestMethod(),
127
COMP_LEVEL_FULL_OPTIMIZATION);
128
}
129
130
@Override
131
protected boolean isIntrinsicAvailable() {
132
return isIntrinsicAvailable;
133
}
134
135
@Override
136
protected String getIntrinsicId() {
137
return "_" + testCase.name().toLowerCase() + "ExactI";
138
}
139
}
140
141
static class LongTest extends IntrinsicBase {
142
143
protected boolean isIntrinsicAvailable; // The tested intrinsic is available on the current platform.
144
145
protected LongTest(MathIntrinsic.LongIntrinsic testCase) {
146
super(testCase);
147
// Only the C2 compiler intrinsifies exact math methods
148
// so check if the intrinsics are available with C2.
149
isIntrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(testCase.getTestMethod(),
150
COMP_LEVEL_FULL_OPTIMIZATION);
151
}
152
153
@Override
154
protected boolean isIntrinsicAvailable() {
155
return isIntrinsicAvailable;
156
}
157
158
@Override
159
protected String getIntrinsicId() {
160
return "_" + testCase.name().toLowerCase() + "ExactL";
161
}
162
}
163
}
164
165