Search in sources :

Example 31 with NotFoundException

use of javassist.NotFoundException in project pinpoint by naver.

the class LegacyProfilerPluginClassInjector method loadFromOtherClassLoader.

private Class<?> loadFromOtherClassLoader(ClassPool pool, ClassLoader classLoader, String className) throws NotFoundException, IOException, CannotCompileException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Class<?> c = null;
    try {
        c = classLoader.loadClass(className);
    } catch (ClassNotFoundException ignore) {
    }
    if (c != null) {
        return c;
    }
    CtClass ct = pool.get(className);
    if (ct == null) {
        throw new NotFoundException(className);
    }
    CtClass superClass = ct.getSuperclass();
    if (superClass != null) {
        loadFromOtherClassLoader(pool, classLoader, superClass.getName());
    }
    CtClass[] interfaces = ct.getInterfaces();
    for (CtClass i : interfaces) {
        loadFromOtherClassLoader(pool, classLoader, i.getName());
    }
    Collection<String> refs = ct.getRefClasses();
    for (String ref : refs) {
        try {
            loadFromOtherClassLoader(pool, classLoader, ref);
        } catch (NotFoundException e) {
            logger.warn("Skip a referenced class because of NotFoundException : ", e);
        }
    }
    byte[] bytes = ct.toBytecode();
    return (Class<?>) DEFINE_CLASS.invoke(classLoader, ct.getName(), bytes, 0, bytes.length);
}
Also used : CtClass(javassist.CtClass) NotFoundException(javassist.NotFoundException) CtClass(javassist.CtClass)

Example 32 with NotFoundException

use of javassist.NotFoundException in project pinpoint by naver.

the class JavassistMethod method addInterceptor0.

private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
    try {
        ScopeInfo scopeInfo = resolveScopeInfo(interceptorClassName, scope, executionPolicy);
        Interceptor interceptor = createInterceptor(interceptorClassName, scopeInfo, constructorArgs);
        int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(interceptor);
        addInterceptor0(interceptor, interceptorId);
        return interceptorId;
    } catch (CannotCompileException ccex) {
        throw new InstrumentException("Failed to add interceptor " + interceptorClassName + " to " + behavior.getLongName(), ccex);
    } catch (NotFoundException nex) {
        throw new InstrumentException("Failed to add interceptor " + interceptorClassName + " to " + behavior.getLongName(), nex);
    }
}
Also used : NotFoundException(javassist.NotFoundException) CannotCompileException(javassist.CannotCompileException) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)

Example 33 with NotFoundException

use of javassist.NotFoundException in project pinpoint by naver.

the class JavassistMethod method insertCatch.

private void insertCatch(int from, String src, CtClass exceptionType, String exceptionName) throws CannotCompileException {
    CtClass cc = behavior.getDeclaringClass();
    ConstPool cp = behavior.getMethodInfo().getConstPool();
    CodeAttribute ca = behavior.getMethodInfo().getCodeAttribute();
    CodeIterator iterator = ca.iterator();
    Bytecode b = new Bytecode(cp, ca.getMaxStack(), ca.getMaxLocals());
    b.setStackDepth(1);
    Javac jv = new Javac(b, cc);
    try {
        jv.recordParams(behavior.getParameterTypes(), Modifier.isStatic(getModifiers()));
        jv.recordLocalVariables(ca, from);
        int var = jv.recordVariable(exceptionType, exceptionName);
        b.addAstore(var);
        jv.compileStmnt(src);
        int stack = b.getMaxStack();
        int locals = b.getMaxLocals();
        if (stack > ca.getMaxStack())
            ca.setMaxStack(stack);
        if (locals > ca.getMaxLocals())
            ca.setMaxLocals(locals);
        int len = iterator.getCodeLength();
        int pos = iterator.append(b.get());
        ca.getExceptionTable().add(from, len, len, cp.addClassInfo(exceptionType));
        iterator.append(b.getExceptionTable(), pos);
        behavior.getMethodInfo().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
    } catch (NotFoundException e) {
        throw new CannotCompileException(e);
    } catch (CompileError e) {
        throw new CannotCompileException(e);
    } catch (BadBytecode e) {
        throw new CannotCompileException(e);
    }
}
Also used : CompileError(javassist.compiler.CompileError) CtClass(javassist.CtClass) ConstPool(javassist.bytecode.ConstPool) Javac(javassist.compiler.Javac) CodeAttribute(javassist.bytecode.CodeAttribute) CodeIterator(javassist.bytecode.CodeIterator) NotFoundException(javassist.NotFoundException) BadBytecode(javassist.bytecode.BadBytecode) Bytecode(javassist.bytecode.Bytecode) CannotCompileException(javassist.CannotCompileException) BadBytecode(javassist.bytecode.BadBytecode)

Example 34 with NotFoundException

use of javassist.NotFoundException in project pinpoint by naver.

the class JavassistMethod method insertBeforeConstructor.

