United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6730716 nulls from two unrelated classes compare not equal
JDK-6730716 : nulls from two unrelated classes compare not equal

Details
Type:
Bug
Submit Date:
2008-07-28
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
linux
Sub-Component:
compiler
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
hs14 (b04)

Related Reports
Backport:
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)


FULL OS VERSION :
Linux 2.6.25.6-27.fc8 #1 SMP Fri Jun 13 16:38:52 EDT 2008 i686 i686 i386 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
We reproduced this problem on several machines. Some are running 32 bit Linux on 64 bit cpu's. All have in common that they are multi-core Linux machines
processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 CPU          6400  @ 2.13GHz
stepping        : 2
cpu MHz         : 2128.043
cache size      : 2048 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm
bogomips        : 4265.81
clflush size    : 64


A DESCRIPTION OF THE PROBLEM :
Code below fails during runtime after loop 5000. This works fine on single-core machines, and on multi-core machines on Windows, but fails on multi-core machines on Linux. This using JDK 1.6


THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the code below, compile and run


EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
  Program prints number of cpus and exits normally
Actual using jdk 1.6 on multi-core Linux machines:
Number of cpus = 2
Failed at i = 5001

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Failed at i = 5001

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Class1
{
  private static  boolean   compare(ThreeClass threeClass, FiveClass fiveClass)
  {
    for (;;)
    {
      if  (threeClass == null || fiveClass == null)
      {
        return (Object)threeClass == (Object)fiveClass;
        // Using this line it works
        //return threeClass == null && fiveClass == null;
      }
      threeClass = threeClass.next;
      fiveClass = fiveClass.next;
    }
  }

  public static void main(String[] args)
  {
    System.out.println( "Number of cpus = " + Runtime.getRuntime().availableProcessors() );
    ThreeClass threeClass = new ThreeClass();
    threeClass.next = null;
    FiveClass fiveClass = new FiveClass();
    fiveClass.next = null;
    
    for ( int i = 0; i < 10000; i++ )
    {
      if ( !Class1.compare(threeClass, fiveClass) )
      {
        System.out.println( "Failed at i = " + i );
        break;
      }
    }
  }
}
class ThreeClass
{
  ThreeClass next;
}
class FiveClass
{
  FiveClass next;
}

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

CUSTOMER SUBMITTED WORKAROUND :
Replace the code
        return (Object)threeClass == (Object)fiveClass;
with the code:
        return threeClass == null && fiveClass == null;

                                    

Comments
SUGGESTED FIX

Fix Cmp[PN]Node::sub() to chack for not-null objects before assuming that objects
from unrelated classes are not equal.
                                     
2008-07-29
EVALUATION

The compiler "proves" that objects from unrelated classes are not equal.  Usually,
this is true, except when both object are null.
                                     
2008-07-29
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/ce93a51457ae
                                     
2008-08-20



Hardware and Software, Engineered to Work Together