File tree Expand file tree Collapse file tree 11 files changed +55
-52
lines changed
test/hotspot/jtreg/runtime
cds/appcds/customLoader/test-classes Expand file tree Collapse file tree 11 files changed +55
-52
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2018, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3737import jdk .test .whitebox .WhiteBox ;
3838import java .lang .reflect .Method ;
3939import jdk .test .lib .classloader .ClassUnloadCommon ;
40+ import java .util .List ;
41+ import java .util .Set ;
4042
4143public class DictionaryDependsTest {
4244 public static WhiteBox wb = WhiteBox .getWhiteBox ();
@@ -82,9 +84,9 @@ public void test() throws Throwable {
8284 public static void main (String args []) throws Throwable {
8385 DictionaryDependsTest d = new DictionaryDependsTest ();
8486 d .test ();
85- ClassUnloadCommon . triggerUnloading (); // should not unload anything
86- System . out . println ( "Should unload MyTest and p2.c2 just now" );
87- ClassUnloadCommon .failIf ( wb . isClassAlive (MY_TEST ) , "should be unloaded" );
88- ClassUnloadCommon .failIf (wb . isClassAlive ( "p2.c2" ), "should be unloaded" );
87+
88+ // Now unload MY_TEST and p2.c2
89+ Set < String > aliveClasses = ClassUnloadCommon .triggerUnloading ( List . of (MY_TEST , "p2.c2" ) );
90+ ClassUnloadCommon .failIf (! aliveClasses . isEmpty ( ), "should be unloaded: " + aliveClasses );
8991 }
9092}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3636import java .lang .ref .SoftReference ;
3737import jdk .test .whitebox .WhiteBox ;
3838import jdk .test .lib .classloader .ClassUnloadCommon ;
39+ import java .util .List ;
40+ import java .util .Set ;
3941
4042/**
4143 * 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 {
6062 }
6163
6264 ClassUnloadCommon .triggerUnloading ();
63-
6465 {
6566 boolean isAlive = wb .isClassAlive (className );
6667 System .out .println ("testClass (2) alive: " + isAlive );
@@ -69,13 +70,8 @@ public static void main(String... args) throws Exception {
6970 }
7071 c = null ;
7172 escape = null ;
72- ClassUnloadCommon .triggerUnloading ();
73-
74- {
75- boolean isAlive = wb .isClassAlive (className );
76- System .out .println ("testClass (3) alive: " + isAlive );
77- ClassUnloadCommon .failIf (isAlive , "should be unloaded" );
78- }
7973
74+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (className ));
75+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "testClass (3) should be unloaded: " + aliveClasses );
8076 }
8177}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3535
3636import jdk .test .whitebox .WhiteBox ;
3737import jdk .test .lib .classloader .ClassUnloadCommon ;
38+ import java .util .List ;
39+ import java .util .Set ;
3840
3941/**
4042 * 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 {
6870 }
6971 cl = null ;
7072 escape = null ;
71- ClassUnloadCommon .triggerUnloading ();
72-
73- {
74- boolean isAlive = wb .isClassAlive (className );
75- System .out .println ("testClassLoader (3) alive: " + isAlive );
76- ClassUnloadCommon .failIf (isAlive , "should be unloaded" );
77- }
7873
74+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (className ));
75+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "testClassLoader (3) should be unloaded: " + aliveClasses );
7976 }
8077}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3535
3636import jdk .test .whitebox .WhiteBox ;
3737import jdk .test .lib .classloader .ClassUnloadCommon ;
38+ import java .util .List ;
39+ import java .util .Set ;
3840
3941import java .lang .ref .Reference ;
4042/**
@@ -68,13 +70,8 @@ public static void main(String... args) throws Exception {
6870 // Don't let `o` get prematurely reclaimed by the GC.
6971 Reference .reachabilityFence (o );
7072 o = null ;
71- ClassUnloadCommon .triggerUnloading ();
72-
73- {
74- boolean isAlive = wb .isClassAlive (className );
75- System .out .println ("testObject (3) alive: " + isAlive );
76- ClassUnloadCommon .failIf (isAlive , "should be unloaded" );
77- }
7873
74+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (className ));
75+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "testObject (3) should be unloaded: " + aliveClasses );
7976 }
8077}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3636import java .lang .ref .SoftReference ;
3737import jdk .test .whitebox .WhiteBox ;
3838import jdk .test .lib .classloader .ClassUnloadCommon ;
39+ import java .util .List ;
3940
4041/**
4142 * 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 {
6970 ClassUnloadCommon .failIf (isAlive != shouldBeAlive , "" + isAlive + " != " + shouldBeAlive );
7071 }
7172 sr .clear ();
72- ClassUnloadCommon .triggerUnloading ();
73-
73+ ClassUnloadCommon .triggerUnloading (List .of (className ));
7474 {
7575 boolean isAlive = wb .isClassAlive (className );
7676 System .out .println ("testSoftReference (3) alive: " + isAlive );
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2018, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3838import jdk .test .whitebox .WhiteBox ;
3939import p2 .*;
4040import jdk .test .lib .classloader .ClassUnloadCommon ;
41+ import java .util .List ;
42+ import java .util .Set ;
4143
4244public class SuperDependsTest {
4345 public static WhiteBox wb = WhiteBox .getWhiteBox ();
@@ -75,9 +77,7 @@ public void test() throws Throwable {
7577 public static void main (String args []) throws Throwable {
7678 SuperDependsTest d = new SuperDependsTest ();
7779 d .test ();
78- ClassUnloadCommon .triggerUnloading (); // should not unload anything
79- System .out .println ("Should unload MyTest and p2.c2 just now" );
80- ClassUnloadCommon .failIf (wb .isClassAlive (MY_TEST ), "should be unloaded" );
81- ClassUnloadCommon .failIf (wb .isClassAlive ("p2.c2" ), "should be unloaded" );
80+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (MY_TEST , "p2.c2" ));
81+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "should be unloaded: " + aliveClasses );
8282 }
8383}
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2018, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3636import test .Interface ;
3737import java .lang .ClassLoader ;
3838import jdk .test .lib .classloader .ClassUnloadCommon ;
39+ import java .util .List ;
40+ import java .util .Set ;
3941
4042/**
4143 * 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 {
8688 ClassUnloadCommon .failIf (!wb .isClassAlive (interfaceName ), "should be live here" );
8789
8890 cl = null ; c = null ; o = null ;
89- ClassUnloadCommon .triggerUnloading ();
90- ClassUnloadCommon .failIf (wb .isClassAlive (className ), "should have been unloaded" );
91+
92+ // Now unload className. This calls triggerUnloading but we only pass the class we expect to be unloaded
93+ // otherwise the test will take too long.
94+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (className ));
95+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "should be unloaded: " + aliveClasses );
9196 ClassUnloadCommon .failIf (!wb .isClassAlive (interfaceName ), "should be live here" );
9297 System .out .println ("We still have Interface referenced" + ic );
9398 }
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3737
3838import java .lang .reflect .Array ;
3939import java .lang .ref .Reference ;
40+ import java .util .List ;
41+ import java .util .Set ;
4042
4143/**
4244 * Test that verifies that liveness of classes is correctly tracked.
@@ -108,9 +110,9 @@ private static void test_unload_obj_array_klass() throws Exception {
108110 // Don't let `o` get prematurely reclaimed by the GC.
109111 Reference .reachabilityFence (o );
110112 o = null ;
111- ClassUnloadCommon .triggerUnloading ();
112113
113- ClassUnloadCommon .failIf (wb .isClassAlive (className ), "should have been unloaded" );
114+ Set <String > aliveClasses = ClassUnloadCommon .triggerUnloading (List .of (className ));
115+ ClassUnloadCommon .failIf (!aliveClasses .isEmpty (), "should have been unloaded: " + aliveClasses );
114116
115117 int unloadedRefcount = wb .getSymbolRefcount (loaderName );
116118 System .out .println ("Refcount of symbol " + loaderName + " is " + unloadedRefcount );
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2019, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2727import java .net .URLClassLoader ;
2828import jdk .test .whitebox .WhiteBox ;
2929import jdk .test .lib .classloader .ClassUnloadCommon ;
30+ import java .util .List ;
31+ import java .util .Set ;
3032
3133public class HelloUnload {
3234 private static String className = "CustomLoadee" ;
@@ -87,9 +89,9 @@ public static void main(String args[]) throws Exception {
8789
8890 if (doUnload ) {
8991 urlClassLoader = null ; c = null ; o = null ;
90- ClassUnloadCommon .triggerUnloading ();
92+ Set < String > aliveClasses = ClassUnloadCommon .triggerUnloading (List . of ( className ) );
9193 System .out .println ("Is CustomLoadee alive? " + wb .isClassAlive (className ));
92- ClassUnloadCommon .failIf (wb . isClassAlive ( className ), "should have been unloaded" );
94+ ClassUnloadCommon .failIf (! aliveClasses . isEmpty ( ), "should have been unloaded: " + aliveClasses );
9395
9496 }
9597 }
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2015, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2727import java .net .URLClassLoader ;
2828import jdk .test .whitebox .WhiteBox ;
2929import jdk .test .lib .classloader .ClassUnloadCommon ;
30+ import java .util .List ;
31+ import java .util .Set ;
3032
3133public class UnloadUnregisteredLoader {
3234 public static void main (String args []) throws Exception {
@@ -39,8 +41,8 @@ public static void main(String args[]) throws Exception {
3941 for (int i =0 ; i <5 ; i ++) {
4042 doit (urls , className , (i == 0 ));
4143
42- ClassUnloadCommon .triggerUnloading ();
43- ClassUnloadCommon .failIf (wb . isClassAlive ( className ), "should have been unloaded" );
44+ Set < String > aliveClasses = ClassUnloadCommon .triggerUnloading (List . of ( className ) );
45+ ClassUnloadCommon .failIf (! aliveClasses . isEmpty ( ), "should have been unloaded: " + aliveClasses );
4446 }
4547 }
4648
You can’t perform that action at this time.
0 commit comments