未验证 提交 d66f775f 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Remove javassist from agent dependency (#3176)

* Remove javassist dependency

*   Finish the PR.

* Change doc title level.

* Remove the duplicated codes.
上级 76d91635
...@@ -38,10 +38,6 @@ ...@@ -38,10 +38,6 @@
<grpc.version>1.14.0</grpc.version> <grpc.version>1.14.0</grpc.version>
<guava.version>20.0</guava.version> <guava.version>20.0</guava.version>
<bytebuddy.version>1.9.2</bytebuddy.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> <disruptor.version>3.3.6</disruptor.version>
<wiremock.version>2.6.0</wiremock.version> <wiremock.version>2.6.0</wiremock.version>
<netty-tcnative-boringssl-static.version>2.0.7.Final</netty-tcnative-boringssl-static.version> <netty-tcnative-boringssl-static.version>2.0.7.Final</netty-tcnative-boringssl-static.version>
...@@ -58,8 +54,6 @@ ...@@ -58,8 +54,6 @@
<shade.io.netty.target>${shade.package}.${shade.io.netty.source}</shade.io.netty.target> <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.source>io.opencensus</shade.io.opencensus.source>
<shade.io.opencensus.target>${shade.package}.${shade.io.opencensus.source}</shade.io.opencensus.target> <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> <ststem-rules.version>1.18.0</ststem-rules.version>
</properties> </properties>
...@@ -104,11 +98,6 @@ ...@@ -104,11 +98,6 @@
<artifactId>netty-tcnative-boringssl-static</artifactId> <artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${netty-tcnative-boringssl-static.version}</version> <version>${netty-tcnative-boringssl-static.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javaassist.version}</version>
</dependency>
<dependency> <dependency>
<groupId>net.bytebuddy</groupId> <groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId> <artifactId>byte-buddy-agent</artifactId>
...@@ -192,10 +181,6 @@ ...@@ -192,10 +181,6 @@
</excludes> </excludes>
</artifactSet> </artifactSet>
<relocations> <relocations>
<relocation>
<pattern>${shade.javaassist.source}</pattern>
<shadedPattern>${shade.javaassist.target}</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>${shade.com.lmax.disruptor.source}</pattern> <pattern>${shade.com.lmax.disruptor.source}</pattern>
<shadedPattern>${shade.com.lmax.disruptor.target}</shadedPattern> <shadedPattern>${shade.com.lmax.disruptor.target}</shadedPattern>
......
...@@ -17,11 +17,10 @@ ...@@ -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.File;
import java.io.IOException; import java.io.IOException;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.DynamicType;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; 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.boot.AgentPackagePath;
...@@ -30,6 +29,9 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog; ...@@ -30,6 +29,9 @@ 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.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 * @author wu-sheng
*/ */
public enum InstrumentDebuggingClass { public enum InstrumentDebuggingClass {
...@@ -38,7 +40,7 @@ public enum InstrumentDebuggingClass { ...@@ -38,7 +40,7 @@ public enum InstrumentDebuggingClass {
private static final ILog logger = LogManager.getLogger(InstrumentDebuggingClass.class); private static final ILog logger = LogManager.getLogger(InstrumentDebuggingClass.class);
private File debuggingClassesRootPath; private File debuggingClassesRootPath;
public void log(TypeDescription typeDescription, DynamicType dynamicType) { public void log(DynamicType dynamicType) {
if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) { if (!Config.Agent.IS_OPEN_DEBUGGING_CLASS) {
return; return;
} }
...@@ -62,7 +64,7 @@ public enum InstrumentDebuggingClass { ...@@ -62,7 +64,7 @@ public enum InstrumentDebuggingClass {
try { try {
dynamicType.saveIn(debuggingClassesRootPath); dynamicType.saveIn(debuggingClassesRootPath);
} catch (IOException e) { } 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) { } catch (Throwable t) {
logger.error(t, "Save debugging classes fail."); logger.error(t, "Save debugging classes fail.");
......
...@@ -26,16 +26,19 @@ import java.lang.instrument.Instrumentation; ...@@ -26,16 +26,19 @@ import java.lang.instrument.Instrumentation;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javassist.ClassPool; import net.bytebuddy.ByteBuddy;
import javassist.CtClass;
import javassist.CtField;
import net.bytebuddy.agent.builder.AgentBuilder; 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.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.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; 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.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager; 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.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.PluginException;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder; import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
...@@ -43,6 +46,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn ...@@ -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.interceptor.StaticMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; 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 * If there is Bootstrap instrumentation plugin declared in plugin list, BootstrapInstrumentBoost inject the necessary
* classes into bootstrap class loader, including generated dynamic delegate classes. * classes into bootstrap class loader, including generated dynamic delegate classes.
...@@ -51,6 +56,7 @@ import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader; ...@@ -51,6 +56,7 @@ import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;
*/ */
public class BootstrapInstrumentBoost { public class BootstrapInstrumentBoost {
private static final ILog logger = LogManager.getLogger(BootstrapInstrumentBoost.class); 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 = { 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.EnhancedInstance",
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.BootstrapInterRuntimeAssist", "org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.BootstrapInterRuntimeAssist",
...@@ -59,7 +65,14 @@ public class BootstrapInstrumentBoost { ...@@ -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.StaticMethodsAroundInterceptor",
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult", "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.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_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"; 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 { ...@@ -128,26 +141,26 @@ public class BootstrapInstrumentBoost {
*/ */
private static boolean prepareJREInstrumentation(PluginFinder pluginFinder, private static boolean prepareJREInstrumentation(PluginFinder pluginFinder,
Map<String, byte[]> classesTypeMap) throws PluginException { Map<String, byte[]> classesTypeMap) throws PluginException {
ClassPool classPool = ClassPool.getDefault(); TypePool typePool = TypePool.Default.of(BootstrapInstrumentBoost.class.getClassLoader());
List<AbstractClassEnhancePluginDefine> bootstrapClassMatchDefines = pluginFinder.getBootstrapClassMatchDefine(); List<AbstractClassEnhancePluginDefine> bootstrapClassMatchDefines = pluginFinder.getBootstrapClassMatchDefine();
for (AbstractClassEnhancePluginDefine define : bootstrapClassMatchDefines) { for (AbstractClassEnhancePluginDefine define : bootstrapClassMatchDefines) {
for (InstanceMethodsInterceptPoint point : define.getInstanceMethodsInterceptPoints()) { for (InstanceMethodsInterceptPoint point : define.getInstanceMethodsInterceptPoints()) {
if (point.isOverrideArgs()) { 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 { } else {
generateDelegator(classesTypeMap, classPool, INSTANCE_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor()); generateDelegator(classesTypeMap, typePool, INSTANCE_METHOD_DELEGATE_TEMPLATE, point.getMethodsInterceptor());
} }
} }
for (ConstructorInterceptPoint point : define.getConstructorsInterceptPoints()) { 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()) { for (StaticMethodsInterceptPoint point : define.getStaticMethodsInterceptPoints()) {
if (point.isOverrideArgs()) { 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 { } 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 { ...@@ -160,29 +173,27 @@ public class BootstrapInstrumentBoost {
* One key step to avoid class confliction between AppClassLoader and BootstrapClassLoader * One key step to avoid class confliction between AppClassLoader and BootstrapClassLoader
* *
* @param classesTypeMap hosts injected binary of generated class * @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 * @param templateClassName represents the class as template in this generation process. The templates are
* pre-defined in SkyWalking agent core. * pre-defined in SkyWalking agent core.
* @param methodsInterceptor * @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 templateClassName, String methodsInterceptor) {
String internalInterceptorName = internalDelegate(methodsInterceptor); String internalInterceptorName = internalDelegate(methodsInterceptor);
try { try {
CtClass interClass = classPool.get(templateClassName); TypeDescription templateTypeDescription = typePool.describe(templateClassName)
interClass.setName(internalInterceptorName); .resolve();
CtField interceptorDefine = interClass.getField("TARGET_INTERCEPTOR");
interClass.removeField(interceptorDefine);
interceptorDefine = CtField.make("private static String TARGET_INTERCEPTOR = \"" + methodsInterceptor + "\";", interClass);
interClass.addField(interceptorDefine);
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) { } catch (Exception e) {
throw new PluginException("Generate Dynamic plugin failure", e); throw new PluginException("Generate Dynamic plugin failure", e);
} }
......
...@@ -81,7 +81,6 @@ ...@@ -81,7 +81,6 @@
<exclude>io.opencensus:*</exclude> <exclude>io.opencensus:*</exclude>
<exclude>com.google.*:*</exclude> <exclude>com.google.*:*</exclude>
<exclude>com.google.guava:guava</exclude> <exclude>com.google.guava:guava</exclude>
<exclude>org.javassist:*</exclude>
</excludes> </excludes>
</artifactSet> </artifactSet>
<relocations> <relocations>
......
...@@ -39,6 +39,7 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog; ...@@ -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.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; 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.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.PluginBootstrap;
import org.apache.skywalking.apm.agent.core.plugin.PluginException; 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.PluginFinder;
...@@ -171,7 +172,7 @@ public class SkyWalkingAgent { ...@@ -171,7 +172,7 @@ public class SkyWalkingAgent {
logger.debug("On Transformation class {}.", typeDescription.getName()); logger.debug("On Transformation class {}.", typeDescription.getName());
} }
InstrumentDebuggingClass.INSTANCE.log(typeDescription, dynamicType); InstrumentDebuggingClass.INSTANCE.log(dynamicType);
} }
@Override @Override
......
...@@ -105,7 +105,7 @@ Now, we have the following known optional plugins. ...@@ -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. * [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. * 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. 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.**. **Make sure `bootstrapJarTmp` writable by agent, which is required by bootstrap instrumentation. New temp jar files will be generated there.**.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册