Skip to content

fix(profiler): recover frozen virtual-thread callers - #879

Open
kaahos wants to merge 25 commits into
paul.fournillon/test-continuation-remount-chaosfrom
paul.fournillon/recover-frozen-virtual-thread-callers
Open

kaahos wants to merge 25 commits into
paul.fournillon/test-continuation-remount-chaosfrom
paul.fournillon/recover-frozen-virtual-thread-callers

Conversation

@kaahos

@kaahos kaahos commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:
Recover frozen Java callers from HotSpot stack chunks at a verified continuation boundary. Restore deoptimized and inlined callers while preserving truthful truncation when recovery is incomplete.

Motivation:
A partial thaw leaves older Java callers in the heap. Recovering carrier frames alone cannot restore that ancestry. This change appends the frozen callers before the continuation root or carrier walk.

Additional Notes:

  • Depends on fix(profiler): recover arm64 native stacks across sampling signals #917. The stack is fix(profiler): mark skipped frozen virtual-thread callers as truncated #877 → fix(profiler): encode debug unwind event sizes as varints #916 → feat(profiler): recover carrier ancestry at continuation boundaries #887 → fix(profiler): recover arm64 native stacks across sampling signals #917 → fix(profiler): recover frozen virtual-thread callers #879. Each PR retains tests for its own production behavior.

  • This delta contains heap recovery, its metadata and counters, focused regressions, and documentation. General DWARF, signal-frame, C1 temporary-stack, and native-test linking corrections belong to fix(profiler): recover arm64 native stacks across sampling signals #917; carrier-boundary corrections belong to feat(profiler): recover carrier ancestry at continuation boundaries #887.

  • Recovery requires HotSpot 21–27, G1/Serial/Parallel, supported metadata, and an interrupted Java body. Native/runtime transitions, unsupported collectors, and nested continuations retain the truncation fallback.

  • Native-call origins outside the freeze/thaw runtime use the first mounted Java frame the walk emitted. Classification requires libjvm's freeze/thaw entry templates, which are static, so their symbols use internal linkage (_ZL); the external spelling (_Z) is also accepted. A stripped libjvm keeps the conservative rejection.

  • Behavior change, please acknowledge: the origin is recorded only after a Java frame is emitted. Any cursor-changing anchor redirect before that frame, including an SP/FP correction inside the same nmethod, now rejects the substitution, as stub-blob redirects already did.

  • The published layout is immutable after successful initialization. Missing metadata remains retryable.

  • MARK_CONT_RUNTIME only annotates libjvm freeze/thaw frames. They keep their symbol (or remote packing), and native walks continue through them. walkVM reads the mark to keep the interrupted-PC rejection.

  • When recovery fails after some frozen frames were appended, those frames stay in the trace and the sample stays truncated. No [skipped frames] marker is added; the JVM Continuation root and the truncation flag identify the gap.

  • High-arity assertions retain strict carrier ancestry and first-invalid-stack diagnostics. The reducer also accepts stacks whose older Java callers were recovered.

  • Chaos gate change, please acknowledge: in ContinuationStackChecks, each layout's partial-thaw coverage check now also passes when the recording-wide walkvm_frozen_recovered counter reaches the minimum. Recovered samples are complete, so they no longer count as partial thaws, and JFR cannot attribute a recovery to a layout. Recoveries in one layout can therefore satisfy the other layout's check.

  • Test design, please acknowledge: ddprof-test test JVMs get -XX:CompileCommand=dontinline for FrozenVirtualThreadStackTest.sampledLeaf (no CompileCommand=quiet, so each test JVM echoes that one line), and the test fails if sampledLeaf is ever recorded as inlined. For an interrupted PC, walkVM approximates the leaf frame's inline chain with the next PcDesc, and it does not flag the approximation. On GraalVM 25 aarch64, where sampledLeaf was inlined into several recursive copies, one sample took another copy's chain and reported 7 extra callers. Its stack was still marked complete, so the exact caller-count check failed. The approximation is older than this PR and applies to every thread kind. PROF-16768 tracks whether to detect and flag it.

  • Agentic review: on the head after the rebase onto fix(profiler): recover arm64 native stacks across sampling signals #917, Sphinx (standard, generalist only: no corpus) on the full range, then /code-review medium on the fix range, two runs. No Critical or High findings. Open Medium items:

    • prepare_thaw_internal (non-template glue under Continuation::prepare_thaw) is not marked as freeze/thaw runtime. If the compiler emits it as a sibling call, a sample inside it has no marked frame on the stack.
    • No gtest pins the boundaries of the Config<oop_kind, ...> symbol match, and no gtest covers the compiled-frame branch of append; the Java tests cover compiled frozen frames on real JVMs.
      A later /code-review medium of e0d4ae1b7 and of its fix ranges found and fixed: _ZL entry names that kept classification always false, an origin taken from a frame the anchor redirect abandoned, a repeated findNMethod and the redundant freeze/thaw entry prefixes. Open Low items from those rounds: the java_origin_pc == NULL guard is repeated at two call sites to skip the lookup; marking (Config substring) and classification (entry prefixes) are not coupled by construction; the linkage comment attributes the _ZL mangling to HotSpot rather than the compiler.
      The latest fixes (bd190c21e..085f97a51: dead origin recording removed, a fault recovered inside append counted in walkvm_frozen_failed, compiler fences around that flag, doc) had /code-review medium on the fix range and twice on its follow-ups; no Critical or High finding. Open Low items from those rounds (round limit reached): no test covers resetting the append flag after a successful recovery; the high-arity test no longer proves that a sample had frozen callers to recover; FrozenStackWalker.md does not say that a faulted attempt adds no frame or chunk counts, that it ends the walk with break_not_walkable (or discards an anchor-seeded walk), that the gtest recovers through a stand-in SIGSEGV handler, and it still calls the counters "debug counters".
      The absent-deoptimization-handler fix had /code-review medium and two fix rounds; no Critical or High finding. Open Low items from its last round: the test now takes the call size from VMNMethod::deoptHandlerCallSize, so a typo in that constant is no longer caught; one new assertion in AbsentHandlerMatchesNoPc duplicates RejectsJvmciReturnPcAfterHandlerCall.
      Open Low items: the remaining per-class freeze/thaw prefixes are redundant with the Config match; later marking passes overwrite earlier marks; the doc and the MARK_CONT_RUNTIME comment describe the match loosely; the RemoteFramePacker mark bits are always zero.
  • Human review: mandatory. The change adds heap reads to the signal-handler stack walk (perf-critical, shared-library behavior).

  • Merge readiness depends on feat(profiler): recover carrier ancestry at continuation boundaries #887 and fix(profiler): recover arm64 native stacks across sampling signals #917 landing first.

  • History: rebuilt on the rebased fix(profiler): recover arm64 native stacks across sampling signals #917 as one feature commit that carries the earlier work-in-progress history, followed by the review fixes.

  • A frozen frame whose PC is a JVMCI deoptimization return address (handler + NativeCall::instruction_size) is rejected instead of being treated as an ordinary PC, so its inline callers cannot be silently dropped.

  • VMNMethod::originalPC treats an absent (null) deoptimization handler as matching no PC; each handler falls back to the other. On JDK 21/22 the method-handle handler address can be null, so the old comparison did pointer arithmetic on null: UBSan reported it in the FrozenDeoptimizationTest child under ASan, which then exited with status 1.

  • A walk that crossed freeze/thaw runtime frames is marked truncated at every boundary kind: a sample inside thaw returns to the entry return PC while older callers are still frozen.

