Skip to content

Adopt ThreadLocal to store ProfiledThread#639

Draft
zhengyu123 wants to merge 2 commits into
mainfrom
zgu/profiled_thread
Draft

Adopt ThreadLocal to store ProfiledThread#639
zhengyu123 wants to merge 2 commits into
mainfrom
zgu/profiled_thread

Conversation

@zhengyu123

Copy link
Copy Markdown
Contributor

What does this PR do?:

Motivation:

Additional Notes:

How to test the change?:

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!

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 migrates ProfiledThread storage from a raw pthread_key_t TLS implementation to the project’s ThreadLocal<> wrapper, and wires up an explicit native initialization path so per-thread profiler metadata can be established earlier and more predictably.

Changes:

  • Replace ProfiledThread’s pthread_key_t TLS plumbing with ThreadLocal<ProfiledThread*> and adjust initialization APIs accordingly.
  • Add Profiler::init() and call it from JavaProfiler_init0() to initialize native state earlier.
  • Update JVM support initialization to also validate the ProfiledThread TLS key.

Reviewed changes

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

Show a summary per file
File Description
ddprof-lib/src/test/cpp/ddprof_ut.cpp Updates unit test to use the new initCurrentThread() return value.
ddprof-lib/src/main/cpp/threadLocalData.h Switches ProfiledThread to ThreadLocal<> and adjusts initialization/lookup API surface.
ddprof-lib/src/main/cpp/threadLocalData.cpp Implements the new ThreadLocal<>-backed ProfiledThread initialization and teardown logic.
ddprof-lib/src/main/cpp/profiler.h Adds Profiler::init() to the public interface.
ddprof-lib/src/main/cpp/profiler.cpp Implements Profiler::init() and uses initCurrentThread() where needed.
ddprof-lib/src/main/cpp/jvmSupport.cpp Treats ProfiledThread TLS key validity as part of JVM support initialization readiness.
ddprof-lib/src/main/cpp/javaApi.cpp Calls Profiler::init() from JNI init and updates several JNI entry points to use the new thread initialization behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ddprof-lib/src/main/cpp/threadLocalData.cpp
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp Outdated
Comment thread ddprof-lib/src/main/cpp/threadLocalData.h Outdated
@datadog-official

datadog-official Bot commented Jul 7, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 8 Pipeline jobs failed

CI Run | test-matrix / test-linux-glibc-amd64 (11-j9, debug)   View in Datadog   GitHub Actions

CI Run | test-matrix / test-linux-glibc-amd64 (17-j9, debug)   View in Datadog   GitHub Actions

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

View all 8 failed jobs.

Useful? React with 👍 / 👎

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

@dd-octo-sts

dd-octo-sts Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #28904774596 | Commit: f7c6db4 | Duration: 13m 43s (longest job)

2 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.

glibc-amd64/debug / 17-j9

Job: View logs

No detailed failure information available. Check the job logs.

Summary: Total: 32 | Passed: 30 | Failed: 2


Updated: 2026-07-07 23:21:20 UTC

@dd-octo-sts

dd-octo-sts Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

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

❌ chaos: profiler gmalloc amd64 21 0 3 temXchaos
Chaos harness crashed (RC=124)

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