JDK-6730716 : nulls from two unrelated classes compare not equal
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2008-07-28
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u14Fixed 7Fixed hs14Fixed
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
EVALUATION http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/ce93a51457ae
20-08-2008

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

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