Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
killuaz丶x
SkyWalking
提交
570ee752
S
SkyWalking
项目概览
killuaz丶x
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
570ee752
编写于
10月 16, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish new class loader mechanism for 3.3 agent core..
上级
c1b92fd3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
22 addition
and
185 deletion
+22
-185
apm-sniffer/apm-agent-core/pom.xml
apm-sniffer/apm-agent-core/pom.xml
+5
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java
...alking/apm/agent/core/plugin/loader/AgentClassLoader.java
+11
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java
...m/agent/core/plugin/loader/InterceptorInstanceLoader.java
+4
-145
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/NotImplementationException.java
.../agent/core/plugin/loader/NotImplementationException.java
+0
-27
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml
...k-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml
+2
-2
apm-sniffer/pom.xml
apm-sniffer/pom.xml
+0
-8
未找到文件。
apm-sniffer/apm-agent-core/pom.xml
浏览文件 @
570ee752
...
@@ -63,6 +63,11 @@
...
@@ -63,6 +63,11 @@
<artifactId>
apm-network
</artifactId>
<artifactId>
apm-network
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-util
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
net.bytebuddy
</groupId>
<groupId>
net.bytebuddy
</groupId>
<artifactId>
byte-buddy
</artifactId>
<artifactId>
byte-buddy
</artifactId>
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java
浏览文件 @
570ee752
...
@@ -46,18 +46,26 @@ import org.skywalking.apm.logging.LogManager;
...
@@ -46,18 +46,26 @@ import org.skywalking.apm.logging.LogManager;
*/
*/
public
class
AgentClassLoader
extends
ClassLoader
{
public
class
AgentClassLoader
extends
ClassLoader
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
AgentClassLoader
.
class
);
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
AgentClassLoader
.
class
);
private
static
AgentClassLoader
LOADER
;
/**
* The default class loader for the agent.
*/
private
static
AgentClassLoader
DEFAULT_LOADER
;
private
List
<
File
>
classpath
;
private
List
<
File
>
classpath
;
private
List
<
Jar
>
allJars
;
private
List
<
Jar
>
allJars
;
private
ReentrantLock
jarScanLock
=
new
ReentrantLock
();
private
ReentrantLock
jarScanLock
=
new
ReentrantLock
();
public
static
AgentClassLoader
getDefault
()
{
public
static
AgentClassLoader
getDefault
()
{
return
LOADER
;
return
DEFAULT_
LOADER
;
}
}
/**
* Init the default
* @return
* @throws AgentPackageNotFoundException
*/
public
static
AgentClassLoader
initDefaultLoader
()
throws
AgentPackageNotFoundException
{
public
static
AgentClassLoader
initDefaultLoader
()
throws
AgentPackageNotFoundException
{
LOADER
=
new
AgentClassLoader
(
PluginBootstrap
.
class
.
getClassLoader
());
DEFAULT_
LOADER
=
new
AgentClassLoader
(
PluginBootstrap
.
class
.
getClassLoader
());
return
getDefault
();
return
getDefault
();
}
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/InterceptorInstanceLoader.java
浏览文件 @
570ee752
...
@@ -42,21 +42,13 @@ import org.skywalking.apm.logging.LogManager;
...
@@ -42,21 +42,13 @@ import org.skywalking.apm.logging.LogManager;
* This is a very important class in sky-walking's auto-instrumentation mechanism. If you want to fully understand why
* This is a very important class in sky-walking's auto-instrumentation mechanism. If you want to fully understand why
* need this, and how it works, you need have knowledge about Classloader appointment mechanism.
* need this, and how it works, you need have knowledge about Classloader appointment mechanism.
* <p>
* <p>
* The loader will load a class, and focus the target class loader (be intercepted class's classloader) loads it.
* <p>
* If the target class and target class loader are same, the loaded classes( {@link InstanceConstructorInterceptor},
* {@link InstanceMethodsAroundInterceptor} and {@link StaticMethodsAroundInterceptor} implementations) stay in
* singleton.
* <p>
* Created by wusheng on 16/8/2.
* Created by wusheng on 16/8/2.
*/
*/
public
class
InterceptorInstanceLoader
{
public
class
InterceptorInstanceLoader
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
InterceptorInstanceLoader
.
class
);
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
InterceptorInstanceLoader
.
class
);
private
static
ConcurrentHashMap
<
String
,
Object
>
INSTANCE_CACHE
=
new
ConcurrentHashMap
<
String
,
Object
>();
private
static
ConcurrentHashMap
<
String
,
Object
>
INSTANCE_CACHE
=
new
ConcurrentHashMap
<
String
,
Object
>();
private
static
ReentrantLock
INSTANCE_LOAD_LOCK
=
new
ReentrantLock
();
private
static
ReentrantLock
INSTANCE_LOAD_LOCK
=
new
ReentrantLock
();
private
static
Map
<
ClassLoader
,
ClassLoader
>
EXTEND_PLUGIN_CLASSLOADERS
=
new
HashMap
<
ClassLoader
,
ClassLoader
>();
private
static
Map
<
ClassLoader
,
ClassLoader
>
EXTEND_PLUGIN_CLASSLOADERS
=
new
HashMap
<
ClassLoader
,
ClassLoader
>();
/**
/**
...
@@ -64,10 +56,10 @@ public class InterceptorInstanceLoader {
...
@@ -64,10 +56,10 @@ public class InterceptorInstanceLoader {
* Create {@link AgentClassLoader} for each targetClassLoader, as an extend classloader.
* Create {@link AgentClassLoader} for each targetClassLoader, as an extend classloader.
* It can load interceptor classes from plugins, activations folders.
* It can load interceptor classes from plugins, activations folders.
*
*
* @param className
* @param className
the interceptor class, which is expected to be found
* @param targetClassLoader
* @param targetClassLoader
the class loader for current application context
* @param <T>
* @param <T>
expected type
* @return
* @return
the type reference.
* @throws InvocationTargetException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws InstantiationException
...
@@ -100,137 +92,4 @@ public class InterceptorInstanceLoader {
...
@@ -100,137 +92,4 @@ public class InterceptorInstanceLoader {
return
(
T
)
inst
;
return
(
T
)
inst
;
}
}
/**
* Old load method, just for backup
*
* @param className
* @param targetClassLoader
* @param <T>
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
*/
public
static
<
T
>
T
load0
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
,
ClassNotFoundException
{
if
(
targetClassLoader
==
null
)
{
targetClassLoader
=
InterceptorInstanceLoader
.
class
.
getClassLoader
();
}
String
instanceKey
=
className
+
"_OF_"
+
targetClassLoader
.
getClass
().
getName
()
+
"@"
+
Integer
.
toHexString
(
targetClassLoader
.
hashCode
());
Object
inst
=
INSTANCE_CACHE
.
get
(
instanceKey
);
if
(
inst
==
null
)
{
if
(
InterceptorInstanceLoader
.
class
.
getClassLoader
().
equals
(
targetClassLoader
))
{
inst
=
targetClassLoader
.
loadClass
(
className
).
newInstance
();
}
else
{
INSTANCE_LOAD_LOCK
.
lock
();
try
{
try
{
inst
=
findLoadedClass
(
className
,
targetClassLoader
);
if
(
inst
==
null
)
{
inst
=
loadBinary
(
className
,
targetClassLoader
);
}
if
(
inst
==
null
)
{
throw
new
ClassNotFoundException
(
targetClassLoader
.
toString
()
+
" load interceptor class:"
+
className
+
" failure."
);
}
}
catch
(
Exception
e
)
{
throw
new
ClassNotFoundException
(
targetClassLoader
.
toString
()
+
" load interceptor class:"
+
className
+
" failure."
,
e
);
}
}
finally
{
INSTANCE_LOAD_LOCK
.
unlock
();
}
}
if
(
inst
!=
null
)
{
INSTANCE_CACHE
.
put
(
instanceKey
,
inst
);
}
}
return
(
T
)
inst
;
}
/**
* load class from class binary files.
* Most likely all the interceptor implementations should be loaded by this.
*
* @param className interceptor class name.
* @param targetClassLoader the classloader, which should load the interceptor.
* @param <T>
* @return interceptor instance.
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws InstantiationException
*/
private
static
<
T
>
T
loadBinary
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
String
path
=
"/"
+
className
.
replace
(
'.'
,
'/'
).
concat
(
".class"
);
byte
[]
data
=
null
;
BufferedInputStream
is
=
null
;
ByteArrayOutputStream
baos
=
null
;
try
{
logger
.
debug
(
"Read binary code of {} using classload {}"
,
className
,
InterceptorInstanceLoader
.
class
.
getClassLoader
());
is
=
new
BufferedInputStream
(
InterceptorInstanceLoader
.
class
.
getResourceAsStream
(
path
));
baos
=
new
ByteArrayOutputStream
();
int
ch
=
0
;
while
((
ch
=
is
.
read
())
!=
-
1
)
{
baos
.
write
(
ch
);
}
data
=
baos
.
toByteArray
();
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
is
!=
null
)
try
{
is
.
close
();
}
catch
(
IOException
ignored
)
{
}
if
(
baos
!=
null
)
try
{
baos
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
Method
defineClassMethod
=
null
;
Class
<?>
targetClassLoaderType
=
targetClassLoader
.
getClass
();
while
(
defineClassMethod
==
null
&&
targetClassLoaderType
!=
null
)
{
try
{
defineClassMethod
=
targetClassLoaderType
.
getDeclaredMethod
(
"defineClass"
,
String
.
class
,
byte
[].
class
,
int
.
class
,
int
.
class
,
ProtectionDomain
.
class
);
}
catch
(
NoSuchMethodException
e
)
{
targetClassLoaderType
=
targetClassLoaderType
.
getSuperclass
();
}
}
defineClassMethod
.
setAccessible
(
true
);
logger
.
debug
(
"load binary code of {} to classloader {}"
,
className
,
targetClassLoader
);
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
,
data
,
0
,
data
.
length
,
null
);
return
(
T
)
type
.
newInstance
();
}
/**
* Find loaded class in the current classloader.
* Just in case some classes have already been loaded for some reason.
*
* @param className interceptor class name.
* @param targetClassLoader the classloader, which should load the interceptor.
* @param <T>
* @return interceptor instance.
*/
private
static
<
T
>
T
findLoadedClass
(
String
className
,
ClassLoader
targetClassLoader
)
throws
InvocationTargetException
,
IllegalAccessException
,
InstantiationException
{
Method
defineClassMethod
=
null
;
Class
<?>
targetClassLoaderType
=
targetClassLoader
.
getClass
();
while
(
defineClassMethod
==
null
&&
targetClassLoaderType
!=
null
)
{
try
{
defineClassMethod
=
targetClassLoaderType
.
getDeclaredMethod
(
"findLoadedClass"
,
String
.
class
);
}
catch
(
NoSuchMethodException
e
)
{
targetClassLoaderType
=
targetClassLoaderType
.
getSuperclass
();
}
}
defineClassMethod
.
setAccessible
(
true
);
Class
<?>
type
=
(
Class
<?>)
defineClassMethod
.
invoke
(
targetClassLoader
,
className
);
if
(
type
==
null
)
{
return
null
;
}
return
(
T
)
type
.
newInstance
();
}
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/NotImplementationException.java
已删除
100644 → 0
浏览文件 @
c1b92fd3
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.agent.core.plugin.loader
;
/**
* The <code>NotImplementationException</code> represents that, a method didn't implement yet. Most likely, this method is not needed in current version, but be called by unexpected.
*
* @author wusheng
*/
public
class
NotImplementationException
extends
RuntimeException
{
}
apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml
浏览文件 @
570ee752
...
@@ -36,13 +36,13 @@
...
@@ -36,13 +36,13 @@
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
<artifactId>
spring-core
</artifactId>
<version>
4.3.10.RELEASE
</version>
<version>
4.3.10.RELEASE
</version>
<scope>
provided
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<artifactId>
spring-webmvc
</artifactId>
<version>
4.3.8.RELEASE
</version>
<version>
4.3.8.RELEASE
</version>
<scope>
provided
</scope>
<scope>
compile
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<groupId>
javax.servlet
</groupId>
...
...
apm-sniffer/pom.xml
浏览文件 @
570ee752
...
@@ -42,12 +42,4 @@
...
@@ -42,12 +42,4 @@
<compiler.version>
1.6
</compiler.version>
<compiler.version>
1.6
</compiler.version>
<shade.package>
org.skywalking.apm.dependencies
</shade.package>
<shade.package>
org.skywalking.apm.dependencies
</shade.package>
</properties>
</properties>
<dependencies>
<dependency>
<groupId>
org.skywalking
</groupId>
<artifactId>
apm-util
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</project>
</project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录