You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/08/01 06:29:08 UTC
[skywalking] 02/03: Make refactor works.
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch code-refactor
in repository https://gitbox.apache.org/repos/asf/skywalking.git
commit 157a8e0fe845b4376a4212dc9014f01eb1a232f7
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Thu Aug 1 13:53:00 2019 +0800
Make refactor works.
---
.../plugin/bootstrap/BootstrapInstrumentBoost.java | 19 +++++++++----------
.../core/plugin/jdk9module/JDK9ModuleExporter.java | 22 +++++++++++++++++-----
.../skywalking/apm/agent/SkyWalkingAgent.java | 2 +-
3 files changed, 27 insertions(+), 16 deletions(-)
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 b9e8300..7376707 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
@@ -80,28 +80,27 @@ public class BootstrapInstrumentBoost {
return agentBuilder;
}
- /**
- * Prepare to open edge of necessary classes.
- */
- for (String generatedClass : classesTypeMap.keySet()) {
- edgeClasses.add(generatedClass);
- }
-
for (String highPriorityClass : HIGH_PRIORITY_CLASSES) {
- edgeClasses.add(highPriorityClass);
loadHighPriorityClass(classesTypeMap, highPriorityClass);
}
-
for (String highPriorityClass : ByteBuddyCoreClasses.CLASSES) {
loadHighPriorityClass(classesTypeMap, highPriorityClass);
}
/**
+ * Prepare to open edge of necessary classes.
+ */
+ for (String generatedClass : classesTypeMap.keySet()) {
+ edgeClasses.add(generatedClass);
+ }
+
+ /**
* Inject the classes into bootstrap class loader by using Unsafe Strategy.
* ByteBuddy adapts the sun.misc.Unsafe and jdk.internal.misc.Unsafe automatically.
*/
- ClassInjector.UsingUnsafe.ofBootLoader().injectRaw(classesTypeMap);
agentBuilder = agentBuilder.enableUnsafeBootstrapInjection();
+ ClassInjector.UsingUnsafe.ofBootLoader().injectRaw(classesTypeMap);
+
return agentBuilder;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/jdk9module/JDK9ModuleExporter.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/jdk9module/JDK9ModuleExporter.java
index 3d25d74..93ad399 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/jdk9module/JDK9ModuleExporter.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/jdk9module/JDK9ModuleExporter.java
@@ -34,22 +34,34 @@ import org.apache.skywalking.apm.agent.core.plugin.ByteBuddyCoreClasses;
public class JDK9ModuleExporter {
private static final ILog logger = LogManager.getLogger(JDK9ModuleExporter.class);
+ private static final String[] HIGH_PRIORITY_CLASSES = {
+ "org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsInter",
+ };
+
/**
- * Assures that all modules of the supplied types are read by the module of any instrumented type.
- * JDK Module system was introduced since JDK9.
+ * Assures that all modules of the supplied types are read by the module of any instrumented type. JDK Module system
+ * was introduced since JDK9.
*
* The following codes work only JDK Module system exist.
*/
- public static void openReadEdge(Instrumentation instrumentation, AgentBuilder agentBuilder, EdgeClasses classes) {
+ public static AgentBuilder openReadEdge(Instrumentation instrumentation, AgentBuilder agentBuilder,
+ EdgeClasses classes) {
for (String className : classes.classes) {
try {
- agentBuilder = agentBuilder.assureReadEdgeTo(instrumentation, Class.forName(className));
+ agentBuilder = agentBuilder.assureReadEdgeFromAndTo(instrumentation, Class.forName(className));
+ } catch (ClassNotFoundException e) {
+ throw new UnsupportedOperationException("Fail to open read edge for class " + className + " to public access in JDK9+", e);
+ }
+ }
+ for (String className : HIGH_PRIORITY_CLASSES) {
+ try {
+ agentBuilder = agentBuilder.assureReadEdgeFromAndTo(instrumentation, Class.forName(className));
} catch (ClassNotFoundException e) {
- logger.error(e, "Fail to open read edge for class " + className + " to public access in JDK9+");
throw new UnsupportedOperationException("Fail to open read edge for class " + className + " to public access in JDK9+", e);
}
}
+ return agentBuilder;
}
public static class EdgeClasses {
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 828ad4b..ddfca1a 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
@@ -107,7 +107,7 @@ public class SkyWalkingAgent {
}
try {
- JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses);
+ agentBuilder = JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses);
} catch (Exception e) {
logger.error(e, "SkyWalking agent open read edge in JDK 9+ failure. Shutting down.");
return;