On Mon, 22 Dec 2025 19:01:54 GMT, Chris Plummer <[email protected]> wrote:

>> Another solution is make some sleep after call `unloadClass()`
>> 
>> 
>> diff --git 
>> a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java
>>  
>> b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java
>> index 13058ec7864..15120d3cad6 100644
>> --- 
>> a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java
>> +++ 
>> b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001.java
>> @@ -47,7 +47,7 @@ public class compmethunload001 {
>>      private final static String CLS_TO_BE_UNLOADED =
>>          "nsk.jvmti.CompiledMethodUnload.compmethunload001u";
>>  
>> -    private final static int MAX_ITERATIONS = 50;
>> +    private final static int MAX_ITERATIONS = 5;
>>  
>>      static {
>>          try {
>> @@ -95,6 +95,7 @@ public static void callHotClass(String location) throws 
>> Exception {
>>  
>>          boolean clsUnloaded = clsUnLoader.unloadClass();
>>          clsUnLoader = null;
>> +        Thread.sleep(5000);
>>          System.gc();
>>      }
>
> It seems this is somewhat poorly written test and is also somewhat imprecise 
> and presumpive. I'm guessing the unload is delayed a bit because it happens 
> async, and you can't really guess how long it is going to take for the unload 
> to happen. The loop and the System.gc() calls are just passing time until the 
> unload happens. The System.gc() calls should not be needed since the 
> ClassUnloader.unloadClass() call should have been sufficient. I would suggest 
> removing both System.gc() calls and just have a loop that does short sleeps 
> until the unload happens. Maybe limit the loop to no more than 10 seconds. A 
> more elegant approach would be to wait on a monitor for no more than 10 
> seconds, and have the native code notify the monitor when the unload happens.

The code "wait on a monitor and notify from JNI" seems too complex for me. So I 
just limit the loop to no more than 10 seconds.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28891#discussion_r2641853242

Reply via email to