Skip to content

fix(profiler): complete malloc/native-socket hook-prefix-skip stackwalking#648

Draft
jbachorik wants to merge 5 commits into
mainfrom
jb/malloc_profiles
Draft

fix(profiler): complete malloc/native-socket hook-prefix-skip stackwalking#648
jbachorik wants to merge 5 commits into
mainfrom
jb/malloc_profiles

Conversation

@jbachorik

@jbachorik jbachorik commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?:
Fixes up gaps in the malloc/native-socket hook-prefix-skip stackwalking logic introduced earlier on this branch (convertNativeTrace and HotspotSupport::walkVM), which was incomplete:

  • Surfaces silent hook-symbol mark-resolution failures via new diagnostic counters and a warning log instead of silently no-opping (markAsyncProfilerHook now returns bool; NativeSocketSampler::start() checks it).
  • Adds a counter for when the MARK_ASYNC_PROFILER hook boundary is never found in a callchain, so a fully-discarded/empty native stack is observable rather than silent.
  • Fixes convertNativeTrace's MARK_ASYNC_PROFILER reset to gate on the immutable skip_hook_prefix parameter instead of the mutable skipping flag, so a second boundary-marked frame later in the same callchain is still treated as a reset point (matches walkVM's per-frame dispatch).
  • Restores the MARK_COMPILER_ENTRY dispatch branch in walkVM that had been dropped without updating the comp_task flag/docs that still reference it.
  • Drops the now-redundant is_marked field on NativeFrameResolution in favor of a computed mark != 0 accessor, and updates the stale doc comments describing per-mark dispatch semantics.
  • Introduces a single isHookPrefixedSample() helper (BCI and EventType overloads) used at all 4 call sites that previously hardcoded the "is this a malloc/socket sample" predicate independently.
  • Adds stack-trace assertions to NativeSocketStackTraceTest proving a real caller frame (not a profiler-internal hook frame) is present after unwinding.

Motivation:
The hook-prefix-skip stackwalking added earlier on this branch was incomplete — this closes the gaps before the branch merges.

Additional Notes:
The restored MARK_COMPILER_ENTRY dispatch is currently unreachable: _features.comp_task is never set to 1 anywhere in the codebase (no CLI flag wires it), so this fix restores doc/dead-code consistency but doesn't change observable behavior. Revisiting that separately.

How to test the change?:
./gradlew assembleDebugJar builds clean; ./gradlew compileTestJava compiles clean. The new/updated assertions in NativeSocketStackTraceTest are parameterized across vm/vmx/dwarf/fp cstack modes and cover the fixed code paths.

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: [JIRA-XXXX]

Unsure? Have a question? Request a review!

jbachorik and others added 5 commits July 10, 2026 16:48
…ix missing native frames

The event name/category did not follow the datadog.* convention used by other
events. Separately, Profiler::getNativeTrace unconditionally skipped native
stack unwinding for BCI_NATIVE_MALLOC under the default cstack setting,
leaving only Java frames in malloc call stacks.
Same guard in Profiler::getNativeTrace that was skipping native unwinding
for BCI_NATIVE_MALLOC also applied to BCI_NATIVE_SOCKET; both are non-CPU/WALL
event types and were bypassed when cstack is left at its default.
Marks the socket hook wrapper symbols (send/recv/write/read_hook) with
MARK_ASYNC_PROFILER, mirroring the existing malloc hook marking, and
teaches convertNativeTrace to discard frames captured before reaching
that mark instead of truncating the stack there, so only the real
caller frames remain for BCI_NATIVE_MALLOC/BCI_NATIVE_SOCKET traces.
Adds SOCKET_SAMPLE to EventType so BCI_NATIVE_SOCKET gets its own
identity in walkVM, and fixes a bug where the generic is_marked
check in HotspotSupport::walkVM terminated the scan on ANY mark
before the MARK_ASYNC_PROFILER dispatch below it could ever run,
making the malloc hook-skip logic dead code. NativeFrameResolution
now carries the actual mark value so walkVM can dispatch correctly:
MARK_ASYNC_PROFILER resets depth and resumes past the hook boundary
for malloc/socket samples (matching the FP/DWARF path), other marks
still terminate the scan as before.
Surface silent hook-mark resolution failures via counters/logging, make
convertNativeTrace's MARK_ASYNC_PROFILER reset gate on skip_hook_prefix
instead of the mutable skipping flag, restore the dropped
MARK_COMPILER_ENTRY dispatch in walkVM, drop the now-redundant is_marked
field, de-duplicate the hook-prefixed-sample predicate, and add stack
trace assertions for the socket hook boundary skip.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jbachorik jbachorik added the AI label Jul 10, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #29114537583 | Commit: 9cc346d | Duration: 17m 2s (longest job)

1 of 32 test jobs failed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
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 Tests

glibc-amd64/debug / 11-j9

Job: View logs

No detailed failure information available. Check the job logs.

Summary: Total: 32 | Passed: 31 | Failed: 1


Updated: 2026-07-10 18:47:56 UTC

@jbachorik jbachorik changed the title Address review findings on malloc/socket hook-skip stackwalking fix(profiler): complete malloc/native-socket hook-prefix-skip stackwalking Jul 10, 2026
@jbachorik

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 002040ca88

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant