Skip to content

Use ThreadLocal to setup protection longjmp buffer and fix jmp_buf chaining - #615

Merged
zhengyu123 merged 55 commits into
mainfrom
zgu/objmonitor_deflation
Jul 6, 2026
Merged

Use ThreadLocal to setup protection longjmp buffer and fix jmp_buf chaining#615
zhengyu123 merged 55 commits into
mainfrom
zgu/objmonitor_deflation

Conversation

@zhengyu123

@zhengyu123zhengyu123 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?:
This PR intents to resolve some of mysterious crashes seen in later releases, e.g. PROF-15206, although, it might not actually solve this particular problem, but I believe it should have positive impact - Cloude and I believe that overwriting JavaThread's exception field is dangerous, in fact, overwriting any JVM data structures are dangerous, because the writes can result in races and readers may see wrong values, that can lead to crashes.

Before introducing Thread Local Handshake in JVM, thread object is usually only read by 'current` thread, so it is relative safe to alter, then restore values inside signal handler, but not any more - a thread may be able to read other thread's states before it decides how to proceed the handshake, so it may read wrong values.

This PR:
Avoid altering JavaThread for jmp_buf
Uses a thread local for storing longjmp buffer and eliminates the dependency on overwriting JavaThread's exception field, so

  • Avoiding other thread reads wrong value of the exception field.
  • longjmp now protects all threads, not just JavaThread - should improve stability.

Chaining jmp_buf
A none signal based sampler can be interrupted by signal based sampler. Therefore, there may be multiple walkVM() calls on stack, each of them sets up a protection jmp_buf for stack walk, the jmp_bufs need to be chained to ensure to jump back to expected location.

Motivation:
Improve profiler's stability.

Additional Notes:
In additional, exception field only exists in JavaThread, but detection code in Profiler is somewhat questionable, especially, for the subclasses of JavaThread

How to test the change?:

  • CI tests
  • New unit tests

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

Unsure? Have a question? Request a review!

Comment threadddprof-lib/src/test/cpp/hotspot_crash_protection_ut.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2Bot commented Jun 24, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 6 Pipeline jobs failed

Code Quality Checks | codeql (cpp) View in DatadogGitHub Actions

Code Quality Checks | codeql (java) View in DatadogGitHub Actions

DataDog/java-profiler | reliability-chaos-aarch64: [profiler+tracer, tcmalloc, 21.0.3-tem] View in DatadogGitLab

View all 6 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c71118d | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-stsBot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run:#28827871146 | Commit:f81588b | Duration: 13m 55s (longest job)

All 32 test jobs passed

Status Overview

JDKglibc-aarch64/debugglibc-amd64/debugmusl-aarch64/debugmusl-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-07-06 22:52:10 UTC

zhengyu123and others added 4 commits June 24, 2026 16:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dd-octo-sts

dd-octo-stsBot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

2 failure(s) detected Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/123082923

❌ chaos: profiler tcmalloc amd64 21 0 3 temXchaos
Chaos harness crashed (RC=124)
❌ chaos: profiler tracer tcmalloc aarch64 25 0 3 temXchaos
Chaos harness crashed (RC=124)

CopilotAI 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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp

CopilotAI 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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Comment threadddprof-lib/src/main/cpp/threadLocal.h Outdated
Comment threadddprof-lib/src/main/cpp/threadLocal.h Outdated
Comment threadddprof-lib/src/main/cpp/threadLocal.h Outdated
Comment threadddprof-lib/src/main/cpp/jvmThread.cpp Outdated
Comment threadddprof-lib/src/main/cpp/jvmThread.h
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
zhengyu123and others added 5 commits June 26, 2026 20:09
@zhengyu123zhengyu123 changed the title wip: wip: Use TheadLocal to setup protection longjmp bufferJun 29, 2026
@zhengyu123
zhengyu123 requested a review from CopilotJune 29, 2026 13:30

CopilotAI 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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.h Outdated
Comment threadddprof-lib/src/main/cpp/jvmThread.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp Outdated
Comment threadddprof-lib/src/main/cpp/threadLocal.h Outdated
Comment threadddprof-lib/src/test/cpp/hotspot_crash_protection_ut.cpp Outdated
Comment threadddprof-lib/src/test/cpp/hotspot_crash_protection_ut.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dd-octo-sts

Copy link
Copy Markdown
Contributor

Benchmark Results (commit e4b9719)

Pipeline: https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines/122633659 Commit: e4b97194a1bd758dfffcb77ab669046e94fe63bc

