< prev index next >
test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java
Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
rev 58568 : [mq]: hidden-class-4
@@ -22,10 +22,11 @@
*/
/*
* @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
*/
@@ -104,24 +105,26 @@
/*
* Create a nest of two hidden classes.
* 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");
Lookup lookup = (Lookup)m.invoke(null);
HiddenClassUnloader[] unloaders = createNestOfTwoHiddenClasses(lookup, false, false);
// 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
unloaders[0].unload();
unloaders[1].unload();
@@ -204,11 +207,11 @@
}
static class HiddenClassUnloader {
private final WeakReference<Class<?>> weakRef;
private HiddenClassUnloader(Class<?> hc) {
- assertTrue(hc.isHiddenClass());
+ assertTrue(hc.isHidden());
this.weakRef = new WeakReference<>(hc);
}
void unload() {
// Force garbage collection to trigger unloading of class loader and native library
< prev index next >