private int insertBeforeConstructor(int pos, String src) throws CannotCompileException {
    CtClass cc = behavior.getDeclaringClass();
    CodeAttribute ca = behavior.getMethodInfo().getCodeAttribute();
    CodeIterator iterator = ca.iterator();
    Bytecode b = new Bytecode(behavior.getMethodInfo().getConstPool(), ca.getMaxStack(), ca.getMaxLocals());
    b.setStackDepth(ca.getMaxStack());
    Javac jv = new Javac(b, cc);
    try {
        jv.recordParams(behavior.getParameterTypes(), false);
        jv.recordLocalVariables(ca, 0);
        jv.compileStmnt(src);
        ca.setMaxStack(b.getMaxStack());
        ca.setMaxLocals(b.getMaxLocals());
        iterator.skipConstructor();
        if (pos != -1) {
            iterator.insertEx(pos, b.get());
        } else {
            pos = iterator.insertEx(b.get());
        }
        iterator.insert(b.getExceptionTable(), pos);
        behavior.getMethodInfo().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
        return pos + b.length();
    } catch (NotFoundException e) {
        throw new CannotCompileException(e);
    } catch (CompileError e) {
        throw new CannotCompileException(e);
    } catch (BadBytecode e) {
        throw new CannotCompileException(e);
    }
}
Also used : CompileError(javassist.compiler.CompileError) CtClass(javassist.CtClass) Javac(javassist.compiler.Javac) CodeAttribute(javassist.bytecode.CodeAttribute) CodeIterator(javassist.bytecode.CodeIterator) NotFoundException(javassist.NotFoundException) BadBytecode(javassist.bytecode.BadBytecode) Bytecode(javassist.bytecode.Bytecode) CannotCompileException(javassist.CannotCompileException) BadBytecode(javassist.bytecode.BadBytecode)

Example 35 with NotFoundException

use of javassist.NotFoundException in project pinpoint by naver.

the class JavassistMethod method insertBeforeMethod.

private int insertBeforeMethod(int pos, String src) throws CannotCompileException {
    CtClass cc = behavior.getDeclaringClass();
    CodeAttribute ca = behavior.getMethodInfo().getCodeAttribute();
    if (ca == null)
        throw new CannotCompileException("no method body");
    CodeIterator iterator = ca.iterator();
    Javac jv = new Javac(cc);
    try {
        int nvars = jv.recordParams(behavior.getParameterTypes(), Modifier.isStatic(getModifiers()));
        jv.recordParamNames(ca, nvars);
        jv.recordLocalVariables(ca, 0);
        jv.recordType(getReturnType0());
        jv.compileStmnt(src);
        Bytecode b = jv.getBytecode();
        int stack = b.getMaxStack();
        int locals = b.getMaxLocals();
        if (stack > ca.getMaxStack())
            ca.setMaxStack(stack);
        if (locals > ca.getMaxLocals())
            ca.setMaxLocals(locals);
        if (pos != -1) {
            iterator.insertEx(pos, b.get());
        } else {
            pos = iterator.insertEx(b.get());
        }
        iterator.insert(b.getExceptionTable(), pos);
        behavior.getMethodInfo().rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
        return pos + b.length();
    } catch (NotFoundException e) {
        throw new CannotCompileException(e);
    } catch (CompileError e) {
        throw new CannotCompileException(e);
    } catch (BadBytecode e) {
        throw new CannotCompileException(e);
    }
}
Also used : CompileError(javassist.compiler.CompileError) CtClass(javassist.CtClass) Javac(javassist.compiler.Javac) CodeAttribute(javassist.bytecode.CodeAttribute) CodeIterator(javassist.bytecode.CodeIterator) NotFoundException(javassist.NotFoundException) BadBytecode(javassist.bytecode.BadBytecode) Bytecode(javassist.bytecode.Bytecode) CannotCompileException(javassist.CannotCompileException) BadBytecode(javassist.bytecode.BadBytecode)

Aggregations

NotFoundException (javassist.NotFoundException)39 CtClass (javassist.CtClass)28 CannotCompileException (javassist.CannotCompileException)20 CtMethod (javassist.CtMethod)18 ClassPool (javassist.ClassPool)14 IOException (java.io.IOException)6 CtField (javassist.CtField)5 EnhancementException (org.hibernate.bytecode.enhance.spi.EnhancementException)5 FileNotFoundException (java.io.FileNotFoundException)4 BadBytecode (javassist.bytecode.BadBytecode)4 CodeIterator (javassist.bytecode.CodeIterator)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Bytecode (javassist.bytecode.Bytecode)3 CodeAttribute (javassist.bytecode.CodeAttribute)3 CompileError (javassist.compiler.CompileError)3 Javac (javassist.compiler.Javac)3 FileFilter (java.io.FileFilter)2 CtBehavior (javassist.CtBehavior)2 CtConstructor (javassist.CtConstructor)2