This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch bootstrap-cl
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 96f17f16b7bf6361e5740358496f94facbbe118f
Author: Wu Sheng <[email protected]>
AuthorDate: Tue Jul 23 22:57:32 2019 +0800

    Setup the new core.
---
 apm-sniffer/apm-agent-core/pom.xml                 |  8 +-
 .../plugin/bootstrap/BootstrapInstrumentBoost.java |  4 +-
 .../plugin/bootstrap/BootstrapPluginLogBridge.java | 91 ++++++++++++++++++++++
 .../agent/core/plugin/bootstrap/IBootstrapLog.java | 54 +++++++++++++
 ...BootstrapInstanceMethodInterceptorTemplate.java | 15 ++--
 .../interceptor/enhance/BootstrapInterAssist.java  | 15 ++--
 .../enhance/ClassEnhancePluginDefine.java          |  4 +-
 apm-sniffer/apm-agent/pom.xml                      |  1 +
 .../HttpUrlConnectionInstrumentation.java          |  4 +
 9 files changed, 173 insertions(+), 23 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/pom.xml 
b/apm-sniffer/apm-agent-core/pom.xml
index 4ef45f4..f6201e7 100644
--- a/apm-sniffer/apm-agent-core/pom.xml
+++ b/apm-sniffer/apm-agent-core/pom.xml
@@ -55,8 +55,8 @@
         
<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.net.javaassist.source>javassist</shade.net.javaassist.source>
-        
<shade.net.javaassist.target>${shade.package}.${shade.net.javaassist.source}</shade.net.javaassist.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>
 
@@ -190,8 +190,8 @@
                             </artifactSet>
                             <relocations>
                                 <relocation>
-                                    
<pattern>${shade.net.javaassist.source}</pattern>
-                                    
<shadedPattern>${shade.net.javaassist.target}</shadedPattern>
+                                    
<pattern>${shade.javaassist.source}</pattern>
+                                    
<shadedPattern>${shade.javaassist.target}</shadedPattern>
                                 </relocation>
                                 <relocation>
                                     
<pattern>${shade.com.lmax.disruptor.source}</pattern>
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 abacfbf..8d38901 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
@@ -53,7 +53,7 @@ public class BootstrapInstrumentBoost {
         
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.BootstrapInterAssist",
         
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor",
         
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult",
-        "org.apache.skywalking.apm.agent.core.logging.api.ILog"
+        "org.apache.skywalking.apm.agent.core.plugin.bootstrap.IBootstrapLog"
     };
     private static String INSTANCE_DELEGATE_TEMPLATE = 
"org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.BootstrapInstanceMethodInterceptorTemplate";
 
