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 720 forks source link

JTReg Test Failure: java/lang/annotation/loaderLeak/Main.java #6701

Open adam-thorpe opened 5 years ago

adam-thorpe commented 5 years ago

Failure link

Optional info

Failure output (captured from console output)

Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Exception in thread "main" java.lang.AssertionError
        at Main.doTest(Main.java:56)
        at Main.main(Main.java:41)
pdbain-ibm commented 5 years ago

Reproduced locally. Investigating...

pdbain-ibm commented 5 years ago

This test is invalid.

        ClassLoader loader = new SimpleClassLoader();
        WeakReference<Class<?>> c = new WeakReference(loader.loadClass("C"));   <<< line 49
        if (c.get() == null) throw new AssertionError();
        if (c.get().getClassLoader() != loader) throw new AssertionError();
        if (readAnn) System.out.println(c.get().getAnnotations()[0]);
        if (c.get() == null) throw new AssertionError();
        System.gc();
        System.gc();
        if (c.get() == null) throw new AssertionError(); <<< Failing line 56

Line 49 creates a weak reference to the Class object for C. It then runs two GCs, which clear the weak reference to the Class object because there are no strong references to the object, as designed.