RFR 8220088 : Test "java/lang/annotation/loaderLeak/Main.java" fails with -Xcomp

Brent Christian brent.christian at oracle.com
Wed Mar 13 22:44:15 UTC 2019


Please review my test-only fix for 8220088[1].  Along with fixing the 
issue, I've also converted this .sh test to .java.

Webrev is here:

The test does the following:
1. sets up a classloader and loads class "C" into a WeakReference
2. runs a few GCs and ensures that the C class is still live
3. clears the reference to the classloader and runs a few more GCs
4. ensures that the C class has been collected (now that its classloader 
can also be collected)

When run with -Xcomp, the test fails with:

Exception in thread "main" java.lang.AssertionError
at Main.doTest(Main.java:56)
at Main.main(Main.java:41)

This comes from the code for step 2:

   if (c.get() == null) throw new AssertionError();

The C class is being collected before expected.

 From my testing, I believe that when the test is pre-compiled with 
-Xcomp, the VM sees that 'loader' gets null'ed out, and doesn't keep it 

My change to fix this issue is adding this check:

+ if (loader != null) { // Under -Xcomp, ensure loader is still alive
       loader = null;
+ }

There are probably other ways to accomplish this, though this worked 
well for local as well as automated testing.

The rest of the changes are for the .sh -> .java conversion.


1. https://bugs.openjdk.java.net/browse/JDK-8220088

More information about the core-libs-dev mailing list