@@ -120,7 +120,7 @@ public class BootstrapInstrumentBoost {
         Map<String, byte[]> classesTypeMap) throws PluginException {
         ClassPool classPool = ClassPool.getDefault();
         boolean isHasJREInstrumentation = false;
-        for (AbstractClassEnhancePluginDefine   define : 
pluginFinder.getBootstrapClassMatchDefine()) {
+        for (AbstractClassEnhancePluginDefine define : 
pluginFinder.getBootstrapClassMatchDefine()) {
             for (InstanceMethodsInterceptPoint point : 
define.getInstanceMethodsInterceptPoints()) {
                 String methodsInterceptor = point.getMethodsInterceptor();
                 String internalInterceptorName = 
internalDelegate(methodsInterceptor);
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java
new file mode 100644
index 0000000..6a70229
--- /dev/null
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/BootstrapPluginLogBridge.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.agent.core.plugin.bootstrap;
+
+import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
+
+/**
+ * The log bridge makes the ILog accessible inside bootstrap classloader, 
especially for internal interceptor.
+ *
+ * @author wusheng
+ */
+public class BootstrapPluginLogBridge implements IBootstrapLog {
+    public static IBootstrapLog getLogger(String clazz) {
+        return new BootstrapPluginLogBridge(clazz);
+    }
+
+    private final ILog logger;
+
+    private BootstrapPluginLogBridge(String clazz) {
+        logger = LogManager.getLogger(clazz);
+    }
+
+    @Override public void info(String format) {
+
+    }
+
+    @Override public void info(String format, Object... arguments) {
+
+    }
+
+    @Override public void warn(String format, Object... arguments) {
+
+    }
+
+    @Override public void warn(Throwable e, String format, Object... 
arguments) {
+
+    }
+
+    @Override public void error(String format, Throwable e) {
+
+    }
+
+    @Override public void error(Throwable e, String format, Object... 
arguments) {
+
+    }
+
+    @Override public boolean isDebugEnable() {
+        return false;
+    }
+
+    @Override public boolean isInfoEnable() {
+        return false;
+    }
+
+    @Override public boolean isWarnEnable() {
+        return false;
+    }
+
+    @Override public boolean isErrorEnable() {
+        return false;
+    }
+
+    @Override public void debug(String format) {
+
+    }
+
+    @Override public void debug(String format, Object... arguments) {
+
+    }
+
+    @Override public void error(String format) {
+
+    }
+}
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/IBootstrapLog.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/IBootstrapLog.java
new file mode 100644
index 0000000..4278c84
--- /dev/null
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/bootstrap/IBootstrapLog.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.agent.core.plugin.bootstrap;
+
+/**
+ * The log interface used in bootstrap internal interceptors.
+ *
+ * Never used in any plugin or tracing core.
+ *
+ * @author wusheng
+ */
+public interface IBootstrapLog {
+    void info(String format);
+
+    void info(String format, Object... arguments);
+
+    void warn(String format, Object... arguments);
+
+    void warn(Throwable e, String format, Object... arguments);
+
+    void error(String format, Throwable e);
+
+    void error(Throwable e, String format, Object... arguments);
+
+    boolean isDebugEnable();
+
+    boolean isInfoEnable();
+
+    boolean isWarnEnable();
+
+    boolean isErrorEnable();
+
+    void debug(String format);
+
+    void debug(String format, Object... arguments);
+
+    void error(String format);
+}
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInstanceMethodInterceptorTemplate.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInstanceMethodInterceptorTemplate.java
index b54859b..86138e6 100644
--- 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInstanceMethodInterceptorTemplate.java
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInstanceMethodInterceptorTemplate.java
@@ -18,6 +18,7 @@
 
 package org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance;
 
+import java.io.PrintStream;
 import java.lang.reflect.Method;
 import java.util.concurrent.Callable;
 import net.bytebuddy.implementation.bind.annotation.AllArguments;
@@ -25,7 +26,7 @@ import net.bytebuddy.implementation.bind.annotation.Origin;
 import net.bytebuddy.implementation.bind.annotation.RuntimeType;
 import net.bytebuddy.implementation.bind.annotation.SuperCall;
 import net.bytebuddy.implementation.bind.annotation.This;
-import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.plugin.bootstrap.IBootstrapLog;
 
 /**
  * This class wouldn't be loaded in real env. This is a class template for 
dynamic class generation.
@@ -33,10 +34,14 @@ import 
org.apache.skywalking.apm.agent.core.logging.api.ILog;
  * @author wusheng
  */
 public class BootstrapInstanceMethodInterceptorTemplate {
+    private static final PrintStream OUT = System.out;
+    /**
+     * This field is never set, but has value in the runtime.
+     */
     private static String TARGET_INTERCEPTOR;
 
-    private static ILog LOGGER;
     private static InstanceMethodsAroundInterceptor INTERCEPTOR;
+    private static IBootstrapLog LOGGER;
 
     /**
      * Intercept the target instance method.
@@ -97,15 +102,15 @@ public class BootstrapInstanceMethodInterceptorTemplate {
             }
         }
 
-        return result;
+        return ret;
     }
 
     private static void prepare() {
-        if (LOGGER == null) {
+        if (INTERCEPTOR == null) {
             ClassLoader loader = BootstrapInterAssist.getAgentClassLoader();
 
             if (loader != null) {
-                ILog logger = BootstrapInterAssist.getLogger(loader, 
TARGET_INTERCEPTOR);
+                IBootstrapLog logger = BootstrapInterAssist.getLogger(loader, 
TARGET_INTERCEPTOR);
                 if (logger != null) {
                     LOGGER = logger;
 
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInterAssist.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInterAssist.java
index 43c6049..361c97a 100644
--- 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInterAssist.java
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/BootstrapInterAssist.java
@@ -21,7 +21,7 @@ package 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance;
 import java.io.PrintStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.plugin.bootstrap.IBootstrapLog;
 
 /**
  * This assist help all bootstrap class core interceptor.
@@ -31,8 +31,7 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog;
 public class BootstrapInterAssist {
     private static final String AGENT_CLASSLOADER_DEFAULT = 
"org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader";
     private static final String DEFAULT_AGENT_CLASSLOADER_INSTANCE = 
"DEFAULT_LOADER";
-    private static final String LOG_MANAGER_CLASS = 
"org.apache.skywalking.apm.agent.core.logging.api.LogManager";
-    private static final String LOG_MANAGER_INSTANCE = "RESOLVER";
+    private static final String LOG_MANAGER_CLASS = 
"org.apache.skywalking.apm.agent.core.plugin.bootstrap.BootstrapPluginLogBridge";
     private static final String LOG_MANAGER_GET_LOGGER_METHOD = "getLogger";
     private static final PrintStream OUT = System.out;
 
@@ -54,15 +53,11 @@ public class BootstrapInterAssist {
         }
     }
 
-    public static ILog getLogger(ClassLoader defaultAgentClassLoader, String 
interceptor) {
+    public static IBootstrapLog getLogger(ClassLoader defaultAgentClassLoader, 
String interceptor) {
         try {
             Class<?> logManagerClass = Class.forName(LOG_MANAGER_CLASS, true, 
defaultAgentClassLoader);
-            Field resolver = 
logManagerClass.getDeclaredField(LOG_MANAGER_INSTANCE);
-            resolver.setAccessible(true);
-            Object logManagerInstance = resolver.get(null);
-
             Method getLogger = 
logManagerClass.getMethod(LOG_MANAGER_GET_LOGGER_METHOD, String.class);
-            return (ILog)getLogger.invoke(logManagerInstance, interceptor + 
"_internal");
+            return (IBootstrapLog)getLogger.invoke(null, interceptor + 
"_internal");
         } catch (Exception e) {
             e.printStackTrace(OUT);
             return null;
@@ -70,7 +65,7 @@ public class BootstrapInterAssist {
     }
 
     public static InstanceMethodsAroundInterceptor 
createInterceptor(ClassLoader defaultAgentClassLoader,
-        String className, ILog log) {
+        String className, IBootstrapLog log) {
         try {
             Class<?> interceptor = Class.forName(className, true, 
defaultAgentClassLoader);
             InstanceMethodsAroundInterceptor interceptorInstance = 
(InstanceMethodsAroundInterceptor)interceptor.newInstance();
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
index d468f85..3fa3737 100644
--- 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
@@ -184,14 +184,14 @@ public abstract class ClassEnhancePluginDefine extends 
AbstractClassEnhancePlugi
                             newClassBuilder.method(junction)
                                 .intercept(
                                     MethodDelegation.withDefaultConfiguration()
-                                        .to(new InstMethodsInter(interceptor, 
classLoader))
+                                        
.to(BootstrapInstrumentBoost.forInternalDelegateClass(interceptor))
                                 );
                     } else {
                         newClassBuilder =
                             newClassBuilder.method(junction)
                                 .intercept(
                                     MethodDelegation.withDefaultConfiguration()
-                                        
.to(BootstrapInstrumentBoost.forInternalDelegateClass(interceptor))
+                                        .to(new InstMethodsInter(interceptor, 
classLoader))
                                 );
                     }
                 }
diff --git a/apm-sniffer/apm-agent/pom.xml b/apm-sniffer/apm-agent/pom.xml
index 64d51bd..6f95267 100644
--- a/apm-sniffer/apm-agent/pom.xml
+++ b/apm-sniffer/apm-agent/pom.xml
@@ -81,6 +81,7 @@
                                     <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-sdk-plugin/jre-HttpURLConnection/src/main/java/org/apache/skywalking/apm/plugin/jre/httpurlconnection/HttpUrlConnectionInstrumentation.java
 
b/apm-sniffer/apm-sdk-plugin/jre-HttpURLConnection/src/main/java/org/apache/skywalking/apm/plugin/jre/httpurlconnection/HttpUrlConnectionInstrumentation.java
index 3d094f0..f400cb9 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jre-HttpURLConnection/src/main/java/org/apache/skywalking/apm/plugin/jre/httpurlconnection/HttpUrlConnectionInstrumentation.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jre-HttpURLConnection/src/main/java/org/apache/skywalking/apm/plugin/jre/httpurlconnection/HttpUrlConnectionInstrumentation.java
@@ -64,4 +64,8 @@ public class HttpUrlConnectionInstrumentation extends 
ClassEnhancePluginDefine {
     @Override public StaticMethodsInterceptPoint[] 
getStaticMethodsInterceptPoints() {
         return new StaticMethodsInterceptPoint[0];
     }
+
+    @Override public boolean isBootstrapInstrumentation() {
+        return true;
+    }
 }

Reply via email to