RFR: 8377950: Refactor ClassUnloader to provide explicit waiting API

SendaoYan syan at openjdk.org
Tue Feb 17 03:07:24 UTC 2026


On Mon, 16 Feb 2026 07:45:11 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

> Separates GC triggering from class reclamation waiting in vmTestbase ClassUnloader.
> 
> The original implementation used an implicit wait loop regardless of caller needs. Because the necessity of waiting is caller-specific, this PR introduces an explicit `unloadClassAndWait(timeout)` API. This allows callers to document their specific reasons for waiting (e.g., race conditions with JDWP or background compilation) while keeping `unloadClass()` simple for those who don't need to wait.
> 
> - Introduced `unloadClassAndWait(timeout)` and simplified `unloadClass()`.
> - Updated `compmethunload001` and `AbstractDebuggeeTest` to use the explicit waiting API with documented rationale.
> 
> Test: tier1-5, `vmTestbase/nsk`

All the tests touched by [JDK-8375485](https://bugs.openjdk.org/secure/attachment/118245/tests-8375485.txt) run passed after this proposed patch.

test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java line 90:

> 88: 
> 89:         // Call hot methods that get compiled
> 90:         c.getMethod("entryMethod").invoke(hotCls);

The "import java.math.*;" and "import java.util.*;" seems useless. Maybe we can remove them by the way.

test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java line 93:

> 91:         c.getMethod("entryNewMethod").invoke(hotCls);
> 92:         // provoke unloading of previously compiled methods
> 93:         hotCls = null;

Should we need update the copyright year to 2026.

test/hotspot/jtreg/vmTestbase/nsk/share/jpda/AbstractDebuggeeTest.java line 166:

> 164:                 wasUnloaded = classUnloader.unloadClassAndWait(10_000);
> 165:             } else {
> 166:                 wasUnloaded = classUnloader.unloadClass();;

Extra semicolon

-------------

PR Comment: https://git.openjdk.org/jdk/pull/29735#issuecomment-3911600536
PR Review Comment: https://git.openjdk.org/jdk/pull/29735#discussion_r2814619118
PR Review Comment: https://git.openjdk.org/jdk/pull/29735#discussion_r2814616827
PR Review Comment: https://git.openjdk.org/jdk/pull/29735#discussion_r2814624481


More information about the serviceability-dev mailing list