eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k stars 721 forks source link

ConcurrentSkipListSet.add presents nondeterministic results #6597

Open non-conformances-research opened 5 years ago

non-conformances-research commented 5 years ago

The following sample program presents different results when executed multiple times.

public class A {
   public static void main(String args[]) {
      ConcurrentSkipListSet concurrentSkipListSet = new ConcurrentSkipListSet();
      System.out.println(concurrentSkipListSet.add(new Object()));
   }
}

Affected versions:

openjdk version "1.8.0_162" OpenJDK Runtime Environment (build 1.8.0_162-b12) Eclipse OpenJ9 VM (build openj9-0.8.0, JRE 1.8.0 Linux amd64-64 Compressed References 20180315_120 (JIT enabled, AOT enabled) OpenJ9 - e24e8aa9 OMR - 3e8296b4 JCL - ee1e77df1d based on jdk8u162-b12)

Steps to reproduce:

  1. Compile above program
  2. Run it using Eclipse OpenJ9 java

Current result:

Sometimes true, sometimes ClassCastException.

Expected result:

true

pdbain-ibm commented 5 years ago

ClassCastException is the correct response: from the API:

... 
public boolean add(E e)
....
Throws:
ClassCastException - if e cannot be compared with the elements currently in this set

I ran > 100 times, with default options, -Xint, and -Xjit:count=0 on the latest Java 11:

openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11-201907311154)
Eclipse OpenJ9 VM AdoptOpenJDK (build master-9e310fd9b, JRE 11 Mac OS X amd64-64-Bit Compressed References 20190731_298 (JIT enabled, AOT enabled)
OpenJ9   - 9e310fd9b
OMR      - f3e16702
JCL      - 3ed58f51d2 based on jdk-11.0.4+11)

and consistently got the exception. Note that OpenJDK Java 11 has the same behaviour.

Java 8:

OpenJDK Runtime Environment (build 1.8.0_222-201907311218-b10)
Eclipse OpenJ9 VM (build master-9e310fd9b, JRE 1.8.0 Mac OS X amd64-64-Bit Compressed References 20190731_306 (JIT enabled, AOT enabled)
OpenJ9   - 9e310fd9b
OMR      - f3e16702
JCL      - 46e5e62038 based on jdk8u222-b10)

does show a mixture of behaviours with -Xint as described above.

I tested with OpenJDK Java 8 with HotSpot:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)

and it also shows inconsistent behaviour.

This is a bug in the implementations of java.util.concurrent.ConcurrentSkipListSet et al. Please open an OpenJDK problem report and close this issue, #6595, and #6596.