11package datadog .trace .instrumentation .java .lang .jdk21 ;
22
33import static datadog .trace .agent .tooling .bytebuddy .matcher .NameMatchers .named ;
4- import static datadog .trace .agent .tooling .bytebuddy .matcher .NameMatchers .namedOneOf ;
54import static datadog .trace .bootstrap .instrumentation .api .AgentTracer .activeSpan ;
65import static datadog .trace .bootstrap .instrumentation .java .concurrent .ConcurrentState .activateAndContinueContinuation ;
76import static datadog .trace .bootstrap .instrumentation .java .concurrent .ConcurrentState .captureContinuation ;
1312import static java .util .Collections .singletonMap ;
1413import static net .bytebuddy .matcher .ElementMatchers .isConstructor ;
1514import static net .bytebuddy .matcher .ElementMatchers .isMethod ;
15+ import static net .bytebuddy .matcher .ElementMatchers .takesArguments ;
1616
1717import com .google .auto .service .AutoService ;
1818import datadog .environment .JavaVirtualMachine ;
4444 * carrier thread.
4545 * <li>{@code unmount()}: closes the scope. The continuation survives as still hold.
4646 * <li>Steps 2-3 repeat on each park/unpark cycle, potentially on different carrier threads.
47- * <li>{@code afterTerminate()} (for early versions of JDK 21 and 22 before GA), {@code afterDone}
48- * (for JDK 21 GA above): cancels the held continuation to let the context scope to be closed.
47+ * <li>{@code afterDone}: cancels the held continuation to let the context scope to be closed.
4948 * </ol>
5049 *
5150 * <p>The instrumentation uses two context stores. The first from {@link Runnable} (as {@code
@@ -105,24 +104,24 @@ public Map<String, String> contextStore() {
105104 @ Override
106105 public void methodAdvice (MethodTransformer transformer ) {
107106 transformer .applyAdvice (isConstructor (), getClass ().getName () + "$Construct" );
108- transformer .applyAdvice (isMethod ().and (named ("mount" )), getClass ().getName () + "$Activate " );
109- transformer .applyAdvice (isMethod ().and (named ("unmount" )), getClass ().getName () + "$Close " );
107+ transformer .applyAdvice (isMethod ().and (named ("mount" )), getClass ().getName () + "$Mount " );
108+ transformer .applyAdvice (isMethod ().and (named ("unmount" )), getClass ().getName () + "$Unmount " );
110109 transformer .applyAdvice (
111- isMethod ().and (namedOneOf ( "afterTerminate" , " afterDone" )),
112- getClass ().getName () + "$Terminate " );
110+ isMethod ().and (named ( " afterDone")). and ( takesArguments ( boolean . class )),
111+ getClass ().getName () + "$AfterDone " );
113112 }
114113
115114 public static final class Construct {
116115 @ OnMethodExit (suppress = Throwable .class )
117- public static void captureScope (@ Advice .This Object virtualThread ) {
116+ public static void capture (@ Advice .This Object virtualThread ) {
118117 captureContinuation (
119118 InstrumentationContext .get (Runnable .class , ConcurrentState .class ),
120119 (Runnable ) virtualThread ,
121120 activeSpan ());
122121 }
123122 }
124123
125- public static final class Activate {
124+ public static final class Mount {
126125 @ OnMethodExit (suppress = Throwable .class )
127126 public static void activate (@ Advice .This Object virtualThread ) {
128127 AgentScope scope =
@@ -135,7 +134,7 @@ public static void activate(@Advice.This Object virtualThread) {
135134 }
136135 }
137136
138- public static final class Close {
137+ public static final class Unmount {
139138 @ OnMethodEnter (suppress = Throwable .class )
140139 public static void close (@ Advice .This Object virtualThread ) {
141140 ContextStore <Object , AgentScope > scopeStore =
@@ -149,9 +148,9 @@ public static void close(@Advice.This Object virtualThread) {
149148 }
150149 }
151150
152- public static final class Terminate {
151+ public static final class AfterDone {
153152 @ OnMethodEnter (suppress = Throwable .class )
154- public static void terminate (@ Advice .This Object virtualThread ) {
153+ public static void clear (@ Advice .This Object virtualThread ) {
155154 ConcurrentState .cancelAndClearContinuation (
156155 InstrumentationContext .get (Runnable .class , ConcurrentState .class ),
157156 (Runnable ) virtualThread );
0 commit comments