Adopt ThreadLocal to store ProfiledThread#639
Conversation
There was a problem hiding this comment.
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’spthread_key_tTLS plumbing withThreadLocal<ProfiledThread*>and adjust initialization APIs accordingly. - Add
Profiler::init()and call it fromJavaProfiler_init0()to initialize native state earlier. - Update JVM support initialization to also validate the
ProfiledThreadTLS 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.
|
CI Test ResultsRun: #28904774596 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Failed Testsglibc-amd64/debug / 11-j9Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 17-j9Job: 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 |
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 |
What does this PR do?:
Motivation:
Additional Notes:
How to test the change?:
For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.Unsure? Have a question? Request a review!