⚠️ Significant outliers

  • 🟢 fj-kmeans (JDK 21): runtime -5% (2875→2730 ms)
  • 🔴 fj-kmeans (JDK 25): runtime +7.9% (2633→2842 ms)
  • ⚠️reactors (JDK 21): wallclock unwinds skipped — latest 0 → dev 1597 (new)
Runtime details (per benchmark × JDK)
BenchmarkJDKLatestDevΔ (dev vs latest)Issues L/D
akka-uct21✅ 10389 ms (7 iters)✅ 10329 ms (7 iters)≈ -0.6% (±20.8%)— / —
akka-uct25✅ 8966 ms (8 iters)✅ 8809 ms (8 iters)≈ -1.8% (±20.3%)— / —
finagle-chirper21✅ 6023 ms (11 iters)✅ 6002 ms (11 iters)≈ -0.3% (±44.9%)⚠️ W:1 / ⚠️ W:1
finagle-chirper25✅ 5457 ms (12 iters)✅ 5438 ms (12 iters)≈ -0.3% (±43.4%)⚠️ W:1 / ⚠️ W:1
fj-kmeans21✅ 2875 ms (22 iters)✅ 2730 ms (23 iters)🟢 -5%— / —
fj-kmeans25✅ 2633 ms (24 iters)✅ 2842 ms (22 iters)🔴 +7.9%— / —
future-genetic21✅ 2133 ms (29 iters)✅ 2080 ms (30 iters)≈ -2.5% (±4.2%)— / —
future-genetic25✅ 2070 ms (30 iters)✅ 2141 ms (29 iters)≈ +3.4% (±4.3%)— / —
naive-bayes21✅ 1221 ms (46 iters)✅ 1277 ms (45 iters)≈ +4.6% (±57.5%)— / —
naive-bayes25✅ 1034 ms (55 iters)✅ 1018 ms (56 iters)≈ -1.5% (±55.8%)— / —
reactors21✅ 16041 ms (5 iters)✅ 15714 ms (5 iters)≈ -2% (±17.4%)— / —
reactors25✅ 17707 ms (5 iters)✅ 17823 ms (5 iters)≈ +0.7% (±11.5%)— / —
Internal counter details (ddprof)

ddprof internal counters, latest / dev (✅ = 0, · = unavailable):

BenchmarkJDKDropped recDropped jvmtiDropped traceSkipped WCAGCT failUnwind fail
akka-uct21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
akka-uct25✅ / ✅✅ / ✅1 / 42466 / 2284✅ / ✅✅ / ✅
finagle-chirper21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
finagle-chirper25✅ / ✅✅ / ✅1 / 18316 / 8172✅ / ✅✅ / ✅
fj-kmeans21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
fj-kmeans25✅ / ✅✅ / ✅2 / 41298 / 1271✅ / ✅✅ / ✅
future-genetic21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
future-genetic25✅ / ✅✅ / ✅3 / 12914 / 2977✅ / ✅✅ / ✅
naive-bayes21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
naive-bayes25✅ / ✅✅ / ✅4 / 13478 / 3494✅ / ✅✅ / ✅
reactors21✅ / ✅✅ / ✅✅ / ✅✅ / 1597✅ / ✅✅ / ✅
reactors25✅ / ✅✅ / ✅✅ / 21765 / 1822✅ / ✅✅ / ✅

@zhengyu123
zhengyu123 marked this pull request as ready for review July 6, 2026 12:08

@chatgpt-codex-connectorchatgpt-codex-connectorBot 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:35d3ad2be2

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

@dd-octo-sts

Copy link
Copy Markdown
Contributor

Benchmark Results (commit 4b571c4)

Pipeline: https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines/122986649 Commit: 4b571c44baa590473687e46b003b9e00256421da

⚠️ Significant outliers

  • 🟢 fj-kmeans (JDK 21): runtime -5% (2872→2727 ms)
  • 🔴 future-genetic (JDK 25): runtime +5.6% (2018→2131 ms)
  • 🔴 reactors (JDK 21): runtime +11% (16572→18390 ms)
  • ⚠️fj-kmeans (JDK 21): wallclock unwinds skipped — latest 0 → dev 1268 (new)
