From 6e43f48fcf342266b3d50688af7ae4664c018ac8 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Mon, 13 Jan 2025 12:50:13 +0000 Subject: [PATCH] 8346929: runtime/ClassUnload/DictionaryDependsTest.java fails with "Test failed: should be unloaded" Reviewed-by: dholmes, ccheung --- .../runtime/ClassUnload/DictionaryDependsTest.java | 12 +++++++----- .../jtreg/runtime/ClassUnload/KeepAliveClass.java | 14 +++++--------- .../runtime/ClassUnload/KeepAliveClassLoader.java | 13 +++++-------- .../jtreg/runtime/ClassUnload/KeepAliveObject.java | 13 +++++-------- .../ClassUnload/KeepAliveSoftReference.java | 6 +++--- .../runtime/ClassUnload/SuperDependsTest.java | 10 +++++----- .../runtime/ClassUnload/UnloadInterfaceTest.java | 11 ++++++++--- .../jtreg/runtime/ClassUnload/UnloadTest.java | 8 +++++--- .../customLoader/test-classes/HelloUnload.java | 8 +++++--- .../test-classes/UnloadUnregisteredLoader.java | 8 +++++--- .../jtreg/runtime/logging/ClassLoadUnloadTest.java | 4 ++-- 11 files changed, 55 insertions(+), 52 deletions(-) diff --git a/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java b/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java index ed47053cd16..11064feb0f8 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,8 @@ import jdk.test.whitebox.WhiteBox; import java.lang.reflect.Method; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; public class DictionaryDependsTest { public static WhiteBox wb = WhiteBox.getWhiteBox(); @@ -82,9 +84,9 @@ public class DictionaryDependsTest { public static void main(String args[]) throws Throwable { DictionaryDependsTest d = new DictionaryDependsTest(); d.test(); - ClassUnloadCommon.triggerUnloading(); // should not unload anything - System.out.println("Should unload MyTest and p2.c2 just now"); - ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); - ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); + + // Now unload MY_TEST and p2.c2 + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(MY_TEST, "p2.c2")); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should be unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java index 741953f5189..a913e45881d 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,8 @@ import java.lang.ref.SoftReference; import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. @@ -60,7 +62,6 @@ public class KeepAliveClass { } ClassUnloadCommon.triggerUnloading(); - { boolean isAlive = wb.isClassAlive(className); System.out.println("testClass (2) alive: " + isAlive); @@ -69,13 +70,8 @@ public class KeepAliveClass { } c = null; escape = null; - ClassUnloadCommon.triggerUnloading(); - - { - boolean isAlive = wb.isClassAlive(className); - System.out.println("testClass (3) alive: " + isAlive); - ClassUnloadCommon.failIf(isAlive, "should be unloaded"); - } + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testClass (3) should be unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java index aab5b613ab7..7eb66ae58b0 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,8 @@ import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. @@ -68,13 +70,8 @@ public class KeepAliveClassLoader { } cl = null; escape = null; - ClassUnloadCommon.triggerUnloading(); - - { - boolean isAlive = wb.isClassAlive(className); - System.out.println("testClassLoader (3) alive: " + isAlive); - ClassUnloadCommon.failIf(isAlive, "should be unloaded"); - } + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testClassLoader (3) should be unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java index 81bdbd60c56..a1c2c172751 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,8 @@ import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; import java.lang.ref.Reference; /** @@ -68,13 +70,8 @@ public class KeepAliveObject { // Don't let `o` get prematurely reclaimed by the GC. Reference.reachabilityFence(o); o = null; - ClassUnloadCommon.triggerUnloading(); - - { - boolean isAlive = wb.isClassAlive(className); - System.out.println("testObject (3) alive: " + isAlive); - ClassUnloadCommon.failIf(isAlive, "should be unloaded"); - } + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testObject (3) should be unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java index 2e704972a16..5fad42d6605 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ import java.lang.ref.SoftReference; import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; /** * Test that verifies that classes are not unloaded when specific types of references are kept to them. @@ -69,8 +70,7 @@ public class KeepAliveSoftReference { ClassUnloadCommon.failIf(isAlive != shouldBeAlive, "" + isAlive + " != " + shouldBeAlive); } sr.clear(); - ClassUnloadCommon.triggerUnloading(); - + ClassUnloadCommon.triggerUnloading(List.of(className)); { boolean isAlive = wb.isClassAlive(className); System.out.println("testSoftReference (3) alive: " + isAlive); diff --git a/test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java b/test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java index 3b771b000e5..4ed7e5eeb98 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,6 +38,8 @@ import jdk.test.whitebox.WhiteBox; import p2.*; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; public class SuperDependsTest { public static WhiteBox wb = WhiteBox.getWhiteBox(); @@ -75,9 +77,7 @@ public class SuperDependsTest { public static void main(String args[]) throws Throwable { SuperDependsTest d = new SuperDependsTest(); d.test(); - ClassUnloadCommon.triggerUnloading(); // should not unload anything - System.out.println("Should unload MyTest and p2.c2 just now"); - ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); - ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(MY_TEST, "p2.c2")); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should be unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java b/test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java index b37cd67d400..d85ab4500e5 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,8 @@ import jdk.test.whitebox.WhiteBox; import test.Interface; import java.lang.ClassLoader; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; /** * Test that verifies that class unloaded removes the implementor from its the interface that it implements @@ -86,8 +88,11 @@ public class UnloadInterfaceTest { ClassUnloadCommon.failIf(!wb.isClassAlive(interfaceName), "should be live here"); cl = null; c = null; o = null; - ClassUnloadCommon.triggerUnloading(); - ClassUnloadCommon.failIf(wb.isClassAlive(className), "should have been unloaded"); + + // Now unload className. This calls triggerUnloading but we only pass the class we expect to be unloaded + // otherwise the test will take too long. + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should be unloaded: " + aliveClasses); ClassUnloadCommon.failIf(!wb.isClassAlive(interfaceName), "should be live here"); System.out.println("We still have Interface referenced" + ic); } diff --git a/test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java b/test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java index f2d7dd1dc33..3a4d8918a75 100644 --- a/test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java +++ b/test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,8 @@ import jdk.test.lib.classloader.ClassUnloadCommon; import java.lang.reflect.Array; import java.lang.ref.Reference; +import java.util.List; +import java.util.Set; /** * Test that verifies that liveness of classes is correctly tracked. @@ -108,9 +110,9 @@ public class UnloadTest { // Don't let `o` get prematurely reclaimed by the GC. Reference.reachabilityFence(o); o = null; - ClassUnloadCommon.triggerUnloading(); - ClassUnloadCommon.failIf(wb.isClassAlive(className), "should have been unloaded"); + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should have been unloaded: " + aliveClasses); int unloadedRefcount = wb.getSymbolRefcount(loaderName); System.out.println("Refcount of symbol " + loaderName + " is " + unloadedRefcount); diff --git a/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java index 95c14b7dbe2..4450498b360 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,8 @@ import java.net.URL; import java.net.URLClassLoader; import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; public class HelloUnload { private static String className = "CustomLoadee"; @@ -100,9 +102,9 @@ public class HelloUnload { if (doUnload) { urlClassLoader = null; c = null; o = null; - ClassUnloadCommon.triggerUnloading(); + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); System.out.println("Is CustomLoadee alive? " + wb.isClassAlive(className)); - ClassUnloadCommon.failIf(wb.isClassAlive(className), "should have been unloaded"); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should have been unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java index 4ad775f62d6..0e0e814327e 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,8 @@ import java.net.URL; import java.net.URLClassLoader; import jdk.test.whitebox.WhiteBox; import jdk.test.lib.classloader.ClassUnloadCommon; +import java.util.List; +import java.util.Set; public class UnloadUnregisteredLoader { public static void main(String args[]) throws Exception { @@ -39,8 +41,8 @@ public class UnloadUnregisteredLoader { for (int i=0; i<5; i++) { doit(urls, className, (i == 0)); - ClassUnloadCommon.triggerUnloading(); - ClassUnloadCommon.failIf(wb.isClassAlive(className), "should have been unloaded"); + Set aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className)); + ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should have been unloaded: " + aliveClasses); } } diff --git a/test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java b/test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java index 7fd4726d9c6..d5ba7eb15f4 100644 --- a/test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java +++ b/test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -52,7 +52,7 @@ public class ClassLoadUnloadTest { ClassLoader cl = ClassUnloadCommon.newClassLoader(); Class c = cl.loadClass(className); cl = null; c = null; - ClassUnloadCommon.triggerUnloading(); + ClassUnloadCommon.triggerUnloading(List.of(className)); } }