This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new d66f775 Remove javassist from agent dependency (#3176)
d66f775 is described below
commit d66f775fe5ca14fc8693f8dbfe9ec1ccf35633fc
Author: 吴晟 Wu Sheng <[email protected]>
AuthorDate: Sun Jul 28 23:33:48 2019 +0800
Remove javassist from agent dependency (#3176)
* Remove javassist dependency
* Finish the PR.
* Change doc title level.
* Remove the duplicated codes.
---
apm-sniffer/apm-agent-core/pom.xml | 15 ------
.../core/plugin}/InstrumentDebuggingClass.java | 10 ++--
.../plugin/bootstrap/BootstrapInstrumentBoost.java | 57 +++++++++++++---------
apm-sniffer/apm-agent/pom.xml | 1 -
.../skywalking/apm/agent/SkyWalkingAgent.java | 3 +-
docs/en/setup/service-agent/java-agent/README.md | 2 +-
6 files changed, 43 insertions(+), 45 deletions(-)
diff --git a/apm-sniffer/apm-agent-core/pom.xml
b/apm-sniffer/apm-agent-core/pom.xml
index 4cedde0..575d7fa 100644
--- a/apm-sniffer/apm-agent-core/pom.xml
+++ b/apm-sniffer/apm-agent-core/pom.xml
@@ -38,10 +38,6 @@
<grpc.version>1.14.0</grpc.version>
<guava.version>20.0</guava.version>
<bytebuddy.version>1.9.2</bytebuddy.version>
- <!-- 3.21.0-GA is the last version w/ JDK 6 supported -->
- <!-- We can't update this, unless JDK 6 agent is not supported. -->
- <!-- ref discussion,
https://github.com/jboss-javassist/javassist/issues/268 -->
- <javaassist.version>3.21.0-GA</javaassist.version>
<disruptor.version>3.3.6</disruptor.version>
<wiremock.version>2.6.0</wiremock.version>
<netty-tcnative-boringssl-static.version>2.0.7.Final</netty-tcnative-boringssl-static.version>
@@ -58,8 +54,6 @@
<shade.io.netty.target>${shade.package}.${shade.io.netty.source}</shade.io.netty.target>
<shade.io.opencensus.source>io.opencensus</shade.io.opencensus.source>
<shade.io.opencensus.target>${shade.package}.${shade.io.opencensus.source}</shade.io.opencensus.target>
- <shade.javaassist.source>javassist</shade.javaassist.source>
-
<shade.javaassist.target>${shade.package}.${shade.javaassist.source}</shade.javaassist.target>
<ststem-rules.version>1.18.0</ststem-rules.version>
</properties>
@@ -105,11 +99,6 @@
<version>${netty-tcnative-boringssl-static.version}</version>
</dependency>
<dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>${javaassist.version}</version>
- </dependency>
- <dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>${bytebuddy.version}</version>
@@ -193,10 +182,6 @@
</artifactSet>
<relocations>
<relocation>
-
<pattern>${shade.javaassist.source}</pattern>
-
<shadedPattern>${shade.javaassist.target}</shadedPattern>
- </relocation>
- <relocation>
<pattern>${shade.com.lmax.disruptor.source}</pattern>
<shadedPattern>${shade.com.lmax.disruptor.target}</shadedPattern>
</relocation>
diff --git
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/InstrumentDebuggingClass.java
similarity index 89%
rename from
apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java
rename to
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/InstrumentDebuggingClass.java
index acb2711..bbf2b75 100644
---
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/InstrumentDebuggingClass.java
+++
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/InstrumentDebuggingClass.java
@@ -17,11 +17,10 @@
*/
-package org.apache.skywalking.apm.agent;
+package org.apache.skywalking.apm.agent.core.plugin;
import java.io.File;
import java.io.IOException;
-import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
@@ -30,6 +29,9 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
/**
+ * The manipulated class output. Write the dynamic classes to the `debugging`
folder, when we need to do some debug and
+ * recheck.
+ *
* @author wu-sheng
*/
public enum InstrumentDebuggingClass {
@@ -38,7 +40,7 @@ public enum InstrumentDebuggingClass {
private static final ILog logger =
LogManager.getLogger(InstrumentDebuggingClass.class);
private File debuggingClassesRootPath;
- public void log(TypeDescription typeDescription, DynamicType dynamicType) {
+ public void log(DynamicType dynamicType) {
if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) {
return;
}
@@ -62,7 +64,7 @@ public enum InstrumentDebuggingClass {
try {
dynamicType.saveIn(debuggingClassesRootPath);
} catch (IOException e) {
- logger.error(e, "Can't save class {} to file." +
typeDescription.getActualName());
+ logger.error(e, "Can't save class {} to file." +
dynamicType.getTypeDescription().getActualName());
}
} catch (Throwable t) {
logger.error(t, "Save debugging classes fail.");
diff --git
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java
index c1dda6d..6e12d9d 100644
---
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java
+++
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapInstrumentBoost.java
@@ -26,16 +26,19 @@ import java.lang.instrument.Instrumentation;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
+import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.dynamic.ClassFileLocator;
+import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassInjector;
+import net.bytebuddy.pool.TypePool;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import
org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
+import org.apache.skywalking.apm.agent.core.plugin.InstrumentDebuggingClass;
import org.apache.skywalking.apm.agent.core.plugin.PluginException;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
@@ -43,6 +46,8 @@ import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
/**
* If there is Bootstrap instrumentation plugin declared in plugin list,
BootstrapInstrumentBoost inject the necessary
* classes into bootstrap class loader, including generated dynamic delegate
classes.
@@ -51,6 +56,7 @@ import
org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;
*/
public class BootstrapInstrumentBoost {
private static final ILog logger =
LogManager.getLogger(BootstrapInstrumentBoost.class);
+ private static final String SHADE_PACKAGE =
"org.apache.skywalking.apm.dependencies.";
private static final String[] HIGH_PRIORITY_CLASSES = {
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance",
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.BootstrapInterRuntimeAssist",
@@ -59,7 +65,14 @@ public class BootstrapInstrumentBoost {
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor",
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult",
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.OverrideCallable",
- "org.apache.skywalking.apm.agent.core.plugin.bootstrap.IBootstrapLog"
+ "org.apache.skywalking.apm.agent.core.plugin.bootstrap.IBootstrapLog",
+ SHADE_PACKAGE +
"net.bytebuddy.implementation.bind.annotation.RuntimeType",
+ SHADE_PACKAGE + "net.bytebuddy.implementation.bind.annotation.This",
+ SHADE_PACKAGE +
"net.bytebuddy.implementation.bind.annotation.AllArguments",
+ SHADE_PACKAGE +
"net.bytebuddy.implementation.bind.annotation.AllArguments$Assignment",
+ SHADE_PACKAGE +
"net.bytebuddy.implementation.bind.annotation.SuperCall",
+ SHADE_PACKAGE + "net.bytebuddy.implementation.bind.annotation.Origin",
+ SHADE_PACKAGE + "net.bytebuddy.implementation.bind.annotation.Morph"
};
private static String INSTANCE_METHOD_DELEGATE_TEMPLATE =
"org.apache.skywalking.apm.agent.core.plugin.bootstrap.template.InstanceMethodInterTemplate";
private static String INSTANCE_METHOD_WITH_OVERRIDE_ARGS_DELEGATE_TEMPLATE
=
"org.apache.skywalking.apm.agent.core.plugin.bootstrap.template.InstanceMethodInterWithOverrideArgsTemplate";
@@ -128,26 +141,26 @@ public class BootstrapInstrumentBoost {
*/
private static boolean prepareJREInstrumentation(PluginFinder pluginFinder,
Map<String, byte[]> classesTypeMap) throws PluginException {
- ClassPool classPool = ClassPool.getDefault();
+ TypePool typePool =
TypePool.Default.of(BootstrapInstrumentBoost.class.getClassLoader());
List<AbstractClassEnhancePluginDefine> bootstrapClassMatchDefines =
pluginFinder.getBootstrapClassMatchDefine();
for (AbstractClassEnhancePluginDefine define :
bootstrapClassMatchDefines) {
for (InstanceMethodsInterceptPoint point :
define.getInstanceMethodsInterceptPoints()) {
if (point.isOverrideArgs()) {
- generateDelegator(classesTypeMap, classPool,
INSTANCE_METHOD_WITH_OVERRIDE_ARGS_DELEGATE_TEMPLATE,
point.getMethodsInterceptor());
+ generateDelegator(classesTypeMap, typePool,
INSTANCE_METHOD_WITH_OVERRIDE_ARGS_DELEGATE_TEMPLATE,
point.getMethodsInterceptor());
} else {
- generateDelegator(classesTypeMap, classPool,
INSTANCE_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor());
+ generateDelegator(classesTypeMap, typePool,
INSTANCE_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor());
}
}
for (ConstructorInterceptPoint point :
define.getConstructorsInterceptPoints()) {
- generateDelegator(classesTypeMap, classPool,
CONSTRUCTOR_DELEGATE_TEMPLATE, point.getConstructorInterceptor());
+ generateDelegator(classesTypeMap, typePool,
CONSTRUCTOR_DELEGATE_TEMPLATE, point.getConstructorInterceptor());
}
for (StaticMethodsInterceptPoint point :
define.getStaticMethodsInterceptPoints()) {
if (point.isOverrideArgs()) {
- generateDelegator(classesTypeMap, classPool,
STATIC_METHOD_WITH_OVERRIDE_ARGS_DELEGATE_TEMPLATE,
point.getMethodsInterceptor());
+ generateDelegator(classesTypeMap, typePool,
STATIC_METHOD_WITH_OVERRIDE_ARGS_DELEGATE_TEMPLATE,
point.getMethodsInterceptor());
} else {
- generateDelegator(classesTypeMap, classPool,
STATIC_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor());
+ generateDelegator(classesTypeMap, typePool,
STATIC_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor());
}
}
}
@@ -160,29 +173,27 @@ public class BootstrapInstrumentBoost {
* One key step to avoid class confliction between AppClassLoader and
BootstrapClassLoader
*
* @param classesTypeMap hosts injected binary of generated class
- * @param classPool to generate new class
+ * @param typePool to generate new class
* @param templateClassName represents the class as template in this
generation process. The templates are
* pre-defined in SkyWalking agent core.
* @param methodsInterceptor
*/
- private static void generateDelegator(Map<String, byte[]> classesTypeMap,
ClassPool classPool,
+ private static void generateDelegator(Map<String, byte[]> classesTypeMap,
TypePool typePool,
String templateClassName, String methodsInterceptor) {
String internalInterceptorName = internalDelegate(methodsInterceptor);
try {
- CtClass interClass = classPool.get(templateClassName);
- interClass.setName(internalInterceptorName);
-
- CtField interceptorDefine =
interClass.getField("TARGET_INTERCEPTOR");
- interClass.removeField(interceptorDefine);
-
- interceptorDefine = CtField.make("private static String
TARGET_INTERCEPTOR = \"" + methodsInterceptor + "\";", interClass);
- interClass.addField(interceptorDefine);
+ TypeDescription templateTypeDescription =
typePool.describe(templateClassName)
+ .resolve();
- byte[] bytes = interClass.toBytecode();
+ DynamicType.Unloaded interceptorType = new ByteBuddy()
+ .redefine(templateTypeDescription,
ClassFileLocator.ForClassLoader.of(BootstrapInstrumentBoost.class.getClassLoader()))
+ .name(internalInterceptorName)
+ .field(named("TARGET_INTERCEPTOR")).value(methodsInterceptor)
+ .make();
- interClass.toClass();
+ classesTypeMap.put(internalInterceptorName,
interceptorType.getBytes());
- classesTypeMap.put(internalInterceptorName, bytes);
+ InstrumentDebuggingClass.INSTANCE.log(interceptorType);
} catch (Exception e) {
throw new PluginException("Generate Dynamic plugin failure", e);
}
diff --git a/apm-sniffer/apm-agent/pom.xml b/apm-sniffer/apm-agent/pom.xml
index 6f95267..64d51bd 100644
--- a/apm-sniffer/apm-agent/pom.xml
+++ b/apm-sniffer/apm-agent/pom.xml
@@ -81,7 +81,6 @@
<exclude>io.opencensus:*</exclude>
<exclude>com.google.*:*</exclude>
<exclude>com.google.guava:guava</exclude>
- <exclude>org.javassist:*</exclude>
</excludes>
</artifactSet>
<relocations>
diff --git
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
index 98b3b53..8b02e86 100644
---
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
+++
b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
@@ -39,6 +39,7 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import
org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext;
+import org.apache.skywalking.apm.agent.core.plugin.InstrumentDebuggingClass;
import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap;
import org.apache.skywalking.apm.agent.core.plugin.PluginException;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
@@ -171,7 +172,7 @@ public class SkyWalkingAgent {
logger.debug("On Transformation class {}.",
typeDescription.getName());
}
- InstrumentDebuggingClass.INSTANCE.log(typeDescription,
dynamicType);
+ InstrumentDebuggingClass.INSTANCE.log(dynamicType);
}
@Override
diff --git a/docs/en/setup/service-agent/java-agent/README.md
b/docs/en/setup/service-agent/java-agent/README.md
index e5f556e..e283708 100644
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -105,7 +105,7 @@ Now, we have the following known optional plugins.
* [Customize enhance](Customize-enhance-trace.md) Trace methods based on
description files, rather than write plugin or change source codes.
* Plugin of Spring Cloud Gateway 2.1.x in optional plugin folder. Please only
active this plugin when you install agent in Spring Gateway.
-# Bootstrap class plugins
+## Bootstrap class plugins
All bootstrap plugins are optional, due to unexpected risk. Bootstrap plugins
are provided in `bootstrap-plugins` folder.
**Make sure `bootstrapJarTmp` writable by agent, which is required by
bootstrap instrumentation. New temp jar files will be generated there.**.