|
5 | 5 |
|
6 | 6 | import datadog.trace.agent.tooling.bytebuddy.memoize.MemoizedMatchers; |
7 | 7 | import datadog.trace.api.InstrumenterConfig; |
| 8 | +import datadog.trace.api.Pair; |
8 | 9 | import datadog.trace.bootstrap.ContextStore; |
9 | 10 | import datadog.trace.bootstrap.FieldBackedContextAccessor; |
10 | 11 | import datadog.trace.bootstrap.FieldBackedContextStores; |
@@ -70,7 +71,7 @@ public final class FieldBackedContextInjector implements AsmVisitorWrapper { |
70 | 71 | Type.getType(FieldBackedContextAccessor.class); |
71 | 72 |
|
72 | 73 | /** Keeps track of injection requests for the class being transformed by the current thread. */ |
73 | | - static final ThreadLocal<BitSet> INJECTED_STORE_IDS = new ThreadLocal<>(); |
| 74 | + static final ThreadLocal<Pair<String, BitSet>> INJECTED_STORE_IDS = new ThreadLocal<>(); |
74 | 75 |
|
75 | 76 | final boolean serialVersionUIDFieldInjection = |
76 | 77 | InstrumenterConfig.get().isSerialVersionUIDFieldInjection(); |
@@ -129,7 +130,7 @@ public void visit( |
129 | 130 |
|
130 | 131 | // keep track of all injection requests for the class currently being transformed |
131 | 132 | // because we need to switch between them in the generated getter/putter methods |
132 | | - int storeId = injectContextStore(keyClassName, contextClassName); |
| 133 | + int storeId = injectContextStore(name, keyClassName, contextClassName); |
133 | 134 | storeFieldName = CONTEXT_STORE_ACCESS_PREFIX + storeId; |
134 | 135 |
|
135 | 136 | if (interfaces == null) { |
@@ -484,26 +485,30 @@ private void invokeSuperPut(final MethodVisitor mv, final String superName) { |
484 | 485 | } |
485 | 486 |
|
486 | 487 | /** Requests injection of a context store for a key and context. */ |
487 | | - static int injectContextStore(final String keyClassName, final String contextClassName) { |
| 488 | + static int injectContextStore( |
| 489 | + final String target, final String keyClassName, final String contextClassName) { |
488 | 490 | int storeId = getContextStoreId(keyClassName, contextClassName); |
489 | 491 |
|
490 | | - BitSet injectedStoreIds = INJECTED_STORE_IDS.get(); |
491 | | - if (null == injectedStoreIds) { |
492 | | - injectedStoreIds = new BitSet(); |
| 492 | + // collect a new set of store ids every time we see a new target |
| 493 | + Pair<String, BitSet> injectedStoreIds = INJECTED_STORE_IDS.get(); |
| 494 | + if (null == injectedStoreIds || !target.equals(injectedStoreIds.getLeft())) { |
| 495 | + injectedStoreIds = Pair.of(target, new BitSet()); |
493 | 496 | INJECTED_STORE_IDS.set(injectedStoreIds); |
494 | 497 | } |
495 | | - injectedStoreIds.set(storeId); |
| 498 | + injectedStoreIds.getRight().set(storeId); |
496 | 499 |
|
497 | 500 | return storeId; |
498 | 501 | } |
499 | 502 |
|
500 | 503 | /** Returns all context store injection requests for the class being transformed. */ |
501 | 504 | static BitSet getInjectedContextStores() { |
502 | | - BitSet injectedStoreIds = INJECTED_STORE_IDS.get(); |
| 505 | + Pair<String, BitSet> injectedStoreIds = INJECTED_STORE_IDS.get(); |
503 | 506 | if (null != injectedStoreIds) { |
504 | 507 | INJECTED_STORE_IDS.remove(); |
| 508 | + return injectedStoreIds.getRight(); |
| 509 | + } else { |
| 510 | + return null; |
505 | 511 | } |
506 | | - return injectedStoreIds; |
507 | 512 | } |
508 | 513 |
|
509 | 514 | private static final class SerialVersionUIDInjector |
|
0 commit comments