Skip to content

fix(profiler): recover arm64 native stacks across sampling signals - #917

Open
kaahos wants to merge 24 commits into
paul.fournillon/fix-continuation-carrier-recoveryfrom
paul.fournillon/test-continuation-remount-chaos
Open

kaahos wants to merge 24 commits into
paul.fournillon/fix-continuation-carrier-recoveryfrom
paul.fournillon/test-continuation-remount-chaos

Conversation

@kaahos

@kaahos kaahos commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:
Preserve ARM64 native and Java ancestry during CPU and wall sampling. Correct DWARF return-address rules, C1 temporary stack areas and JNI wrapper phases, and recover saved contexts at Linux vDSO signal returns and at the libc restorer the kernel reports for profiler handlers.

Motivation:
Incorrect return-address sources and frame-size assumptions lose callers or fabricate ancestry across native transitions and nested signals.

Additional Notes:

  • Stacked on feat(profiler): recover carrier ancestry at continuation boundaries #887. Heap-resident frozen caller recovery remains in fix(profiler): recover frozen virtual-thread callers #879.
  • Unsupported signal restorers stop with truthful truncation. No allocation, blocking synchronization or ucontext mutation is added to signal paths.
  • musl signal restorer: the kernel builds the same rt_sigframe for every SA_RESTORER trampoline, but the instruction pair alone does not prove a frame is one. Recovery trusts the vDSO restorer and the restorer the kernel reports, via rt_sigaction, for a three-argument handler that OS::installSignalHandler just installed. musl always installs its own __restore_rt. Without this, on musl arm64 every profiling signal that landed inside another profiler handler (CPU inside wall-clock, or the reverse) stopped at the handler, so 1–3% of carrier CPU samples were truncated in the chaos test. The trust is checked once, at install time, and then persists. OS::replaceCrashHandler does not set it.
  • Human review: mandatory. The change alters stack-walker code that runs inside SIGPROF/SIGVTALRM handlers on arm64.
  • Agentic review: Sphinx (standard effort) on the full range, then /code-review (medium) on each fix range. No Critical/High findings. Fixed: inaccurate restorer comment/doc, a misnamed test, four uncovered boundary branches (DW_CFA_nop, CIE-initial advance opcodes, the rt_sigframe span bound, the native-leaf entry bound). The last fixes (doc corrections and the C++ cast conversion of this PR's added lines) had /code-review medium; no Critical or High finding. The chaos-classifier fix had /code-review medium and two fix rounds; no Critical or High finding. Open Low items from those reviews: the cap comment says a root-only regression fails, but only above the cap; the cap's assertion message hard-codes 10% and names carrier walks instead of successful boundary walks; TestingGuide.md does not name the cap's denominator; no test has a non-leaf thaw frame or a null method name; the eligible() test helper parses toString(). Open Low items from the cast review: unwindEpilogue is called with reinterpret_cast<uintptr_t&>(epilogue_pc) on a const void* local, a strict-aliasing write that predates the conversion; two unchanged lines next to converted ones still use C-style casts. The musl restorer fix had /code-review medium and three fix rounds; no Critical or High finding. Open Low items from its last round: ReportsTheRestorerTheKernelHoldsForASignal restores its signal only at the end, so a failed assertion leaves a fake handler on SIGRTMIN+7; the comment on the 1-arg step of InstallingAHandlerTrustsOnlyAReportedRestorer states a premise the test does not assert; installSignalHandler(signo, NULL, SIG_DFL) would take the 3-arg path (no caller does this). Open Low findings, not fixed (review-round limit reached):
    • advanceDwarfFrame: the existing depth == 1 LR branch does not null-check the ucontext. No current caller reaches it without a context.
    • signalFrame_ut AcceptsFrameEndingAtSavedPc uses an interrupted SP inside the frame and copies the production required expression.
    • signalFrame_linux.cpp restorer comment could name the mechanism more precisely; JvmSupportLayer.md does not describe the CFI/FP fallback on other VMs.
    • dwarf_ut: RestoreUsesCieDefinedReturnAddressRule still uses ASSERT_GE; the nop and CIE-advance tests could also assert row loc.
  • The CIE-derived initial return-address rule (LR on arm64, also for PLT leaves and DW_CFA_restore) also fixes PROF-16925: on main, a sample in an arm64 native leaf that has not saved LR ends after one frame.
  • walkDwarf now unwinds an atomic stub at any depth where the frame describes the cursor (atInterruptedContext), so a context restored at a signal frame that lands on a stub follows its LR into libjvm. interruptedContext_ut covers the helper; the end-to-end path (signal-frame recovery onto a stub) has no test, because it needs a Linux arm64 HotSpot fixture.
  • After walkDwarf recovers a signal frame, the restored context's LR now reaches the Java walk: StackContext::lr carries it, getJavaTraceAsync writes it next to PC/SP/FP for ASGCT's stub and prologue retries, and RegisterSnapshot saves and restores LR so the sampling context is put back intact.
  • ContinuationStackChecks counts a known carrier's truncated, native-only stack as a failed walk, and GraalNativeUnwindRegressionTest counts every skipped-frames gap in a workload sample. Accepted change (signed off by Paul Fournillon, 2026-11-26, recorded on PROF-16298): in cstack=vm only, a truncated carrier stack that ends at the single outermost JVM Continuation root, with at least one thaw frame or nothing above it, is not a failed walk. It counts in thawsAtRoot, never as a success, and is capped at 10% of successful walks. In vm mode the walk stops at that root by design; a carrier sampled mid-thaw has no mounted Java frame yet. Accepted risk: a walker regression that emits only the root on up to 10% of carrier samples passes, and the exemption needs resolved thaw symbols in libjvm.
  • Open from a later /code-review medium of 1fcbecfe8 (not addressed in this PR yet):
    • The C1 object-arraycopy outer-pair adjustment applies only at the call's return address; a sample on the following cbnz or second ldp still computes SP 16 bytes short (a coverage gap, not a regression).
    • testCommon now depends on chaosElements, whose JAR compiles against :ddprof-lib's debug configuration, so non-debug test cells may also build the native debug library (not measured).

How to test the change?:
Run the native suites and the GraalNativeUnwindRegressionTest and VirtualThreadCarrierChaosTest integration tests through ./.claude/commands/build-and-summarize.

Validation for 6999f70b2 (on #887 f0df35f39):

  • Local macOS arm64 :ddprof-lib:gtestDebug: passed (1,710 tests OK, 0 failed). qualityChecks and spotlessCheck: passed.
  • signalFrame_ut on 6999f70b2 (podman, Linux arm64, JDK 25, debug): passed on musl and glibc (16 tests each). Removing the null-handler guard fails a test on glibc; trusting a 1-arg handler fails one on musl.
  • Earlier, on d76f7adb4: signalFrame_ut passed on musl and on glibc (16 tests each). Each new guard fails a test when removed (checked by mutation on the libc where it applies).
  • Linux musl arm64 :ddprof-lib:gtestDebug: passed (on c5b2a47d7; the last commit changes only OS::installSignalHandler's call, its test and docs).
  • Linux musl arm64 VirtualThreadCarrierChaosTest (on d76f7adb4): passed; carrier-only failures 0 (CPU) and 0 (wall). Before the fix, 100 CPU samples stopped at the handler.
  • Linux glibc arm64 VirtualThreadCarrierChaosTest (cstack=vm and vmx): passed (on c5b2a47d7).
  • Remote CI: pending for this head.

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 (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16298

@dd-octo-sts

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

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #46026873213 | Commit: 5fa7805 | Duration: 24m 10s (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

⚠️ Flaky tests — failed, then passed on retry

Test Cells Message
MallocArenaWarningTest.statsEventsDescribeTheArenas__ glibc-8-orcl-debug-amd64 org.opentest4j.AssertionFailedError: expected: <478150656> but was: <477626368>

These fail the build. Passing on a second run makes a test flaky, not passing. Fix it, or quarantine it against a ticket so the debt is tracked rather than forgotten.

Consider quarantining these — click for ready-made entries

A quarantined test still runs and still reports; its failures just stop
turning CI red. To quarantine one:

  1. Open a PROF ticket for the test, linking the failing job.
  2. Append the line below to ddprof-test/quarantine.txt, replacing
    PROF-XXXXX with the ticket number.
  3. Check the cells and reason columns — the proposal only knows what
    failed in this run, and a narrower cells glob keeps the same test
    gating everywhere it has not misbehaved.

CI fails once review_by passes, so an entry expires instead of piling up.

# test | ticket | added | review_by | cells | reason
com.datadoghq.profiler.nativemem.MallocArenaWarningTest.statsEventsDescribeTheArenas | PROF-XXXXX | 2026-11-27 | 2027-02-25 | glibc-8-orcl-debug-amd64 | org.opentest4j.AssertionFailedError: expected: <478150656> but was: <477626368> (seen in: glibc-8-orcl-debug-amd64)

Retried 1 of 102 cells.

Failed Jobs

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


Updated: 2026-11-27 16:09:15 UTC

@dd-octo-sts

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

Copy link
Copy Markdown
Contributor

✅ All 30 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 6999f70b

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

@kaahos kaahos changed the title test(profiler): share virtual-thread remount chaos coverage fix(profiler): recover arm64 native stacks across sampling signals Oct 28, 2026
@datadog-datadog-us1-prod

This comment has been minimized.

@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:43:56 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/test-continuation-remount-chaos branch from 6779cd7 to 45d82b0 Compare November 19, 2026 10:28
@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/test-continuation-remount-chaos branch from d6d0e5e to 1fcbecf Compare November 19, 2026 22:34
@kaahos kaahos added test:release Run CI tests with release configuration test:tsan Run CI tests with ThreadSanitizer configuration test:fuzz test:reliability labels Nov 20, 2026
@kaahos
kaahos force-pushed the paul.fournillon/test-continuation-remount-chaos branch from 1fcbecf to 471a8f7 Compare November 20, 2026 14:17
@dd-octo-sts

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

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

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

@kaahos
kaahos force-pushed the paul.fournillon/test-continuation-remount-chaos branch 2 times, most recently from b7ee0a6 to 493815f Compare November 23, 2026 10:24
@kaahos
kaahos marked this pull request as ready for review November 23, 2026 15:27

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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

Unavailable base-version Git objects limited assessment of the ARM64 unwinding changes. No concrete regression was established in the available code.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f4fb2bb

@kaahos
kaahos force-pushed the paul.fournillon/test-continuation-remount-chaos branch from f4fb2bb to 0f12507 Compare November 26, 2026 16:03

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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

Nested-signal recovery intentionally stops at unsupported restorers, including musl’s __restore_rt. The completed static review raised no reportable findings; ARM64 signal-handler behavior remains unverified at runtime.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0f12507

@kaahos
kaahos force-pushed the paul.fournillon/test-continuation-remount-chaos branch from 0f12507 to 7b39da6 Compare November 27, 2026 12:59

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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

Static review supports the restored PC and link-register handoff into Java walking, with unsupported signal restorers explicitly truncating the walk. ARM64 runtime behavior across nested signals remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7b39da6

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.

1 participant