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 void test() throws Throwable { 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 static void main(String... args) throws Exception { } ClassUnloadCommon.triggerUnloading(); - { boolean isAlive = wb.isClassAlive(className); System.out.println("testClass (2) alive: " + isAlive); @@ -69,13 +70,8 @@ public static void main(String... args) throws Exception { } 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 static void main(String... args) throws Exception { } 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 static void main(String... args) throws Exception { // 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 static void main(String... args) throws Exception { 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 void test() throws Throwable { 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 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 @@ private static void run() throws Exception { 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 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 @@ private static void test_unload_obj_array_klass() throws Exception { // 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.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 static void main(String args[]) throws Exception { 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.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 static void main(String args[]) throws Exception { 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 ea17cad78dd..e495929823e 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 static void main(String... args) throws Exception { ClassLoader cl = ClassUnloadCommon.newClassLoader(); Class c = cl.loadClass(className); cl = null; c = null; - ClassUnloadCommon.triggerUnloading(); + ClassUnloadCommon.triggerUnloading(List.of(className)); } }