diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java index 871cbbb759d44f634670b616127f5dbb20bc11ea..b0fab5fe3b2489a2e15ad729fbcbc6bbff790242 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java @@ -202,7 +202,7 @@ public class TracingContext implements AbstractTracerContext { final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); if (parentSpan == null) { entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() - .find(segment.getApplicationId(), operationName) + .findOnly(segment.getApplicationId(), operationName) .doInCondition(new PossibleFound.FoundAndObtain() { @Override public Object doProcess(int operationId) { return new EntrySpan(spanIdGenerator++, parentSpanId, operationId); @@ -216,7 +216,7 @@ public class TracingContext implements AbstractTracerContext { return push(entrySpan); } else if (parentSpan.isEntry()) { entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() - .find(segment.getApplicationId(), operationName) + .findOnly(segment.getApplicationId(), operationName) .doInCondition(new PossibleFound.FoundAndObtain() { @Override public Object doProcess(int operationId) { return parentSpan.setOperationId(operationId); @@ -244,7 +244,7 @@ public class TracingContext implements AbstractTracerContext { AbstractTracingSpan parentSpan = peek(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() - .find(segment.getApplicationId(), operationName) + .findOrPrepare4Register(segment.getApplicationId(), operationName) .doInCondition(new PossibleFound.FoundAndObtain() { @Override public Object doProcess(int operationId) { @@ -282,7 +282,7 @@ public class TracingContext implements AbstractTracerContext { @Override public Object doProcess(final int applicationId) { return DictionaryManager.findOperationNameCodeSection() - .find(applicationId, operationName) + .findOrPrepare4Register(applicationId, operationName) .doInCondition( new PossibleFound.FoundAndObtain() { @Override diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java index 852b67a04dced6f8447beedde7544228642b32c6..4b2d69cfc6c56299a430c514886526b789d1ff09 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java @@ -1,6 +1,8 @@ package org.skywalking.apm.agent.core.context.trace; +import org.skywalking.apm.agent.core.dictionary.DictionaryManager; import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; +import org.skywalking.apm.agent.core.dictionary.PossibleFound; import org.skywalking.apm.network.trace.component.Component; /** @@ -82,6 +84,22 @@ public class EntrySpan extends AbstractTracingSpan { @Override public boolean finish(TraceSegment owner) { if (--stackDepth == 0) { + if (this.operationId == DictionaryUtil.nullValue()) { + this.operationId = (Integer)DictionaryManager.findOperationNameCodeSection() + .findOrPrepare4Register(owner.getApplicationId(), operationName) + .doInCondition( + new PossibleFound.FoundAndObtain() { + @Override public Object doProcess(int value) { + return value; + } + }, + new PossibleFound.NotFoundAndObtain() { + @Override public Object doProcess() { + return DictionaryUtil.nullValue(); + } + } + ); + } return super.finish(owner); } else { return false; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java index 2abd18cb523b1bf95b77945f2e9b156a73a52584..1e06333f6bcf0094f551f67561948affbc30254c 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/dictionary/OperationNameDictionary.java @@ -20,7 +20,15 @@ public enum OperationNameDictionary { private Map operationNameDictionary = new ConcurrentHashMap(); private Set unRegisterOperationNames = new ConcurrentSet(); - public PossibleFound find(int applicationId, String operationName) { + public PossibleFound findOrPrepare4Register(int applicationId, String operationName) { + return find0(applicationId, operationName, true); + } + + public PossibleFound findOnly(int applicationId, String operationName) { + return find0(applicationId, operationName, false); + } + + private PossibleFound find0(int applicationId, String operationName, boolean registerWhenNotFound) { if (operationName == null || operationName.length() == 0) { return new NotFound(); } @@ -29,7 +37,8 @@ public enum OperationNameDictionary { if (operationId != null) { return new Found(applicationId); } else { - if (operationNameDictionary.size() + unRegisterOperationNames.size() < OPERATION_NAME_BUFFER_SIZE) { + if (registerWhenNotFound && + operationNameDictionary.size() + unRegisterOperationNames.size() < OPERATION_NAME_BUFFER_SIZE) { unRegisterOperationNames.add(key); } return new NotFound(); diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java index 87bfae3ed3d3a17ba4befec60b1bb5dd1edad502..29cafff54e5879193e7a9cbe95daafd209eb3e1b 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/AbstractClassEnhancePluginDefine.java @@ -37,7 +37,7 @@ public abstract class AbstractClassEnhancePluginDefine { logger.debug("prepare to enhance class {} by {}.", transformClassName, interceptorDefineClassName); /** - * find witness classes for enhance class + * findOrPrepare4Register witness classes for enhance class */ String[] witnessClasses = witnessClasses(); if (witnessClasses != null) { @@ -51,7 +51,7 @@ public abstract class AbstractClassEnhancePluginDefine { } /** - * find origin class source code for interceptor + * findOrPrepare4Register origin class source code for interceptor */ DynamicType.Builder newClassBuilder = this.enhance(transformClassName, builder, classLoader); diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java index 271b32cee500ab8fce48b4b36d364dbc93c30d0b..4adaaaa6d323c278658d19cba5a36da415f55cc7 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginFinder.java @@ -16,7 +16,7 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.not; /** - * The PluginFinder represents a finder , which assist to find the one + * The PluginFinder represents a finder , which assist to findOrPrepare4Register the one * from the given {@link AbstractClassEnhancePluginDefine} list. * * @author wusheng diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java index 34e56e93f9814ceab00cb19218c9a9d8914c147d..84c2955a7d92109c81f4645302b0a69f5f893db0 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginResourcesResolver.java @@ -27,7 +27,7 @@ public class PluginResourcesResolver { while (urls.hasMoreElements()) { URL pluginUrl = urls.nextElement(); cfgUrlPaths.add(pluginUrl); - logger.info("find skywalking plugin define in {}", pluginUrl); + logger.info("findOrPrepare4Register skywalking plugin define in {}", pluginUrl); } return cfgUrlPaths; @@ -42,7 +42,7 @@ public class PluginResourcesResolver { * First get current thread's classloader, * if fail, get {@link PluginResourcesResolver}'s classloader. * - * @return the classloader to find plugin definitions. + * @return the classloader to findOrPrepare4Register plugin definitions. */ private ClassLoader getDefaultClassLoader() { ClassLoader cl = null;