Search in sources :

Example 6 with LoaderClassPath

use of javassist.LoaderClassPath in project pinpoint by naver.

the class JavassistVerifyErrorTest method bug_regression_BytecodeVerifyError_Invalid_StackMapFrame.

/**
     * bug id
     * https://github.com/naver/pinpoint/issues/1807
     * @throws Exception
     */
@Ignore("fixed Javassist 3.21.0-GA")
@Test
public void bug_regression_BytecodeVerifyError_Invalid_StackMapFrame() throws Exception {
    CustomURLClassLoader classLoader = new CustomURLClassLoader(new URL[] {}, Thread.currentThread().getContextClassLoader());
    ClassPool classPool = new ClassPool(true);
    classPool.appendClassPath(new LoaderClassPath(classLoader));
    final CtClass ctClass = classPool.get(INVALID_STACK_MAP_FRAME);
    final CtMethod method = ctClass.getDeclaredMethod("bytecodeVerifyError");
    method.addLocalVariable("test_localVariable", CtClass.intType);
    method.insertBefore("{ test_localVariable = 1; }");
    final byte[] bytecode = ctClass.toBytecode();
    classLoader.defineClass0(INVALID_STACK_MAP_FRAME, bytecode);
    try {
        Class.forName(INVALID_STACK_MAP_FRAME, true, classLoader);
        Assert.fail("VerifyError");
    } catch (VerifyError e) {
        logger.debug("verifyError:{}", e.getMessage(), e);
    }
    final ASMBytecodeDisassembler bytecodeDisassembler = new ASMBytecodeDisassembler();
    final String dumpBytecode = bytecodeDisassembler.dumpBytecode(bytecode);
    logger.debug("dumpBytecode:{}", dumpBytecode);
    //        javassist bug : invalid stack map frame
    //        00013 InvalidStackMapFrame ArrayList String Iterator I  :  :    FRAME FULL [bug_regression_jdk7/javassist/InvalidStackMapFrame java/util/ArrayList [[[java/lang/Object->[Ljava/lang/String;]]] java/util/Iterator T T T I] []
    final String verify = bytecodeDisassembler.dumpVerify(bytecode, classLoader);
    logger.debug("dumpVerify:{}", verify);
    final String dumpAsm = bytecodeDisassembler.dumpASM(bytecode);
    logger.debug("dumpAsm :{}", dumpAsm);
}
Also used : CtClass(javassist.CtClass) ClassPool(javassist.ClassPool) ASMBytecodeDisassembler(com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler) LoaderClassPath(javassist.LoaderClassPath) CtMethod(javassist.CtMethod) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with LoaderClassPath

use of javassist.LoaderClassPath in project HikariCP by brettwooldridge.

the class JavassistProxyFactory method main.

public static void main(String... args) {
    classPool = new ClassPool();
    classPool.importPackage("java.sql");
    classPool.appendClassPath(new LoaderClassPath(JavassistProxyFactory.class.getClassLoader()));
    try {
        // Cast is not needed for these
        String methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }";
        generateProxyClass(Connection.class, ProxyConnection.class.getName(), methodBody);
        generateProxyClass(Statement.class, ProxyStatement.class.getName(), methodBody);
        generateProxyClass(ResultSet.class, ProxyResultSet.class.getName(), methodBody);
        // For these we have to cast the delegate
        methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }";
        generateProxyClass(PreparedStatement.class, ProxyPreparedStatement.class.getName(), methodBody);
        generateProxyClass(CallableStatement.class, ProxyCallableStatement.class.getName(), methodBody);
        modifyProxyFactory();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ProxyResultSet(com.zaxxer.hikari.pool.ProxyResultSet) ProxyStatement(com.zaxxer.hikari.pool.ProxyStatement) ProxyConnection(com.zaxxer.hikari.pool.ProxyConnection) ClassPool(javassist.ClassPool) LoaderClassPath(javassist.LoaderClassPath) ProxyPreparedStatement(com.zaxxer.hikari.pool.ProxyPreparedStatement) NotFoundException(javassist.NotFoundException) ProxyCallableStatement(com.zaxxer.hikari.pool.ProxyCallableStatement)

Example 8 with LoaderClassPath

use of javassist.LoaderClassPath in project hibernate-orm by hibernate.

the class EnhancerImpl method buildClassPool.

private ClassPool buildClassPool(JavassistEnhancementContext enhancementContext) {
    ClassPool classPool = new ClassPool(false) {

        @Override
        public ClassLoader getClassLoader() {
            return enhancementContext.getLoadingClassLoader();
        }
    };
    ClassLoader loadingClassLoader = enhancementContext.getLoadingClassLoader();
    if (loadingClassLoader != null) {
        classPool.appendClassPath(new LoaderClassPath(loadingClassLoader));
    }
    return classPool;
}
Also used : ClassPool(javassist.ClassPool) LoaderClassPath(javassist.LoaderClassPath)

Example 9 with LoaderClassPath

use of javassist.LoaderClassPath in project dubbo by alibaba.

the class ClassGenerator method getClassPool.

public static ClassPool getClassPool(ClassLoader loader) {
    if (loader == null)
        return ClassPool.getDefault();
    ClassPool pool = POOL_MAP.get(loader);
    if (pool == null) {
        pool = new ClassPool(true);
        pool.appendClassPath(new LoaderClassPath(loader));
        POOL_MAP.put(loader, pool);
    }
    return pool;
}
Also used : ClassPool(javassist.ClassPool) LoaderClassPath(javassist.LoaderClassPath)

Example 10 with LoaderClassPath

use of javassist.LoaderClassPath in project pinpoint by naver.

the class LegacyProfilerPluginClassInjector method loadFromOtherClassLoader.

private Class<?> loadFromOtherClassLoader(ClassLoader classLoader, String className) throws NotFoundException, IllegalArgumentException, IOException, CannotCompileException, IllegalAccessException, InvocationTargetException {
    ClassPool pool = new ClassPool();
    pool.appendClassPath(new LoaderClassPath(classLoader));
    pool.appendClassPath(new LoaderClassPath(sourceClassLoader));
    return loadFromOtherClassLoader(pool, classLoader, className);
}
Also used : ClassPool(javassist.ClassPool) LoaderClassPath(javassist.LoaderClassPath)

Aggregations

LoaderClassPath (javassist.LoaderClassPath)13 ClassPool (javassist.ClassPool)9 CtClass (javassist.CtClass)5 ClassPath (javassist.ClassPath)3 NotFoundException (javassist.NotFoundException)2 Test (org.junit.Test)2 ASMBytecodeDisassembler (com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler)1 ProxyCallableStatement (com.zaxxer.hikari.pool.ProxyCallableStatement)1 ProxyConnection (com.zaxxer.hikari.pool.ProxyConnection)1 ProxyPreparedStatement (com.zaxxer.hikari.pool.ProxyPreparedStatement)1 ProxyResultSet (com.zaxxer.hikari.pool.ProxyResultSet)1 ProxyStatement (com.zaxxer.hikari.pool.ProxyStatement)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 CannotCompileException (javassist.CannotCompileException)1 CtMethod (javassist.CtMethod)1 Ignore (org.junit.Ignore)1