Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/floatingpoint/NaNTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 2021, 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
* @test
25
* @bug 8076373
26
* @summary Verify if signaling NaNs are preserved.
27
* @library /test/lib /
28
*
29
* @build sun.hotspot.WhiteBox
30
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
31
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
32
* compiler.floatingpoint.NaNTest
33
*/
34
35
package compiler.floatingpoint;
36
37
import jdk.test.lib.Platform;
38
import jtreg.SkippedException;
39
import sun.hotspot.WhiteBox;
40
41
public class NaNTest {
42
static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
43
44
static void testFloat() {
45
int originalValue = 0x7f800001;
46
int readBackValue = Float.floatToRawIntBits(Float.intBitsToFloat(originalValue));
47
if (originalValue != readBackValue) {
48
String errorMessage = String.format("Original and read back float values mismatch\n0x%X 0x%X\n",
49
originalValue,
50
readBackValue);
51
throw new RuntimeException(errorMessage);
52
} else {
53
System.out.printf("Written and read back float values match\n0x%X 0x%X\n",
54
originalValue,
55
readBackValue);
56
}
57
}
58
59
static void testDouble() {
60
long originalValue = 0xFFF0000000000001L;
61
long readBackValue = Double.doubleToRawLongBits(Double.longBitsToDouble(originalValue));
62
if (originalValue != readBackValue) {
63
String errorMessage = String.format("Original and read back double values mismatch\n0x%X 0x%X\n",
64
originalValue,
65
readBackValue);
66
throw new RuntimeException(errorMessage);
67
} else {
68
System.out.printf("Written and read back double values match\n0x%X 0x%X\n",
69
originalValue,
70
readBackValue);
71
}
72
73
}
74
75
public static void main(String args[]) {
76
// Some platforms are known to strip signaling NaNs.
77
// The block below can be used to except them.
78
boolean expectStableFloats = true;
79
boolean expectStableDoubles = true;
80
81
// On x86_32 without relevant SSE-enabled stubs, we are entering
82
// native methods that use FPU instructions, and those strip the
83
// signaling NaNs.
84
if (Platform.isX86()) {
85
int sse = WHITE_BOX.getIntxVMFlag("UseSSE").intValue();
86
expectStableFloats = (sse >= 1);
87
expectStableDoubles = (sse >= 2);
88
}
89
90
if (expectStableFloats) {
91
testFloat();
92
} else {
93
System.out.println("Stable floats cannot be expected, skipping");
94
}
95
96
if (expectStableDoubles) {
97
testDouble();
98
} else {
99
System.out.println("Stable doubles cannot be expected, skipping");
100
}
101
102
if (!expectStableFloats && !expectStableDoubles) {
103
throw new SkippedException("No tests were run.");
104
}
105
}
106
}
107
108