Path: blob/master/test/hotspot/jtreg/compiler/floatingpoint/NaNTest.java
41149 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/**23* @test24* @bug 807637325* @summary Verify if signaling NaNs are preserved.26* @library /test/lib /27*28* @build sun.hotspot.WhiteBox29* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox30* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI31* compiler.floatingpoint.NaNTest32*/3334package compiler.floatingpoint;3536import jdk.test.lib.Platform;37import jtreg.SkippedException;38import sun.hotspot.WhiteBox;3940public class NaNTest {41static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();4243static void testFloat() {44int originalValue = 0x7f800001;45int readBackValue = Float.floatToRawIntBits(Float.intBitsToFloat(originalValue));46if (originalValue != readBackValue) {47String errorMessage = String.format("Original and read back float values mismatch\n0x%X 0x%X\n",48originalValue,49readBackValue);50throw new RuntimeException(errorMessage);51} else {52System.out.printf("Written and read back float values match\n0x%X 0x%X\n",53originalValue,54readBackValue);55}56}5758static void testDouble() {59long originalValue = 0xFFF0000000000001L;60long readBackValue = Double.doubleToRawLongBits(Double.longBitsToDouble(originalValue));61if (originalValue != readBackValue) {62String errorMessage = String.format("Original and read back double values mismatch\n0x%X 0x%X\n",63originalValue,64readBackValue);65throw new RuntimeException(errorMessage);66} else {67System.out.printf("Written and read back double values match\n0x%X 0x%X\n",68originalValue,69readBackValue);70}7172}7374public static void main(String args[]) {75// Some platforms are known to strip signaling NaNs.76// The block below can be used to except them.77boolean expectStableFloats = true;78boolean expectStableDoubles = true;7980// On x86_32 without relevant SSE-enabled stubs, we are entering81// native methods that use FPU instructions, and those strip the82// signaling NaNs.83if (Platform.isX86()) {84int sse = WHITE_BOX.getIntxVMFlag("UseSSE").intValue();85expectStableFloats = (sse >= 1);86expectStableDoubles = (sse >= 2);87}8889if (expectStableFloats) {90testFloat();91} else {92System.out.println("Stable floats cannot be expected, skipping");93}9495if (expectStableDoubles) {96testDouble();97} else {98System.out.println("Stable doubles cannot be expected, skipping");99}100101if (!expectStableFloats && !expectStableDoubles) {102throw new SkippedException("No tests were run.");103}104}105}106107108