Skip to content

8346929: runtime/ClassUnload/DictionaryDependsTest.java fails with "Test failed: should be unloaded" #2094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(MY_TEST, "p2.c2"));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should be unloaded: " + aliveClasses);
}
}
14 changes: 5 additions & 9 deletions test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClass.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testClass (3) should be unloaded: " + aliveClasses);
}
}
13 changes: 5 additions & 8 deletions test/hotspot/jtreg/runtime/ClassUnload/KeepAliveClassLoader.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testClassLoader (3) should be unloaded: " + aliveClasses);
}
}
13 changes: 5 additions & 8 deletions test/hotspot/jtreg/runtime/ClassUnload/KeepAliveObject.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "testObject (3) should be unloaded: " + aliveClasses);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions test/hotspot/jtreg/runtime/ClassUnload/SuperDependsTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(MY_TEST, "p2.c2"));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should be unloaded: " + aliveClasses);
}
}
11 changes: 8 additions & 3 deletions test/hotspot/jtreg/runtime/ClassUnload/UnloadInterfaceTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String> 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);
}
Expand Down
8 changes: 5 additions & 3 deletions test/hotspot/jtreg/runtime/ClassUnload/UnloadTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -100,9 +102,9 @@ public static void main(String args[]) throws Exception {

if (doUnload) {
urlClassLoader = null; c = null; o = null;
ClassUnloadCommon.triggerUnloading();
Set<String> 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);

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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<String> aliveClasses = ClassUnloadCommon.triggerUnloading(List.of(className));
ClassUnloadCommon.failIf(!aliveClasses.isEmpty(), "should have been unloaded: " + aliveClasses);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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));
}
}

Expand Down