Using type pool cache only when applying instrumentation for the entire JVM
@@ -303,7 +303,9 @@ public class ElasticApmAgent {
final ByteBuddy byteBuddy = new ByteBuddy()
.with(TypeValidation.of(logger.isDebugEnabled()))
.with(FailSafeDeclaredMethodsCompiler.INSTANCE);
- AgentBuilder agentBuilder = getAgentBuilder(byteBuddy, coreConfiguration, logger, descriptionStrategy, premain);
+ AgentBuilder agentBuilder = getAgentBuilder(
+ byteBuddy, coreConfiguration, logger, descriptionStrategy, premain, coreConfiguration.isTypePoolCacheEnabled()
+ );
int numberOfAdvices = 0;
for (final ElasticApmInstrumentation advice : instrumentations) {
if (isIncluded(advice, coreConfiguration)) {
@@ -588,7 +590,8 @@ public class ElasticApmAgent {
}
private static AgentBuilder getAgentBuilder(final ByteBuddy byteBuddy, final CoreConfiguration coreConfiguration, final Logger logger,
- final AgentBuilder.DescriptionStrategy descriptionStrategy, final boolean premain) {
+ final AgentBuilder.DescriptionStrategy descriptionStrategy, final boolean premain,
+ final boolean useTypePoolCache) {
AgentBuilder.LocationStrategy locationStrategy = AgentBuilder.LocationStrategy.ForClassLoader.WEAK;
if (agentJarFile != null) {
try {
@@ -624,7 +627,7 @@ public class ElasticApmAgent {
.with(locationStrategy)
.with(new ErrorLoggingListener())
// ReaderMode.FAST as we don't need to read method parameter names
- .with(coreConfiguration.isTypePoolCacheEnabled()
+ .with(useTypePoolCache
? new SoftlyReferencingTypePoolCache(TypePool.Default.ReaderMode.FAST, 1, isReflectionClassLoader())
: AgentBuilder.PoolStrategy.Default.FAST)
.ignore(any(), isReflectionClassLoader())
@@ -706,7 +709,9 @@ public class ElasticApmAgent {
final ByteBuddy byteBuddy = new ByteBuddy()
.with(TypeValidation.of(logger.isDebugEnabled()))
.with(FailSafeDeclaredMethodsCompiler.INSTANCE);
- AgentBuilder agentBuilder = getAgentBuilder(byteBuddy, config, logger, AgentBuilder.DescriptionStrategy.Default.HYBRID, false);
+ AgentBuilder agentBuilder = getAgentBuilder(
+ byteBuddy, config, logger, AgentBuilder.DescriptionStrategy.Default.HYBRID, false, false
+ );
for (Class<? extends ElasticApmInstrumentation> instrumentationClass : instrumentationClasses) {
pluginClassLoaderByAdviceClass.put(
instrumentationClass.getName(),
