Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4180399

javac does not always evaluate denormal constant expressions as strict

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 1.4.0
    • 1.2.0
    • tools
    • beta
    • generic
    • solaris_2.5.1
    • Verified

    Description

       Javac/x86/JIT (JDK 1.2fcs-J and -K) fails to pass lang/FP/fpl03502m2 and
                 lang/FP/fpl03502m4 tests from JCK 1.2(beta4), which check if compile-time
                 constant expression is treated FP-strict.

                 These tests calculate a number of double constant expressions, and each of
                 those expressions result in a double value slightly greater than 1. That tiny
                 appendix to 1.0 vanishes, if constant-expression is incorrectly calculated
                 using extended floating-point format suffering second rounding error when
                 rounded to standard format. (The tests are designed to catch mantissa
                 extensions upto 105 significand bits.)

                 Below is the shortest check extracted from fpl03502m2, which produces error
                 message:

                 --------------------------------------------------------------------------------

                 public class fpl352m24 {

                     public static void main (String args[]) {

                         double test_value = 1 + (double)((1L<<11) +
                 1)/(1L<<11)/(1L<<53);

                         double correct_value = Double.longBitsToDouble(0x3ff0000000000001L);

                         if (test_value != correct_value) {
                             println("test_value = " + test_value);
                             println("instead of: " + correct_value +
                                 " == Double.longBitsToDouble(0x3ffe000000000001)");

                         };
                     };

                     static void println (Object x) {
                         System.out.println( x );
                     };
                 }

                 ---- Prints:

                 test_value = 1.0
                 instead of: 1.0000000000000002 == Double.longBitsToDouble(0x3ffe000000000001)

                 --------------------------------------------------------------------------------

                 The following disassembled fragment compiled by javac/x86 with JIT shows,
                 that test_value is incorrectly computed at compile time:

                 --------------------------------------------------------------------------------

                 public static Method main:"([Ljava/lang/String;)V"
                         stack 4 locals 5
                 {
                         // test_value = 1 + (double)((1L<<11) +
                 1)/(1L<<11)/(1L<<53):
                                 dconst_1; // incorrectly rounded to 1.0 !!!
                                 dstore_1;

                         // correct_result = Double.longBitsToDouble(0x3ff0000000000001L):
                                 ldc2_w long 4607182418800017409l;
                                 invokestatic Method java/lang/Double.longBitsToDouble:"(J)D";
                                 dstore_3;

                         // if (test_value == correct_result) goto O'Key;
                                 dload_1;
                                 dload_3;
                                 dcmpl;
                                 ifeq L58;

                 // ...print error message...

                         L58: return;
                 }

                 --------------------------------------------------------------------------------

                 Nevertheless, the same fragment translated with no JIT using the command:
                     javac -J-Djava.compiler=none ...
                 is compiled correctly, and the test does not print error message.

                 So, javac/x86/JIT (JDK 1.2 fcs-J & -K) incorrectly calculates some double
                 constant expressions. Maybe, javac does not says to JIT to calculate those
                 expressions FP-strict.

                 But, see also BugId 4175714: "JIT/x86 suffers more than one rounding error
                 in FP-strict addition".

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              dstoutamsunw David Stoutamire (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: