From 9d204bb4916c312e0824fcfeed6608e46defdfb3 Mon Sep 17 00:00:00 2001 From: duke Date: Mon, 19 Jun 2023 15:41:31 +0000 Subject: [PATCH] Backport d07f7c76c5df1473bffa41f10a89ca1e21e001ef --- .../intrinsics/unsafe/ByteBufferTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/hotspot/jtreg/compiler/intrinsics/unsafe/ByteBufferTest.java b/test/hotspot/jtreg/compiler/intrinsics/unsafe/ByteBufferTest.java index 6294e90a8a9..194ce17af7a 100644 --- a/test/hotspot/jtreg/compiler/intrinsics/unsafe/ByteBufferTest.java +++ b/test/hotspot/jtreg/compiler/intrinsics/unsafe/ByteBufferTest.java @@ -211,13 +211,22 @@ short getShortX(long a) { void ck(long x, long y) { if (x != y) { - throw new RuntimeException(" x = " + Long.toHexString(x) + ", y = " + Long.toHexString(y)); + throw new RuntimeException("expect x == y: x = " + Long.toHexString(x) + ", y = " + Long.toHexString(y)); } } void ck(double x, double y) { - if (x == x && y == y && x != y) { - ck(x, y); + // Check if x and y have identical values. + // Remember: NaN == x is false for ANY x, including if x is NaN (IEEE standard). + // Therefore, if x and y are NaN, x != y would return true, which is not what we want. + // We do not want an Exception if both are NaN. + // Double.compare takes care of these special cases + // including NaNs, and comparing -0.0 to 0.0 + if (Double.compare(x,y) != 0) { + throw new RuntimeException("expect x == y:" + + " x = " + Double.toString(x) + ", y = " + Double.toString(y) + + " (x = " + Long.toHexString(Double.doubleToRawLongBits(x)) + + ", y = " + Long.toHexString(Double.doubleToRawLongBits(y)) + ")"); } }