RFR: 8231269: CompileTask::is_unloaded is slow due to JNIHandles type checks [v10]

Coleen Phillimore coleenp at openjdk.org
Tue Apr 29 19:39:52 UTC 2025


On Tue, 29 Apr 2025 09:22:10 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> [JDK-8163511](https://bugs.openjdk.org/browse/JDK-8163511) made the `CompileTask` improvement to avoid blocking class unloading if a relevant compile task is in queue. Current code does a sleight-of-hand to make sure the the `method*` in `CompileTask` are still valid before using them. Still a noble goal, so we keep trying to do this.
>> 
>> The code tries to switch weak JNI handle with a strong one when it wants to capture the holder to block unloading. Since we are reusing the same field, we have to do type checks like `JNIHandles::is_weak_global_handle(_method_holder)`. Unfortunately, that type-check goes all the way to `OopStorage` allocation code to verify the handle is really allocated in the relevant `OopStorage`. This takes internal `OopStorage` locks, and thus is slow.
>> 
>> This issue is clearly visible in Leyden, when there are lots of `CompileTask`-s in the queue, dumped by AOT code loader. It also does not help that `CompileTask::select_task` is effectively quadratic in number of methods in queue, so we end up calling `CompileTask::is_unloaded` very often.
>> 
>> It is possible to mitigate this issue by splitting the related fields into weak and strong ones. But as Kim mentions in the bug, we should not be using JNI handles here at all, and instead go directly for relevant `OopStorage`-s. This is what this PR does, among other things that should hopefully make the whole mechanics clearer.
>> 
>> Additional testing:
>>  - [x] Linux x86_64 server fastdebug, `compiler/classUnloading`, 100x still passes; these tests are sensitive to bugs in this code
>>  - [x] Linux x86_64 server fastdebug, `all`
>>  - [x] Linux AArch64 server fastdebug, `all`
>
> Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improve get_method_blocker

src/hotspot/share/runtime/unloadableMethodHandle.hpp line 26:

> 24: 
> 25: #ifndef SHARE_RUNTIME_UNLOADABLE_METHOD_HANDLE_HPP
> 26: #define SHARE_RUNTIME_UNLOADABLE_METHOD_HANDLE_HPP

I think this should be in the oops directory like OopHandle and WeakHandle and Method*, the thing it contains.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24018#discussion_r2067225946


More information about the hotspot-compiler-dev mailing list