|
24 | 24 | * @test
|
25 | 25 | * @bug 8076373
|
26 | 26 | * @summary Verify if signaling NaNs are preserved.
|
| 27 | + * @library /test/lib / |
27 | 28 | *
|
28 |
| - * @run main compiler.floatingpoint.NaNTest |
| 29 | + * @build sun.hotspot.WhiteBox |
| 30 | + * @run driver ClassFileInstaller sun.hotspot.WhiteBox |
| 31 | + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
| 32 | + * compiler.floatingpoint.NaNTest |
29 | 33 | */
|
30 | 34 |
|
31 | 35 | package compiler.floatingpoint;
|
32 | 36 |
|
| 37 | +import jdk.test.lib.Platform; |
| 38 | +import jtreg.SkippedException; |
| 39 | +import sun.hotspot.WhiteBox; |
| 40 | + |
33 | 41 | public class NaNTest {
|
| 42 | + static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
| 43 | + |
34 | 44 | static void testFloat() {
|
35 | 45 | int originalValue = 0x7f800001;
|
36 | 46 | int readBackValue = Float.floatToRawIntBits(Float.intBitsToFloat(originalValue));
|
@@ -63,11 +73,34 @@ static void testDouble() {
|
63 | 73 | }
|
64 | 74 |
|
65 | 75 | public static void main(String args[]) {
|
66 |
| - System.out.println("### NanTest started"); |
| 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 | + } |
67 | 95 |
|
68 |
| - testFloat(); |
69 |
| - testDouble(); |
| 96 | + if (expectStableDoubles) { |
| 97 | + testDouble(); |
| 98 | + } else { |
| 99 | + System.out.println("Stable doubles cannot be expected, skipping"); |
| 100 | + } |
70 | 101 |
|
71 |
| - System.out.println("### NanTest ended"); |
| 102 | + if (!expectStableFloats && !expectStableDoubles) { |
| 103 | + throw new SkippedException("No tests were run."); |
| 104 | + } |
72 | 105 | }
|
73 | 106 | }
|
0 commit comments