mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-28 06:08:43 +10:00
[강운덕] [LUCYSUS-1744] 바이트 코드 조작 클래스 별도 분리.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@530 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.profiler.interceptor.bci;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import javassist.ClassPool;
|
||||
|
||||
public interface ByteCodeInstrumentor {
|
||||
|
||||
void addInterceptor(String className, String methodName, String[] args, Interceptor interceptor);
|
||||
|
||||
// 임시로 만들자.
|
||||
ClassPool getClassPool();
|
||||
|
||||
void checkLibrary(ClassLoader classLoader, String javassistClassName);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.profiler.interceptor.bci;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
|
||||
public interface ByteCodeManipulator {
|
||||
void addInterceptor(Interceptor interceptor);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.profiler.interceptor.bci;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
import com.profiler.interceptor.StaticBeforeInterceptor;
|
||||
import javassist.ClassPool;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class JavaAssistByteCodeInstrumentor implements ByteCodeInstrumentor {
|
||||
|
||||
private final Logger logger = Logger.getLogger(JavaAssistByteCodeInstrumentor.class.getName());
|
||||
|
||||
private ClassPool classPool;
|
||||
|
||||
public JavaAssistByteCodeInstrumentor() {
|
||||
this.classPool = createClassPool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptor(String className, String methodName, String[] args, Interceptor interceptor) {
|
||||
if(interceptor instanceof StaticBeforeInterceptor) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ClassPool getClassPool() {
|
||||
return this.classPool;
|
||||
}
|
||||
|
||||
private ClassPool createClassPool() {
|
||||
ClassPool classPool = new ClassPool(null);
|
||||
classPool.appendSystemPath();
|
||||
|
||||
String catalinaHome = System.getProperty("catalina.home");
|
||||
if (catalinaHome != null) {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("CATALINA_HOME=" + catalinaHome);
|
||||
}
|
||||
|
||||
appendClassPath(classPool, catalinaHome + "/lib/servlet-api.jar");
|
||||
appendClassPath(classPool, catalinaHome + "/lib/catalina.jar");
|
||||
}
|
||||
return classPool;
|
||||
}
|
||||
|
||||
private void appendClassPath(ClassPool classPool, String pathName) {
|
||||
try {
|
||||
classPool.appendClassPath(pathName);
|
||||
} catch (NotFoundException e) {
|
||||
if (logger.isLoggable(Level.WARNING)) {
|
||||
logger.warning("lib not found. " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void checkLibrary(ClassLoader classLoader, String javassistClassName) {
|
||||
// TODO Util로 뽑을까?
|
||||
boolean findClass = findClass(javassistClassName);
|
||||
if (findClass) {
|
||||
return;
|
||||
}
|
||||
loadClassLoaderLibraries(classLoader);
|
||||
}
|
||||
|
||||
public boolean findClass(String javassistClassName) {
|
||||
// TODO 원래는 get인데. find는 ctclas를 생성하지 않아 변경. 어차피 아래서 생성하기는 함. 유효성 여부 확인
|
||||
// 필요
|
||||
URL url = classPool.find(javassistClassName);
|
||||
if (url == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadClassLoaderLibraries(ClassLoader classLoader) {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
|
||||
// TODO classLoader가 가지고 있는 전체 리소스를 모두 로드해야 되는것인지? 테스트 케이스 만들어서
|
||||
// 확인해봐야 할듯.
|
||||
URL[] urlList = urlClassLoader.getURLs();
|
||||
for (URL tempURL : urlList) {
|
||||
String filePath = tempURL.getFile();
|
||||
try {
|
||||
classPool.appendClassPath(filePath);
|
||||
// TODO 여기서 로그로 class로더를 찍어보면 어떤 clasdLoader에서 로딩되는지 알수 있을거
|
||||
// 것같음.
|
||||
// 만약 한개만 로딩해도 된다면. return true 할것
|
||||
// log("Loaded "+filePath+" library.");
|
||||
|
||||
} catch (NotFoundException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.profiler.interceptor.bci;
|
||||
|
||||
import com.profiler.interceptor.Interceptor;
|
||||
|
||||
public class JavaAssistByteCodeManipulator implements ByteCodeManipulator{
|
||||
@Override
|
||||
public void addInterceptor(Interceptor interceptor) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user