Runtime details (per benchmark × JDK)
BenchmarkJDKLatestDevΔ (dev vs latest)Issues L/D
akka-uct21✅ 10142 ms (7 iters)✅ 10374 ms (7 iters)≈ +2.3% (±21.9%)— / —
akka-uct25✅ 8697 ms (8 iters)✅ 8704 ms (8 iters)≈ +0.1% (±16.9%)— / —
finagle-chirper21✅ 6027 ms (11 iters)✅ 5956 ms (11 iters)≈ -1.2% (±45.3%)⚠️ W:1 / ⚠️ W:1
finagle-chirper25✅ 5449 ms (12 iters)✅ 5449 ms (12 iters)≈ 0% (±43.5%)⚠️ W:1 / ⚠️ W:1
fj-kmeans21✅ 2872 ms (22 iters)✅ 2727 ms (23 iters)🟢 -5%— / —
fj-kmeans25✅ 2824 ms (22 iters)✅ 2791 ms (22 iters)≈ -1.2% (±4.6%)— / —
future-genetic21✅ 2034 ms (30 iters)✅ 2088 ms (30 iters)≈ +2.7% (±4.3%)— / —
future-genetic25✅ 2018 ms (31 iters)✅ 2131 ms (29 iters)🔴 +5.6%— / —
naive-bayes21✅ 1234 ms (46 iters)✅ 1327 ms (43 iters)≈ +7.5% (±58.8%)— / —
naive-bayes25✅ 1017 ms (56 iters)✅ 1017 ms (56 iters)≈ 0% (±55.2%)— / —
reactors21✅ 16572 ms (5 iters)✅ 18390 ms (5 iters)🔴 +11%— / —
reactors25✅ 18269 ms (5 iters)✅ 18396 ms (5 iters)≈ +0.7% (±6%)— / —
Internal counter details (ddprof)

ddprof internal counters, latest / dev (✅ = 0, · = unavailable):

BenchmarkJDKDropped recDropped jvmtiDropped traceSkipped WCAGCT failUnwind fail
akka-uct21✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅✅ / ✅
akka-uct25✅ / ✅✅ / ✅1 / 22289 / 2053✅ / ✅✅ / ✅
finagle-chirper21✅ / ✅✅ / ✅2 / ✅8650 / ✅✅ / ✅✅ / ✅
finagle-chirper25✅ / ✅✅ / ✅✅ / ✅8159 / 8478✅ / ✅✅ / ✅
fj-kmeans21✅ / ✅✅ / ✅✅ / 5✅ / 1268✅ / ✅✅ / ✅
fj-kmeans25✅ / ✅✅ / ✅7 / 41275 / 1265✅ / ✅✅ / ✅
future-genetic21✅ / ✅✅ / ✅1 / ✅2953 / ✅✅ / ✅✅ / ✅
future-genetic25✅ / ✅✅ / ✅3 / ✅2941 / ✅✅ / ✅✅ / ✅
naive-bayes21✅ / ✅✅ / ✅5 / ✅3490 / ✅✅ / ✅✅ / ✅
naive-bayes25✅ / ✅✅ / ✅3 / 23489 / 3508✅ / ✅✅ / ✅
reactors21✅ / ✅✅ / ✅2 / 31692 / 1976✅ / ✅✅ / ✅
reactors25✅ / ✅✅ / ✅✅ / ✅1875 / 1835✅ / ✅✅ / ✅

@rkennkerkennke 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.

Looks good to me. Thank you!

@zhengyu123

Copy link
Copy Markdown
ContributorAuthor

Looks good to me. Thank you!

@rkennke Thank you for reviewing.

Comment threadddprof-lib/src/main/cpp/jvmThread.cpp Outdated
Comment threadddprof-lib/src/main/cpp/profiler.cpp Outdated
Comment threadddprof-lib/src/main/cpp/vmEntry.cpp Outdated

@jbachorikjbachorik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few minor/clarifying comments. Otherwise good to go.

@zhengyu123
zhengyu123 merged commit 3869f88 into mainJul 6, 2026
537 of 558 checks passed
@zhengyu123
zhengyu123 deleted the zgu/objmonitor_deflation branch July 6, 2026 23:14
@github-actionsgithub-actionsBot added this to the 1.47.0 milestone Jul 6, 2026
CopilotAI added a commit that referenced this pull request Jul 9, 2026
…from deleted thread.h to threadLocalData.h
PR #615 (origin/main) renamed thread.cpp to threadLocalData.cpp and deleted
thread.h, absorbing ProfiledThread into threadLocalData.h. Our branch had
modified thread.h to add per-thread JFR-inflight tracking.
Resolution:
- Delete thread.h (accept deletion from main)
- Port _registry_head/_registry_lock static members to threadLocalData.h
- Port _jfr_inflight/_registry_next instance members to threadLocalData.h
- Port enterJfrInflight/exitJfrInflight/jfrInflight methods to threadLocalData.h
- Port forEachRegistered/registryInsert/registryRemove declarations to threadLocalData.h
- Update signalInflight.cpp to include threadLocalData.h instead of thread.h
- threadLocalData.cpp already has implementation (correctly auto-merged)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@zhengyu123@jbachorik@rkennke@kaahos