United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8020215 Different execution plan when using JIT vs interpreter
JDK-8020215 : Different execution plan when using JIT vs interpreter

Details
Type:
Bug
Submit Date:
2013-06-28
Status:
Resolved
Updated Date:
2013-07-28
Project Name:
JDK
Resolved Date:
2013-07-16
Component:
hotspot
OS:
windows_7
Sub-Component:
compiler
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
hs24,hs25
Fixed Versions:
hs24,hs25

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version  " 1.7.0_25 " 
Java(TM) SE Runtime Environment (build 1.7.0_25_b16)
Java Hotspot(TM) 64-bit Server VM (build 23.25-b01, mixed mode)

FULL OS VERSION :
Windows 7 64-bit

EXTRA RELEVANT SYSTEM CONFIGURATION :
No additional configuration needed

A DESCRIPTION OF THE PROBLEM :
The attached sample program calls a method 10'000 times without changing any border conditions. As soon as the method gets compiled, the result of that method returns null instead of a instance.

Please note that the attached sample was stripped down a lot and multiple coding standards were violated to make the sample code as small as possible.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

REGRESSION.  Last worked in version 6u45

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) compile the sample java program
2) run it with the java interpreter -> run through
3) run it with the jit enabled -> returned method value is null and it throws an exception

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect that the program never throws an excpetion
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error messages

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;

public class TestJITError {
public static class NamedObject {
    public int id;
    public String name;
public NamedObject(int id, String name) {
this.id = id;
this.name = name;
}
}

public static class NamedObjectList {
public List<NamedObject> namedObjectList = new ArrayList<NamedObject>();

    public NamedObject getBest(int id) {
        NamedObject bestObject = null;
        for (NamedObject o : namedObjectList) {
            bestObject = id==o.id ? getBetter(bestObject, o) : bestObject;
        }
        return bestObject != null ? bestObject : null;
    }

    private static NamedObject getBetter(NamedObject p1, NamedObject p2) {
    return p1 == null ? p2 : (p2 == null) ? p1 : p2.name.compareTo(p1.name)>=0 ? p2 : p1;
    }
}

public static void main(String[] args) {
// setup
NamedObjectList b = new NamedObjectList();
for (int i = 0; i < 10000; i++) {
b.namedObjectList.add(new NamedObject(1,  " 2012-12-31 " ));
}
b.namedObjectList.add(new NamedObject(2,  " 2013-12-31 " ));

// execution
for (int i = 0; i < 100000; i++) {
NamedObject x = b.getBest(2);
// test
if (x == null) {
throw new RuntimeException( " x should never be null here!! (i= "  + i +  " ) " );
}
}
System.out.println( " finished " );
}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Refactoring of the java code will make it behave correctly.
                                    

Comments
When I disable Escape Analysis the test passes:

dhcp-santaclara22-3fl-west-10-132-189-104:~ ajiva$ jdk8/bin/java -showversion -XX:-DoEscapeAnalysis  TestJITError
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b94)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b36, mixed mode)

 finished 
dhcp-santaclara22-3fl-west-10-132-189-104:~ ajiva$ jdk8/bin/java -showversion TestJITError
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b94)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b36, mixed mode)

Exception in thread "main" java.lang.RuntimeException:  x should never be null here!! (i= 12288 ) 
	at TestJITError.main(TestJITError.java:43)
dhcp-santaclara22-3fl-west-10-132-189-104:~ ajiva$ 
                                     
2013-07-09
Yes, it is EA. It failedwith old (hs23)  and new code  (hs25).
                                     
2013-07-09
workaround: -XX:-OptimizePtrCompare

                                     
2013-07-10
7-critical-request justification:
Was found by external customer with jdk7. Small safe changes. The fix is pushed into hs25/jdk8 and will be tested (see https://jbs.oracle.com/bugs/browse/JDK-8020482).

                                     
2013-07-13



Hardware and Software, Engineered to Work Together