8375485: Tests in vmTestbase/nsk are failing due to missing class unloading after 8373945

Reviewed-by: lmesnik, cjplummer
This commit is contained in:
SendaoYan 2026-01-21 03:39:02 +00:00
parent a2e749572e
commit 599ed0bb5f
2 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2026, 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
@ -105,6 +105,21 @@ public class em02t003 extends DebugeeClass {
return Consts.TEST_FAILED;
}
while (thrd.isAlive()) {
logger.display("Thread state: " + thrd.getState()
+ " - waiting for completion.");
try {
// small delay to avoid produce huge amount of output
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
try {
// give some time wait thread to exit completely
Thread.sleep(2000);
} catch (InterruptedException e) {
}
logger.display("MethodCompiling:: Provoke unloading compiled method - "
+ "\n\ttrying to unload class...");
thrd = null;

View File

@ -239,6 +239,9 @@ public class ClassUnloader {
*
* @see WhiteBox.getWhiteBox().fullGC()
*/
public static final int MAX_UNLOAD_ATTEMPS = 10;
public boolean unloadClass() {
// free references to class and class loader to be able for collecting by GC
@ -247,14 +250,26 @@ public class ClassUnloader {
// force class unloading by triggering full GC
WhiteBox.getWhiteBox().fullGC();
int count = 0;
while (count++ < MAX_UNLOAD_ATTEMPS && !isClassLoaderReclaimed()) {
System.out.println("ClassUnloader: waiting for class loader reclaiming... " + count);
WhiteBox.getWhiteBox().fullGC();
try {
// small delay to give more changes to process objects
// inside VM like jvmti deferred queue
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
// force GC to unload marked class loader and its classes
if (isClassLoaderReclaimed()) {
Runtime.getRuntime().gc();
System.out.println("ClassUnloader: class loader has been reclaimed.");
return true;
}
// class loader has not been reclaimed
System.out.println("ClassUnloader: class loader is still reachable.");
return false;
}
}