Validation for 24f804415 (restacked on #917 6999f70b2):

  • Local macOS arm64 :ddprof-lib:gtestDebug: passed (1,756 tests OK, 0 failed). RecoveredFaultInAppendCountsAsFailed fails without the landing-pad count; AbsentHandlerMatchesNoPc fails without either fallback.
  • qualityChecks and spotlessCheck: passed.
  • Linux arm64 FrozenDeoptimizationTest (podman, glibc, JDK 21, asan): passed, 3 of 3, child exit 0, on 176dc42dd. It failed 3 of 3 before the fix, as in CI.
  • Linux arm64 HighArityVirtualThreadStackTest (podman, glibc, JDK 25, debug): passed on 355122c14 (27 boundary samples, 0 continuation errors, notWalkable=0).
  • Local macOS arm64 FrozenDeoptimizationTest (Temurin 25.0.5, measured on 4cc060b00): failed, 3 of 3, No frozen callers were recovered. The earlier head e0d4ae1b7 fails the same way. No CI cell runs macOS tests. Tracked in PROF-16813.
  • Local macOS *VirtualThread*: inconclusive, all 11 tests skipped on this platform.
  • CI on 724435173, glibc aarch64 25-graal release: FrozenVirtualThreadStackTest.restoresWhileCollecting[cstack=vm] failed once, then passed on retry: one application-Java sample was [sampledLeaf, JVM Continuation], truncated, with frozen recovery failed (recovered=653, failed=774). The cause is not identified: FrozenStackWalker::append has no per-reason failure counters. The stack is honestly marked truncated, but the test requires full recovery at application samples.
  • Remote CI: pending for this head.

How to test the change?:

./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug qualityChecks
for test_class in '*Frozen*Test' 'NestedContinuationTransition*' VirtualThreadCarrierChaosTest HighArityVirtualThreadStackTest; do
  ./.claude/commands/build-and-summarize :ddprof-test:testDebug \
    "-Ptests=$test_class" -Pskip-gtest -PkeepJFRs || exit 1
done

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a security review.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16269

@dd-octo-sts

dd-octo-sts Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #46028393113 | Commit: 9c1177f | Duration: 25m 28s (longest job)

❌ 1 of 108 test jobs failed

Status Overview

JDK glibc-aarch64/asan glibc-aarch64/debug glibc-aarch64/release glibc-aarch64/tsan glibc-amd64/asan glibc-amd64/debug glibc-amd64/release glibc-amd64/tsan musl-aarch64/debug musl-aarch64/release musl-amd64/debug musl-amd64/release
8 - - - - ✅ ✅ ✅ ✅ - - - -
8-ibm - - - - ✅ ✅ ✅ ✅ - - - -
8-j9 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
8-librca - - - - - - - - ✅ ✅ ✅ ✅
8-orcl - - - - ✅ ✅ ✅ ✅ - - - -
11 - - - - ✅ ✅ ✅ ✅ - - - -
11-j9 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
11-librca - - - - - - - - ✅ ✅ ✅ ✅
17 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
17-graal ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
17-j9 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
17-librca - - - - - - - - ✅ ✅ ✅ ✅
21 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
21-graal ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
21-librca - - - - - - - - ✅ ✅ ✅ ✅
25 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
25-graal ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ - - - -
25-librca - - - - - - - - ✅ ✅ ✅ ❌

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Failed Jobs

  • musl-amd64/release / 25-librca — view logs

Summary: Total: 108 | Passed: 107 | Failed: 1


Updated: 2026-11-27 16:20:04 UTC

@dd-octo-sts

dd-octo-sts Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 30 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 24f80441

10 not applicable (not scheduled): musl-x64-openj9, musl-arm64-openj9. OpenJ9 requires glibc; upstream publishes no musl runtime.

@dd-octo-sts

dd-octo-sts Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

✅ All reliability & chaos checks passed Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/156816215

@kaahos
kaahos marked this pull request as ready for review October 22, 2026 16:51
@kaahos
kaahos requested a review from a team as a code owner October 22, 2026 16:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T15:32:18.473265Z 0a272be Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Nested continuation transitions can make frozen-stack recovery append suspended child callers instead of parent callers and incorrectly report the trace as complete.

Open Bits AI session

🤖 Bits Code Review · Commit 746acbe

@datadog-official

This comment has been minimized.

@kaahos
kaahos changed the base branch from paul.fournillon/fix-frozen-virtual-thread-truncation to paul.fournillon/fix-continuation-carrier-recovery October 23, 2026 19:42

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Local JDK checks supported the stack-chunk layout and deoptimization metadata assumptions used to recover frozen callers. The completed static review identified no concrete regression within the examined scope.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit af03bf7

@kaahos
kaahos changed the base branch from paul.fournillon/fix-continuation-carrier-recovery to paul.fournillon/test-continuation-remount-chaos October 28, 2026 13:12
@kaahos
kaahos marked this pull request as draft October 28, 2026 13:12

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Frozen-stack reads require Java thread state and an interrupted Java-body PC, matching the safeguards described in the human PR discussion. Incomplete recovery preserves truncation.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 833aceb

@jbachorik
jbachorik added this pull request to stack #922 October 29, 2026 15:03
@dd-octo-sts

dd-octo-sts Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmccnms
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 21.1.8 (6ubuntu1)
Date:Wed Nov 18 17:47:48 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs2
Logic error
Dereference of null pointer1
Unused code
Dead initialization1

Filter Results by File

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead initializationreferenceChains.cppapplyOomRamp4971
Logic errorDereference of null pointerperfEvents_linux.cppunregisterThread72026

@kaahos kaahos added test:asan Run CI tests with AddressSanitizer configuration human_review:mandatory Human review required — see PR description labels Nov 14, 2026
@kaahos
kaahos force-pushed the paul.fournillon/recover-frozen-virtual-thread-callers branch from 88058a7 to 1bf3039 Compare November 19, 2026 13:33
@kaahos
kaahos removed this pull request from stack #922 November 19, 2026 16:27
@kaahos
kaahos added this pull request to stack #1026 November 19, 2026 16:28
@kaahos
kaahos removed this pull request from stack #1026 November 19, 2026 22:34
@kaahos
kaahos added this pull request to stack #1033 November 19, 2026 22:34
@kaahos
kaahos force-pushed the paul.fournillon/recover-frozen-virtual-thread-callers branch from c444ade to e0d4ae1 Compare November 19, 2026 22:34

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The completed static assessment raised no actionable correctness issue in frozen-caller recovery. Runtime behavior remains unverified because tests were not run.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f3cb810

@kaahos
kaahos force-pushed the paul.fournillon/recover-frozen-virtual-thread-callers branch from f3cb810 to 2f0372c Compare November 27, 2026 14:57

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Frozen-caller recovery rejects non-Java thread states before reading continuation heap objects, consistent with the safepoint handling discussed on the PR. The completed static review produced no reportable defect; runtime behavior remains unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2f0372c

@kaahos
kaahos force-pushed the paul.fournillon/recover-frozen-virtual-thread-callers branch from 2f0372c to 24f8044 Compare November 27, 2026 15:50

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Frozen-caller recovery uses continuation-boundary and origin checks, with incomplete recovery retaining truncation. The static review raised no actionable findings; runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 24f8044

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human_review:mandatory Human review required — see PR description test:asan Run CI tests with AddressSanitizer configuration test:fuzz test:release Run CI tests with release configuration test:reliability test:tsan Run CI tests with ThreadSanitizer configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants