Skip to content

Make ProfiledThread's UnwindFailures field debug only - #734

Open
zhengyu123 wants to merge 5 commits into
mainfrom
zgu/unwinfailures
Open

Make ProfiledThread's UnwindFailures field debug only#734
zhengyu123 wants to merge 5 commits into
mainfrom
zgu/unwinfailures

Conversation

@zhengyu123

@zhengyu123 zhengyu123 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?:

Removes the UnwindFailures/UnwindStats per-thread diagnostic counters from release builds, gating them entirely behind #ifdef DEBUG, and backfills a test.

  • New macro — debug_only(s) expands to s when DEBUG is defined, else to nothing.

  • threadLocalData.h ProfiledThread::_unwind_failures is now debug_only(...), and the unwindFailures() accessor is wrapped in #ifdef DEBUG. This is the actual memory-overhead fix — the field no longer exists per-thread on release builds.

  • unwindStats.h: entire UnwindStats class and its static members wrapped in #ifdef DEBUG — the whole subsystem is compiled out on release.

-flightRecorder.cpp: Recording::writeUnwindFailures() body gated by #ifdef DEBUG (becomes a no-op on release).

  • hotspotSupport.cpp: the call sites that record into UnwindFailures are gated by #ifdef DEBUG.

  • build.gradle.kts: the unwindFailuresBenchmark now compiles with -DDEBUG, since the code it benchmarks no longer exists without that define.

  • Tests:
    -- existing UnwindFailures/UnwindStats gtest cases in ddprof_ut.cpp wrapped in #ifdef DEBUG;
    -- new UnwindFailuresTest.java — a JFR smoke test under cstack=vm that skips unless the build config is debug/*san, asserts the profiler runs cleanly, and sanity-checks datadog.UnwindFailure event schema if any happen to fire (a real stub-unwind failure is described as too rare to force deterministically).

Motivation:
Reduce profiler memory usage in release build

Additional Notes:

How to test the change?:

  • CI tests - no regression
  • New test to test UnwindFailures in debug build

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-15696

Unsure? Have a question? Request a review!

@dd-octo-sts

dd-octo-sts Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmvrwv9
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Tue Aug 11 18:41:55 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs1
Logic error
Dereference of null pointer1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Logic errorDereference of null pointerprofiler.hfindLibraryByAddress52313

@dd-octo-sts

dd-octo-sts Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #31523867699 | Commit: e3300b5 | Duration: 18m 45s (longest job)

All 32 test jobs passed

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

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-08-11 19:01:35 UTC

@dd-octo-sts

dd-octo-sts Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 a7ec37a9

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes unwind-failure tracking (the UnwindFailures counters surfaced via the datadog.UnwindFailure JFR event) available only in DEBUG-instrumented native builds, reducing per-thread memory overhead in release builds while keeping the diagnostics pipeline intact for debug/asan/tsan.

Changes:

  • Compile-gate unwindStats.{h,cpp} and per-thread ProfiledThread::_unwind_failures behind DEBUG, introducing a debug_only(...) macro to simplify conditional inclusion.
  • Guard unwind-failure emission/serialization paths in HotSpot VM unwinding (HotspotSupport::walkVM) and JFR writing (Recording::writeUnwindFailures) to DEBUG builds.
  • Add a JUnit smoke test that validates datadog.UnwindFailure event schema when present, and update the unwind-failures benchmark to compile with -DDEBUG.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ddprof-test/src/test/java/com/datadoghq/profiler/UnwindFailuresTest.java Adds a DEBUG-only smoke test for the datadog.UnwindFailure JFR event schema under cstack=vm.
ddprof-lib/src/test/cpp/ddprof_ut.cpp Wraps UnwindFailures/UnwindStats unit tests in #ifdef DEBUG.
ddprof-lib/src/main/cpp/unwindStats.h Makes UnwindFailures/UnwindStats definitions DEBUG-only.
ddprof-lib/src/main/cpp/unwindStats.cpp Makes UnwindStats static member definitions DEBUG-only.
ddprof-lib/src/main/cpp/threadLocalData.h Makes ProfiledThread’s per-thread UnwindFailures storage and accessor DEBUG-only.
ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Records unwind failures only in DEBUG builds during walkVM unwinding.
ddprof-lib/src/main/cpp/flightRecorder.cpp Writes datadog.UnwindFailure events only in DEBUG builds.
ddprof-lib/src/main/cpp/common.h Introduces debug_only(...) macro for DEBUG-conditional code.
ddprof-lib/benchmarks/build.gradle.kts Compiles the unwind-failures benchmark with -DDEBUG.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ddprof-lib/src/test/cpp/ddprof_ut.cpp Outdated
zhengyu123 and others added 2 commits August 11, 2026 18:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@zhengyu123 zhengyu123 changed the title Make ProfiledThread's UnwinFailures field debug only Make ProfiledThread's UnwindFailures field debug only Aug 11, 2026
@zhengyu123
zhengyu123 marked this pull request as ready for review August 11, 2026 18:59
@zhengyu123
zhengyu123 requested a review from a team as a code owner August 11, 2026 18:59

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7ec37a9d9

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

return 0;
}

debug_only(UnwindFailures* unwindFailures = prof_thread->unwindFailures();)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid resetting unwind stats on every sample

In DEBUG/ASan/TSan builds with cstack=vm, every CPU/wall sample reaches this new call and unwindFailures() defaults to reset=true, so it invokes clear() even when no unwind failure has occurred. That clear() zeros the 1024-name/counter buffers (about 288 KiB) on the signal sampling path for each walk, which can dominate debug/sanitizer profiling; keep the per-thread buffer untouched until a failure is recorded or make the reset O(1).

AGENTS.md reference: AGENTS.md:L375-L376

Useful? React with 👍 / 👎.

# endif
#endif

#ifdef DEBUG

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the required Datadog copyright header

This modified header still starts directly with the include guard, but the repository instructions require adding a Datadog copyright when touching files that do not already contain one. The same issue applies to the modified unwindStats.h and unwindStats.cpp files, so please add the standard current-year header before landing.

AGENTS.md reference: AGENTS.md:L372-L374

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants