United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6796786 invalid FP identity transform - (a - b) -> b - a
6796786 : invalid FP identity transform - (a - b) -> b - a

Details
Type:
Bug
Submit Date:
2009-01-22
Status:
Closed
Updated Date:
2011-07-29
Project Name:
JDK
Resolved Date:
2011-05-16
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
hs14
Fixed Versions:
hs21

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
Looks like static field access of uninitialized class leads to wrong 1/-0 result in case server compiler is used.

The following test case demonstrates this:

======== TesterSmall_10.java ========
final class TesterSmall_10_Class_0 {
    static float var_1 = 1;
    float var_2 = 1;
}

public class TesterSmall_10 {
    float var_3 = TesterSmall_10_Class_0.var_1; // changing this line to "float var_1 = 1" will make the test pass
    float var_bad;
    float var_ok;

    void test()
    {
        var_bad += 1 / -(TesterSmall_10_Class_0.var_1 -= TesterSmall_10_Class_0.var_1);

        TesterSmall_10_Class_0 t0 = new TesterSmall_10_Class_0();
        var_ok += 1 / -(t0.var_2 -= t0.var_2);
    }

    public static void main(String[] args)
    {
            TesterSmall_10 t = new TesterSmall_10();
            t.test();

            System.out.println(" Tester.var_ok = " + t.var_ok);
            System.out.println("Tester.var_bad = " + t.var_bad);

            System.out.println((t.var_bad == t.var_ok ? "PASS" : "FAIL") + "\n");
    }
}
=============================================

> java -server -Xcomp -XX:CompileOnly=Tester TesterSmall_10
 Tester.var_ok = -Infinity
Tester.var_bad = Infinity
FAIL

The test passes in -Xint and with client compiler:
> java -client -Xcomp -XX:CompileOnly=Tester TesterSmall_10
 Tester.var_ok = -Infinity
Tester.var_bad = -Infinity
PASS

                                    

Comments
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/f1d6640088a1
                                     
2011-05-04
EVALUATION

It doesn't have anything to do with the uninitialized classes.  They just effect whether the code gets compiled and executed by C2 or not.

The problem is that C2 is transforming the idiom - (a - b) into b - a which produces the wrong sign if a == b.  For this pattern:

float f = - (zero - zero);
System.out.println(f);

c2 will print 0.0 instead of -0.0.  The fix is simply to delete NegFNode::Ideal and NegDNode::Ideal
                                     
2009-01-29



Hardware and Software, Engineered to Work Together