Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve bytebuddy class enhance for retransform classes #561

Merged
merged 24 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release Notes.
* Fix the conflict between the logging kernel and the JDK threadpool plugin.
* Fix the thread safety bug of finishing operation for the span named "SpringCloudGateway/sendRequest"
* Fix NPE in guava-eventbus-plugin.
* Support re-transform/hot-swap classes with other java agents, and remove the obsolete cache enhanced class feature.

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.skywalking.apm.agent.core.logging.core.LogOutput;
import org.apache.skywalking.apm.agent.core.logging.core.ResolverType;
import org.apache.skywalking.apm.agent.core.logging.core.WriterFactory;
import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ClassCacheMode;
import org.apache.skywalking.apm.util.Length;

/**
Expand Down Expand Up @@ -110,19 +109,6 @@ public static class Agent {
*/
public static boolean IS_OPEN_DEBUGGING_CLASS = false;

/**
* If true, SkyWalking agent will cache all instrumented classes to memory or disk files (decided by class cache
* mode), allow other javaagent to enhance those classes that enhanced by SkyWalking agent.
*/
public static boolean IS_CACHE_ENHANCED_CLASS = false;

/**
* The instrumented classes cache mode: MEMORY or FILE MEMORY: cache class bytes to memory, if instrumented
* classes is too many or too large, it may take up more memory FILE: cache class bytes in `/class-cache`
* folder, automatically clean up cached class files when the application exits
*/
public static ClassCacheMode CLASS_CACHE_MODE = ClassCacheMode.MEMORY;

/**
* The identifier of the instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ public class Constants {
public static String EVENT_LAYER_NAME = "GENERAL";

public static int NULL_VALUE = 0;

/**
* The name trait for auxiliary type names, field names and method names which generated by ByteBuddy.
*/
public static final String NAME_TRAIT = "sw$";

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public boolean matches(T target) {
return target.getAnnotationType().asErasure().getName().equals(annotationTypeName);
}

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
*/
@Override
public String toString() {
return "AnnotationTypeNameMatch{" +
"annotationTypeName='" + annotationTypeName + '\'' +
'}';
}

/**
* The static method to create {@link AnnotationTypeNameMatch} This is a delegate method to follow byte-buddy {@link
* ElementMatcher}'s code style.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public boolean matches(MethodDescription target) {
return false;
}

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
*/
@Override
public String toString() {
return "ArgumentTypeNameMatch{" +
"index=" + index +
", argumentTypeName='" + argumentTypeName + '\'' +
'}';
}

/**
* The static method to create {@link ArgumentTypeNameMatch} This is a delegate method to follow byte-buddy {@link
* ElementMatcher}'s code style.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public boolean matches(MethodDescription target) {
return target.getReturnType().asErasure().getName().equals(returnTypeName);
}

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
*/
@Override
public String toString() {
return "ReturnTypeNameMatch{" +
"returnTypeName='" + returnTypeName + '\'' +
'}';
}

/**
* The static method to create {@link ReturnTypeNameMatch} This is a delegate method to follow byte-buddy {@link
* ElementMatcher}'s code style.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.Objects;

/**
* One of the three "Intercept Point". "Intercept Point" is a definition about where and how intercept happens. In this
* "Intercept Point", the definition targets class's constructors, and the interceptor.
Expand All @@ -41,4 +43,13 @@ public interface ConstructorInterceptPoint {
* org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor}
*/
String getConstructorInterceptor();

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
* @return hashCode of this intercept point
*/
default int computeHashCode() {
return Objects.hash(this.getClass().getName(), this.getConstructorMatcher().toString(), this.getConstructorInterceptor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.Objects;

/**
* One of the three "Intercept Point". "Intercept Point" is a definition about where and how intercept happens. In this
* "Intercept Point", the definition targets class's instance methods, and the interceptor.
Expand All @@ -42,4 +44,13 @@ public interface InstanceMethodsInterceptPoint {
String getMethodsInterceptor();

boolean isOverrideArgs();

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
* @return hashCode of this intercept point
*/
default int computeHashCode() {
return Objects.hash(this.getClass().getName(), this.getMethodsMatcher().toString(), this.getMethodsInterceptor(), this.isOverrideArgs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.Objects;

/**
* One of the three "Intercept Point". "Intercept Point" is a definition about where and how intercept happens. In this
* "Intercept Point", the definition targets class's static methods, and the interceptor.
Expand All @@ -42,4 +44,13 @@ public interface StaticMethodsInterceptPoint {
String getMethodsInterceptor();

boolean isOverrideArgs();

/**
* To ensure that the hashCode for recreating the XxxInterceptPoint instance is the same as the previous instance,
* each ElementMatcher implementation class needs to implement toString() method.
* @return hashCode of this intercept point
*/
default int computeHashCode() {
return Objects.hash(this.getClass().getName(), this.getMethodsMatcher().toString(), this.getMethodsInterceptor(), this.isOverrideArgs());
}
}
Loading
Loading