Skip to content

Commit 2a2bc2c

Browse files
committed
8346929: runtime/ClassUnload/DictionaryDependsTest.java fails with "Test failed: should be unloaded"
Backport-of: 6e43f48fcf342266b3d50688af7ae4664c018ac8
1 parent 121903b commit 2a2bc2c

File tree

11 files changed

+55
-52
lines changed

11 files changed

+55
-52
lines changed

test/hotspot/jtreg/runtime/ClassUnload/DictionaryDependsTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -37,6 +37,8 @@
3737
import jdk.test.whitebox.WhiteBox;
3838
import java.lang.reflect.Method;
3939
import jdk.test.lib.classloader.ClassUnloadCommon;
40+
import java.util.List;
41+
import java.util.Set;
4042

4143
public 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
}

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -36,6 +36,8 @@
3636
import java.lang.ref.SoftReference;
3737
import jdk.test.whitebox.WhiteBox;
3838
import 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
}

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -35,6 +35,8 @@
3535

3636
import jdk.test.whitebox.WhiteBox;
3737
import 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
}

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -35,6 +35,8 @@
3535

3636
import jdk.test.whitebox.WhiteBox;
3737
import jdk.test.lib.classloader.ClassUnloadCommon;
38+
import java.util.List;
39+
import java.util.Set;
3840

3941
import 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
}

test/hotspot/jtreg/runtime/ClassUnload/KeepAliveSoftReference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -36,6 +36,7 @@
3636
import java.lang.ref.SoftReference;
3737
import jdk.test.whitebox.WhiteBox;
3838
import 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);

test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -38,6 +38,8 @@
3838
import jdk.test.whitebox.WhiteBox;
3939
import p2.*;
4040
import jdk.test.lib.classloader.ClassUnloadCommon;
41+
import java.util.List;
42+
import java.util.Set;
4143

4244
public 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
}

test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -36,6 +36,8 @@
3636
import test.Interface;
3737
import java.lang.ClassLoader;
3838
import 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
}

test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -37,6 +37,8 @@
3737

3838
import java.lang.reflect.Array;
3939
import 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);

test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/HelloUnload.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -27,6 +27,8 @@
2727
import java.net.URLClassLoader;
2828
import jdk.test.whitebox.WhiteBox;
2929
import jdk.test.lib.classloader.ClassUnloadCommon;
30+
import java.util.List;
31+
import java.util.Set;
3032

3133
public 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
}

test/hotspot/jtreg/runtime/cds/appcds/customLoader/test-classes/UnloadUnregisteredLoader.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -27,6 +27,8 @@
2727
import java.net.URLClassLoader;
2828
import jdk.test.whitebox.WhiteBox;
2929
import jdk.test.lib.classloader.ClassUnloadCommon;
30+
import java.util.List;
31+
import java.util.Set;
3032

3133
public 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

0 commit comments

Comments
 (0)