diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003.java b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003.java index d4cb4a8569a..a23732dc554 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t003.java @@ -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; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java b/test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java index 94b086f5757..5c7d2b8d640 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java @@ -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; } }