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: #28894744365 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Failed Testsmusl-aarch64/debug / 11-librcaJob: View logs No detailed failure information available. Check the job logs. musl-amd64/debug / 21-librcaJob: View logs No detailed failure information available. Check the job logs. musl-amd64/debug / 25-librcaJob: View logs No detailed failure information available. Check the job logs. musl-aarch64/debug / 8-librcaJob: View logs No detailed failure information available. Check the job logs. musl-amd64/debug / 11-librcaJob: View logs No detailed failure information available. Check the job logs. musl-aarch64/debug / 25-librcaJob: View logs No detailed failure information available. Check the job logs. musl-amd64/debug / 17-librcaJob: View logs No detailed failure information available. Check the job logs. musl-amd64/debug / 8-librcaJob: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 8-ibmJob: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 21-graalJob: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 11-j9Job: View logs No detailed failure information available. Check the job logs. musl-aarch64/debug / 17-librcaJob: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 21Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 17-graalJob: 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. glibc-amd64/debug / 8-j9Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 11Job: View logs No detailed failure information available. Check the job logs. musl-aarch64/debug / 21-librcaJob: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 25Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 8-orclJob: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 17Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 17Job: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 21-graalJob: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 25-graalJob: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 25Job: View logs No detailed failure information available. Check the job logs. glibc-amd64/debug / 25-graalJob: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 21Job: View logs No detailed failure information available. Check the job logs. glibc-aarch64/debug / 17-graalJob: View logs No detailed failure information available. Check the job logs. Summary: Total: 32 | Passed: 3 | Failed: 29 Updated: 2026-07-07 20:27:31 UTC |
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!