|
15 | 15 | import java.util.HashMap; |
16 | 16 | import java.util.Map; |
17 | 17 | import java.util.concurrent.ConcurrentHashMap; |
| 18 | +import javax.annotation.Nullable; |
18 | 19 | import net.bytebuddy.agent.builder.AgentBuilder; |
19 | 20 | import net.bytebuddy.utility.JavaModule; |
20 | 21 |
|
@@ -57,16 +58,8 @@ public static InstrumentationModuleClassLoader getInstrumentationClassLoader( |
57 | 58 | InstrumentationModule module, ClassLoader instrumentedClassLoader) { |
58 | 59 |
|
59 | 60 | ClassLoader moduleCl = module.getClass().getClassLoader(); |
60 | | - InstrumentationModuleClassLoader loader = null; |
61 | | - if (!(moduleCl instanceof ExtensionClassLoader)) { |
62 | | - loader = instrumentationClassLoaders.get(instrumentedClassLoader); |
63 | | - } else { |
64 | | - Map<ClassLoader, InstrumentationModuleClassLoader> map = |
65 | | - extensionsInstrumentationClassLoaders.get(moduleCl); |
66 | | - if (map != null) { |
67 | | - loader = map.get(instrumentedClassLoader); |
68 | | - } |
69 | | - } |
| 61 | + InstrumentationModuleClassLoader loader = |
| 62 | + lookupInstrumentationClassLoader(instrumentedClassLoader, moduleCl); |
70 | 63 |
|
71 | 64 | if (loader == null || !loader.hasModuleInstalled(module)) { |
72 | 65 | throw new IllegalArgumentException( |
@@ -97,6 +90,22 @@ public static InstrumentationModuleClassLoader getInstrumentationClassLoader( |
97 | 90 | return loader; |
98 | 91 | } |
99 | 92 |
|
| 93 | + @Nullable |
| 94 | + private static InstrumentationModuleClassLoader lookupInstrumentationClassLoader( |
| 95 | + ClassLoader instrumentedClassLoader, ClassLoader moduleCl) { |
| 96 | + if (!(moduleCl instanceof ExtensionClassLoader)) { |
| 97 | + // internal instrumentation is using one CL per instrumented CL. |
| 98 | + return instrumentationClassLoaders.get(instrumentedClassLoader); |
| 99 | + } |
| 100 | + // extension module needs to use a common CL per extension and instrumented CL. |
| 101 | + Map<ClassLoader, InstrumentationModuleClassLoader> map = |
| 102 | + extensionsInstrumentationClassLoaders.get(moduleCl); |
| 103 | + if (map != null) { |
| 104 | + return map.get(instrumentedClassLoader); |
| 105 | + } |
| 106 | + return null; |
| 107 | + } |
| 108 | + |
100 | 109 | /** |
101 | 110 | * Returns a newly created class loader containing only the provided module. Note that other |
102 | 111 | * modules from the same module group will not be installed in this class loader. |
|
0 commit comments