profiling(ddprof): migrate context bridge to the all-native API (Phase 2)#11899
Draft
rkennke wants to merge 1 commit into
Draft
profiling(ddprof): migrate context bridge to the all-native API (Phase 2)#11899rkennke wants to merge 1 commit into
rkennke wants to merge 1 commit into
Conversation
Switch the profiler context bridge off the deprecated DirectByteBuffer (DBB) context API onto java-profiler's all-native API (setTraceContext / clearTraceContext / setContextValue / clearContextValue). This eliminates the virtual-thread use-after-free (the DBB cached buffer that dangled on carrier migration) and folds the per-activation sequence (setContext + two setContextValue) into a single native call. - DatadogProfilingIntegration.activate: one setTraceContext(...) carrying trace/span context + operation and resource attributes (3 JNI calls -> 1); close/clearContext: clearTraceContext() (wipes op/resource slots too). - DatadogProfiler: setContextValue/clearContextValue/reapplyAppContext/ syncNativeAppContext are now all-native. reapplyAppContext uses a per-slot native setContextValue loop (native setContextValue publishes valid=1, so app context stays visible without an active span — preserves PR #11646). A native batch reapply is deferred to a measured follow-up (java-profiler PROF-15361). - AppContextSnapshot simplified to strings-only (the native path resolves each value's encoding via the process-wide cache; no cached id/utf8/snapshotTags). - snapshot() uses the new native copyContextTags read (no ThreadContext/DBB, so it observes native writes without resetting the record). - ContextSetter kept only for offsetOf + size (pure Java); no DBB usage remains. Requires java-profiler with the all-native API (ddprof >= the phase-1 release; DataDog/java-profiler#631). Build/test with -PddprofUseSnapshot=true against a local publishToMavenLocal 1.47.0-SNAPSHOT until that ships. ddprof suite is Linux-gated (assumeTrue(isLinux)) — verify on Linux/CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Migrates the profiler context bridge off the deprecated DirectByteBuffer (DBB) context API onto java-profiler's all-native API (
setTraceContext/clearTraceContext/setContextValue/clearContextValue).This is Phase 2 of the all-native context work (Phase 1 = DataDog/java-profiler#631).
Why
DirectByteBufferover the native OTEP record; on a carrier that a mounted virtual thread later migrated off, the record was freed while the cached buffer kept being written. The all-native API resolves the current carrier's record inside each JNI call — no cached buffer to dangle.setContext+ 2×setContextValue(3 JNI calls) into onesetTraceContext(~28% faster on the combined cycle per the design-note benchmark).Changes
DatadogProfilingIntegration.activate→ onesetTraceContext(...)carrying trace/span context + operation & resource attributes;close/clearContext→clearTraceContext().DatadogProfiler:setContextValue/clearContextValue/reapplyAppContext/syncNativeAppContextare now all-native.reapplyAppContextuses a per-slot nativesetContextValueloop — nativesetContextValuepublishes the record (valid=1) even with no active span, so app context stays visible between spans (preserves Restore app context attributes wiped by ddprof setContext on span activation #11646). A native batch reapply is deferred to a measured follow-up (java-profiler PROF-15361).AppContextSnapshotsimplified to strings-only (the native path resolves each value's encoding via the process-wide cache — no cached id/utf8/snapshotTagsDBB read).snapshot()uses the new nativecopyContextTagsread (noThreadContext/DBB, so it observes native writes without resetting the record).ContextSetterkept only foroffsetOf+size(pure Java); no DBB usage remains.Dependency / how to build
Requires java-profiler with the all-native API — DataDog/java-profiler#631 (
ddprof≥ the Phase-1 release). Until that ships, build/test against a local snapshot:Status / verification
1.47.0-SNAPSHOT.DatadogProfilerTest, …) is Linux-gated (assumeTrue(isLinux())) and was not run on the author's macOS box — needs Linux/CI to exercise behavior.🤖 Generated with Claude Code