JVMTI stack and monitor queries on a platform or carrier thread can miss
frames. The issue describes three cases. This PR fixes all three in
`JvmtiEnvBase`.
### Changes
**Frames left in a stack chunk (cases 1 and 3).** `get_stack_trace`,
`get_frame_count`, `count_locked_objects` and `get_owned_monitors` now walk
with `RegisterMap::WalkContinuation::include`.
- `get_frame_location`, `VM_GetOrSetLocal`, `SetOrClearFramePopClosure` and
`JvmtiThreadState::count_frames` already walk this way.
- So every depth-indexed JVMTI function now sees the same frames for a platform
thread.
- The `skip` in these four walks dates back to the implicit `walk_cont = false`
default of the `RegisterMap` constructor. JDK-8290074 made it explicit.
**Carrier thread in a mount or unmount transition (case 2).**
`is_cthread_with_continuation()` now also returns true when the carrier is in a
transition and has a virtual thread continuation on its stack.
- `get_cthread_last_java_vframe()` then starts at the carrier's frames, so
`check_and_skip_hidden_frames()` stops at `VirtualThread.runContinuation`,
`mount` or `unmount`. The walk no longer runs into the virtual thread's
continuation entry and returns an empty trace.
- The carrier then reports the same frames as when its JVMTI identity is the
virtual thread.
### Behavior changes
For a carrier in a transition window, the other users of
`is_cthread_with_continuation()` and `get_cthread_last_java_vframe()` now also
treat the virtual thread's frames as hidden:
- `GetOwnedMonitorInfo` and `GetOwnedMonitorStackDepthInfo` no longer report
the virtual thread's monitors as the carrier's.
- `GetCurrentContendedMonitor` reports none for the carrier.
- `GetLocal*`/`SetLocal*` and `NotifyFramePop` depths count from the carrier's
frames.
These are the results the carrier already gets outside the window.
### Testing
New tests:
- **`serviceability/jvmti/thread/GetStackTrace/GetStackTraceStackChunkTest`:**
a `Continuation` holds a monitor 100 frames deep and yields from 200 frames
deep. The worker thread holds a second monitor around `Continuation.run()`.
- After a lazy resume, the test checks from the thread itself and from a
suspended second thread.
- `GetStackTrace` must give the same frames as before the yield.
- `GetFrameCount` and `GetFrameLocation` at every depth must agree with it.
- `GetOwnedMonitorStackDepthInfo` must report each monitor at the depth of
its frame.
- `GetOwnedMonitorInfo` must list both monitors, and `GetObjectMonitorUsage`
must report `entry_count` 1 for each.
- **`serviceability/jvmti/vthread/GetAllStackTracesCarrierTest`:** calls
`GetAllStackTraces` while 64 virtual threads keep yielding. It fails on any
live carrier trace that is empty or does not end in `run()`.
- It samples up to 200,000 carrier traces or 20 s.
- A transition cannot be caught deterministically, so this is a stress test.
Results on linux-x64 fastdebug:
| Build | Test | Result |
| --- | --- | --- |
| without the fix | `GetStackTraceStackChunkTest` | fails |
| without the fix | `GetAllStackTracesCarrierTest` | fails within the first 32
carrier traces |
| fix without the two monitor-walk changes | `GetStackTraceStackChunkTest` |
fails: inner monitor not reported |
| with the fix | `GetStackTraceStackChunkTest` | passes with default flags,
`-Xint`, `-Xcomp`, `-XX:TieredStopAtLevel=1`, `-XX:+UseZGC` and
`-XX:+UseShenandoahGC` |
| with the fix | `GetAllStackTracesCarrierTest` | passes: 173,088 carrier
traces, none missing frames |
| with the fix | `serviceability/jvmti`,
`vmTestbase/nsk/jvmti/{unit,PopFrame,NotifyFramePop}`, `jdk/com/sun/jdi`,
`vmTestbase/nsk/jdi/ThreadReference` | 585 passed, 0 failed, 11 skipped |
---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK
Interim AI Policy](https://openjdk.org/legal/ai).
-------------
Commit messages:
- 8398335: JVMTI frame walks miss frames on platform and carrier threads
Changes: https://git.openjdk.org/jdk/pull/34089/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34089&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8398335
Stats: 587 lines in 5 files changed: 582 ins; 0 del; 5 mod
Patch: https://git.openjdk.org/jdk/pull/34089.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/34089/head:pull/34089
PR: https://git.openjdk.org/jdk/pull/34089