changeset 59593:19f8a7827a31 nestmates

[nestmates] Add reachability fence to UnloadingTest to ensure object not GC'ed
author mchung
date Mon, 30 Mar 2020 17:39:48 -0700
parents f4dc7eafeb51
children 912c4c0ca796
files test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java	Mon Mar 30 16:28:00 2020 -0700
+++ b/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java	Mon Mar 30 17:39:48 2020 -0700
@@ -24,6 +24,7 @@
 /*
  * @test
  * @summary verify if the hidden class is unloaded when the class loader is GC'ed
+ * @modules jdk.compiler
  * @library /test/lib/
  * @build jdk.test.lib.util.ForceGC
  * @run testng/othervm UnloadingTest
@@ -106,7 +107,7 @@
      * They can be unloaded even the loader is strongly reachable
      */
     @Test
-    public void hiddenClassNest2() throws Exception {
+    public void hiddenClassNest() throws Exception {
         TestLoader loader = new TestLoader();
         Class<?> helper = Class.forName("LookupHelper", true, loader);
         Method m = helper.getMethod("getLookup");
@@ -115,11 +116,13 @@
 
         // keep a strong reference to the nest member class
         Class<?> member = unloaders[1].weakRef.get();
+        assertTrue(member != null);
         // nest host and member will not be unloaded
         assertFalse(unloaders[0].tryUnload());
         assertFalse(unloaders[1].tryUnload());
 
         // clear the reference to the nest member
+        Reference.reachabilityFence(member);
         member = null;
 
         // nest host and member will be unloaded