33import static datadog .trace .bootstrap .FieldBackedContextStores .getContextStoreId ;
44import static datadog .trace .util .Strings .getInternalName ;
55
6+ import datadog .instrument .fieldinject .KeyWithValue ;
67import datadog .instrument .fieldinject .ObjectStoreDispatch ;
78import datadog .trace .agent .tooling .bytebuddy .memoize .MemoizedMatchers ;
89import datadog .trace .api .InstrumenterConfig ;
910import datadog .trace .api .Pair ;
1011import datadog .trace .bootstrap .ContextStore ;
11- import datadog .trace .bootstrap .FieldBackedContextAccessor ;
1212import datadog .trace .bootstrap .WeakMapPerStore ;
1313import java .io .Serializable ;
1414import java .util .Arrays ;
@@ -36,16 +36,15 @@ public final class FieldBackedContextInjector implements AsmVisitorWrapper {
3636
3737 private static final Logger log = LoggerFactory .getLogger (FieldBackedContextInjector .class );
3838
39- static final String FIELD_BACKED_CONTEXT_ACCESSOR_CLASS =
40- getInternalName (FieldBackedContextAccessor .class .getName ());
39+ static final String KEY_WITH_VALUE_CLASS = getInternalName (KeyWithValue .class .getName ());
4140
42- static final String CONTEXT_STORE_ACCESS_PREFIX = "__datadogContext$" ;
41+ static final String CONTEXT_STORE_FIELD_PREFIX = "__datadogContext$" ;
4342
44- static final String GETTER_METHOD = "$get$" + CONTEXT_STORE_ACCESS_PREFIX ;
43+ static final String GETTER_METHOD = "$get$__dd_instrument$" ;
4544 static final String GETTER_METHOD_DESCRIPTOR =
4645 Type .getMethodDescriptor (Type .getType (Object .class ), Type .INT_TYPE );
4746
48- static final String PUTTER_METHOD = "$put$" + CONTEXT_STORE_ACCESS_PREFIX ;
47+ static final String PUTTER_METHOD = "$put$__dd_instrument$" ;
4948 static final String PUTTER_METHOD_DESCRIPTOR =
5049 Type .getMethodDescriptor (Type .VOID_TYPE , Type .INT_TYPE , Type .getType (Object .class ));
5150
@@ -70,8 +69,7 @@ public final class FieldBackedContextInjector implements AsmVisitorWrapper {
7069
7170 static final String OBJECT_DESCRIPTOR = Type .getDescriptor (Object .class );
7271
73- public static final Type EXPECTED_SUPER_STORE_TYPE =
74- Type .getType (FieldBackedContextAccessor .class );
72+ public static final Type EXPECTED_SUPER_STORE_TYPE = Type .getType (KeyWithValue .class );
7573
7674 /** Keeps track of injection requests for the class being transformed by the current thread. */
7775 static final ThreadLocal <Pair <String , BitSet >> INJECTED_STORE_IDS = new ThreadLocal <>();
@@ -134,25 +132,25 @@ public void visit(
134132 // keep track of all injection requests for the class currently being transformed
135133 // because we need to switch between them in the generated getter/putter methods
136134 int storeId = injectContextStore (name , keyClassName , contextClassName );
137- storeFieldName = CONTEXT_STORE_ACCESS_PREFIX + storeId ;
135+ storeFieldName = CONTEXT_STORE_FIELD_PREFIX + storeId ;
138136
139137 if (interfaces == null ) {
140138 interfaces = new String [] {};
141139 }
142140
143- if (!Arrays .asList (interfaces ).contains (FIELD_BACKED_CONTEXT_ACCESSOR_CLASS )) {
141+ if (!Arrays .asList (interfaces ).contains (KEY_WITH_VALUE_CLASS )) {
144142 if (serialVersionUIDFieldInjection
145143 && instrumentedType .isAssignableTo (Serializable .class )) {
146144 serialVersionUIDInjector = new SerialVersionUIDInjector ();
147145 serialVersionUIDInjector .visit (version , access , name , signature , superName , interfaces );
148146 }
149147
150148 if (signature != null ) {
151- signature += 'L' + FIELD_BACKED_CONTEXT_ACCESSOR_CLASS + ';' ;
149+ signature += 'L' + KEY_WITH_VALUE_CLASS + ';' ;
152150 }
153151
154152 interfaces = Arrays .copyOf (interfaces , interfaces .length + 1 );
155- interfaces [interfaces .length - 1 ] = FIELD_BACKED_CONTEXT_ACCESSOR_CLASS ;
153+ interfaces [interfaces .length - 1 ] = KEY_WITH_VALUE_CLASS ;
156154 }
157155
158156 super .visit (version , access , name , signature , superName , interfaces );
@@ -165,7 +163,7 @@ public FieldVisitor visitField(
165163 final String descriptor ,
166164 final String signature ,
167165 final Object value ) {
168- if (name .startsWith (CONTEXT_STORE_ACCESS_PREFIX )) {
166+ if (name .startsWith (CONTEXT_STORE_FIELD_PREFIX )) {
169167 if (storeFieldName .equals (name )) {
170168 foundField = true ;
171169 }
@@ -426,7 +424,7 @@ private void getStoreField(
426424 mv .visitFieldInsn (
427425 Opcodes .GETFIELD ,
428426 instrumentedName ,
429- CONTEXT_STORE_ACCESS_PREFIX + injectedStoreId ,
427+ CONTEXT_STORE_FIELD_PREFIX + injectedStoreId ,
430428 OBJECT_DESCRIPTOR );
431429 mv .visitInsn (Opcodes .ARETURN );
432430 }
@@ -438,7 +436,7 @@ private void putStoreField(
438436 mv .visitFieldInsn (
439437 Opcodes .PUTFIELD ,
440438 instrumentedName ,
441- CONTEXT_STORE_ACCESS_PREFIX + injectedStoreId ,
439+ CONTEXT_STORE_FIELD_PREFIX + injectedStoreId ,
442440 OBJECT_DESCRIPTOR );
443441 mv .visitInsn (Opcodes .RETURN );
444442 }
0 commit comments