Commit 8930561
profiling(ddprof): migrate context bridge to the all-native API (Phase 2) (#11899)
profiling(ddprof): migrate context bridge to the all-native API
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>
profiling(ddprof): guard zero span in setTraceContext; document clearContextValue
The native setTraceContext rejects spanId==0 with IllegalArgumentException (it is
the activation path; clearing is clearTraceContext). The bridge's catch(Throwable)
would swallow that throw and leave the previous span's context stale on the thread.
Span ids are non-zero by construction (IdGenerationStrategy never yields 0,
DDSpanId.ZERO means "no span", and DDSpanContext is the only ProfilerContext), so
this is defensive: route a zero span to a clean clearTraceContext instead of a
silently-swallowed throw over stale state.
Also document clearContextValue(int)'s return contract (@param/@return) and add a
testContextRegistration scenario asserting a zero-span activation does not throw and
still reapplies app context.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
profiling(ddprof): describe current behavior in comments; drop historical references
Rewrite or remove comments that documented the superseded DirectByteBuffer context
API and the ddprof-version history of the bridge (e.g. "Replaces the previous
setContext...", "no DBB read", the 1.41.0/1.45.0 no-op history in
DatadogProfilingScope). Those explain how the code got here, not what it does now;
the commit history and PRs carry that evolution. Comment-only, behavior unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
profiling(ddprof): fix JMH benchmark for strings-only AppContextSnapshot
AppContextSnapshotBenchmark.setup() still called the old
record(int, int, byte[], String) signature; AppContextSnapshot.record is now
record(int, String) (strings-only, per the all-native context migration).
compileJmhJava was failing in CI.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
profiling(ddprof): fix two reapply ordering bugs found by PR review bots
- setContextValue: a rejected native write (e.g. >255-byte UTF-8) clears the
native slot but left the Java snapshot untouched, so the attribute read as
unset until the next span boundary silently resurrected the stale prior
value. Reapply immediately on rejection so the prior value stays visible
continuously, matching pre-migration DBB behavior.
- setTraceContext: reapplyAppContext() ran unconditionally after the native
call, so when profiling.context.attributes also names
_dd.trace.operation/resource (with span-name/resource-name context
enabled), the trailing reapply clobbered the span-derived value that
setTraceContext just wrote to the same offset with a stale app-recorded
one. reapplyAppContext now takes the operation/resource offsets to skip.
Both were flagged independently by Codex and Datadog Autotest PR review bots
on #11899, with a concrete repro for the first. Added regression coverage to
DatadogProfilerTest#testContextRegistration for both (verified each new
assertion fails without its corresponding fix).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merge branch 'master' into rkennke/profiler-all-native-context-phase2
Rename reapplyAppContext skip-offset params to operationOffset/resourceOffset
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Merge branch 'master' into rkennke/profiler-all-native-context-phase2
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent ca4153b commit 8930561
5 files changed
Lines changed: 211 additions & 111 deletions
File tree
- dd-java-agent/agent-profiling/profiling-ddprof/src
- jmh/java/com/datadog/profiling/ddprof
- main/java/com/datadog/profiling/ddprof
- test/java/com/datadog/profiling/ddprof
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
56 | | - | |
| 54 | + | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
| |||
Lines changed: 127 additions & 91 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
| |||
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
122 | | - | |
123 | | - | |
124 | | - | |
| 121 | + | |
| 122 | + | |
125 | 123 | | |
126 | 124 | | |
127 | 125 | | |
128 | 126 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 127 | | |
139 | 128 | | |
140 | 129 | | |
| |||
170 | 159 | | |
171 | 160 | | |
172 | 161 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
177 | 165 | | |
178 | | - | |
| 166 | + | |
179 | 167 | | |
180 | 168 | | |
181 | 169 | | |
182 | | - | |
183 | | - | |
184 | 170 | | |
185 | 171 | | |
186 | 172 | | |
187 | | - | |
188 | | - | |
| 173 | + | |
| 174 | + | |
189 | 175 | | |
190 | | - | |
| 176 | + | |
191 | 177 | | |
192 | 178 | | |
193 | | - | |
194 | | - | |
195 | 179 | | |
196 | 180 | | |
197 | 181 | | |
198 | 182 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 183 | + | |
202 | 184 | | |
203 | 185 | | |
204 | 186 | | |
| |||
214 | 196 | | |
215 | 197 | | |
216 | 198 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | 199 | | |
226 | | - | |
227 | | - | |
228 | 200 | | |
229 | 201 | | |
230 | 202 | | |
231 | 203 | | |
232 | 204 | | |
233 | | - | |
234 | | - | |
235 | 205 | | |
236 | 206 | | |
237 | 207 | | |
| |||
271 | 241 | | |
272 | 242 | | |
273 | 243 | | |
274 | | - | |
| 244 | + | |
| 245 | + | |
275 | 246 | | |
276 | 247 | | |
277 | 248 | | |
| |||
514 | 485 | | |
515 | 486 | | |
516 | 487 | | |
517 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
518 | 513 | | |
519 | 514 | | |
520 | | - | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
521 | 524 | | |
522 | | - | |
| 525 | + | |
523 | 526 | | |
524 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
525 | 532 | | |
526 | 533 | | |
527 | | - | |
| 534 | + | |
| 535 | + | |
528 | 536 | | |
529 | 537 | | |
530 | | - | |
| 538 | + | |
531 | 539 | | |
532 | | - | |
| 540 | + | |
533 | 541 | | |
534 | 542 | | |
535 | 543 | | |
536 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
537 | 553 | | |
538 | | - | |
| 554 | + | |
539 | 555 | | |
540 | 556 | | |
541 | 557 | | |
542 | | - | |
| 558 | + | |
543 | 559 | | |
544 | 560 | | |
545 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
546 | 566 | | |
547 | 567 | | |
548 | 568 | | |
| |||
564 | 584 | | |
565 | 585 | | |
566 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
567 | 598 | | |
568 | | - | |
| 599 | + | |
569 | 600 | | |
570 | 601 | | |
571 | 602 | | |
572 | | - | |
| 603 | + | |
573 | 604 | | |
574 | | - | |
| 605 | + | |
575 | 606 | | |
576 | 607 | | |
577 | 608 | | |
| |||
581 | 612 | | |
582 | 613 | | |
583 | 614 | | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
592 | 620 | | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
597 | 624 | | |
598 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
599 | 636 | | |
600 | 637 | | |
601 | 638 | | |
| |||
604 | 641 | | |
605 | 642 | | |
606 | 643 | | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
617 | 653 | | |
618 | 654 | | |
619 | 655 | | |
| |||
625 | 661 | | |
626 | 662 | | |
627 | 663 | | |
628 | | - | |
629 | 664 | | |
630 | 665 | | |
631 | 666 | | |
| |||
637 | 672 | | |
638 | 673 | | |
639 | 674 | | |
640 | | - | |
| 675 | + | |
641 | 676 | | |
642 | 677 | | |
643 | 678 | | |
| |||
648 | 683 | | |
649 | 684 | | |
650 | 685 | | |
651 | | - | |
| 686 | + | |
652 | 687 | | |
653 | | - | |
| 688 | + | |
654 | 689 | | |
655 | 690 | | |
656 | 691 | | |
| |||
719 | 754 | | |
720 | 755 | | |
721 | 756 | | |
| 757 | + | |
| 758 | + | |
722 | 759 | | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
| 760 | + | |
729 | 761 | | |
730 | 762 | | |
731 | 763 | | |
| |||
736 | 768 | | |
737 | 769 | | |
738 | 770 | | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
743 | 779 | | |
744 | 780 | | |
745 | 781 | | |
| |||
0 commit comments