On Mon, 30 Nov 2026 02:38:15 GMT, Andrei Pangin <[email protected]> wrote:

>> A change in JDK-8364258 broke CPU-time sampling for threads that call JNI 
>> `AttachCurrentThread` or `AttachCurrentThreadAsDaemon` while profiler is 
>> active. This PR restores the correct behavior, allowing JNI-attached threads 
>> to be sampled, whether they attach before or after enabling profiler.
>> 
>> When a native thread is attached to the JVM, it goes directly to 
>> `_thread_in_vm` state, but `JfrThreadLocal::on_start` enables CPU-time 
>> sampling only for `_thread_new` threads. The fix is to add an explicit check 
>> for `is_attaching_via_jni()`.
>> 
>> Testing: all `jdk_jfr` tests, including new `TestCPUTimeSamplingJNIAttach`.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Andrei Pangin has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Simplified fix

src/hotspot/share/jfr/support/jfrThreadLocal.cpp line 147:

> 145:     }
> 146:     JavaThread* const jt = JavaThread::cast(t);
> 147:     if (jt->thread_state() == _thread_in_vm) {

PR description talks about `is_attaching_via_jni()` to check for the thread 
feasibility, yet we have plain comparison here.
Could you please update the PR description such that it corresponds to the real 
change?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33678#discussion_r4766915798

Reply via email to