> Implements the native profiler hook for unbiased stack-traces, as described 
> in [JEP draft: Native Profiler Hook for Unbiased Stack Traces 
> (Experimental)](https://openjdk.org/jeps/8380294).
> 
> New JVMTI extension function: `RequestStackTrace(jvmtiEnv*, jthread*, void* 
> ucontext, jlong user_data)` - async-signal-safe request for a stack trace. 
> For the current thread, `ucontext` may be `nullptr` or the signal-handler 
> `ucontext`. For another thread, the thread must be suspended for the duration 
> of the call and `ucontext` must be captured during that suspension; otherwise 
> the VM may crash. Returns `JVMTI_ERROR_NONE`, `JVMTI_ERROR_INVALID_THREAD`, 
> or `JVMTI_ERROR_NOT_AVAILABLE`. Requests may be silently dropped (queue full, 
> wrong thread state, rate-limited).
> 
> New experimental JFR event `StackTraceRequest` with fields `stackTrace`, 
> `eventThread`, `userData`, `failed`, `biased`. Enabled in `profile.jfc`, not 
> in `default.jfc` (the rate is controlled by the external agent, so default-on 
> would expose users to unbounded overhead).
> 
> The machinery gets enabled/disabled whenever the event `StackTraceRequest` 
> gets enabled/disabled.
> 
> Refactoring: The stack-walker request machinery from JEP 509 (CPU-time 
> profiler) is generalized into a callback-based API (`JfrStackWalkerCallback`) 
> used by both the CPU-time profiler and the new JVMTI hook. Shared pieces: the 
> per-thread signal-safe request queue, the enqueue/dequeue lock state machine, 
> and the native stack-walker thread that processes requests for in-native 
> threads. Two callback implementations remain: one for 
> CPUTimeSample/empty/lost events, one for StackTraceRequest.
> 
> Non-goals (per the JEP): Native frames are not reported; this is a follow-up.
> 
> Platform support: Linux and MacOS, or more generally POSIX. Windows support 
> can be a follow-up, if ucontext is interpreted as WPA context.
> 
> Testing:
> 
> Several tests have been added that verify the new functionality.
> 
>  - [x] jdk_jfr
>  - [x] serviceability/jvmti
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Roman Kennke has updated the pull request incrementally with three additional 
commits since the last revision:

 - Fold JfrStackWalker hooks into Jfr facade, drop unused walker API, and 
minimize changes to existing JFR code
 - Bail out of compute_top_frame when no frame is found above the sampled sp
 - Reuse JFR sample-request building and top-frame computation in 
JfrStackWalker, also picks up NEEDS_STACK_REPAIR handling, which the copy lacked

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/31059/files
  - new: https://git.openjdk.org/jdk/pull/31059/files/84a9ea59..eafaa210

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=31059&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=31059&range=03-04

  Stats: 994 lines in 24 files changed: 203 ins; 730 del; 61 mod
  Patch: https://git.openjdk.org/jdk/pull/31059.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31059/head:pull/31059

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

Reply via email to