JDK-8289721 : Hotspot8 and Hotspot11 get different results when executing the same test case
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2022-07-04
  • Updated: 2022-07-06
  • Resolved: 2022-07-05
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Microsoft Windows 10 Professional
10.0.19044 Build 19044
AMD Ryzen 5 5600G with Radeon Graphics 3.90 GHz
Memory 32 GB

A DESCRIPTION OF THE PROBLEM :
For the simple test case in the attachment, we get different results when we execute using JDK8 than when we execute using JDK11


---------- BEGIN SOURCE ----------
public class testCase8 {
    public static int my_check_sum = 0;
    public testCase8() {}

    public void f() {
        for(int i=0;i<20;i++){
            for(int j=0;j<5000;j++){
                double var3 = Math.pow((double) i, (double) j);
                my_check_sum = Integer.hashCode(my_check_sum+Double.hashCode(var3));
            }
        }
    }

    public static void main(String[] var0) {
        testCase8 var1 = new testCase8();
        var1.f();
        System.out.print("my_check_sum_value:");
        System.out.println(my_check_sum);
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Thanks [~darcy]!
06-07-2022

Possible consequence of JDK-8145688.
05-07-2022

Math.pow implementations are explicitly allowed to return different results for the same inputs, subject to the quality of implementation criteria. Different intrinsifictions of pow would be expected to return slightly different results for some arguments.
05-07-2022

I changed the call to Math.pow to StrictMath.pow and now I see: > java8 -Xint Testcase8 my_check_sum_value:1948193764 > java9 -Xint Testcase8 my_check_sum_value:1948193764 > java17 -Xint Testcase8 my_check_sum_value:1948193764 so this seems not a bug, just the imprecision of floating-point arithmetic.
05-07-2022

I see the same results comparing 8 and 9 and using -Xint. So I'm not sure this would be a hotspot issue. I'm also not sure if the test program is guaranteed to always give the same result. [~darcy] could you comment?
05-07-2022

Issue is reproduced. JDK 8 gives different output. OS: Windows10 JDK 8u333: Fail Output: "my_check_sum_value:1948193948" JDK 11.0.15.1 : Pass Output: "my_check_sum_value:1948193993" JDK 17.0.3.1: Pass Output: "my_check_sum_value:1948193993" JDK 18.0.1.1: Pass Output: "my_check_sum_value:1948193993" Moving it to Dev team for further evaluation
05-07-2022