> 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

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/33678/files
  - new: https://git.openjdk.org/jdk/pull/33678/files/9e122afd..3e74293b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=33678&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=33678&range=00-01

  Stats: 7 lines in 1 file changed: 0 ins; 6 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/33678.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/33678/head:pull/33678

PR: https://git.openjdk.org/jdk/pull/33678

Reply via email to