Search in sources :

Example 1 with ASMBytecodeDisassembler

use of com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler 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 2 with ASMBytecodeDisassembler

use of com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler in project pinpoint by naver.

the class JavassistVerifyErrorTest method asm_stackmapframe_check.

@Test
public void asm_stackmapframe_check() throws Exception {
    CustomURLClassLoader classLoader = new CustomURLClassLoader(new URL[] {}, Thread.currentThread().getContextClassLoader());
    final InputStream stream = classLoader.getResourceAsStream(JavaAssistUtils.javaNameToJvmName(INVALID_STACK_MAP_FRAME) + ".class");
    ClassReader cr = new ClassReader(stream);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    ClassVisitor cv = new BytecodeVerifyTestClassVisitor(cw);
    cr.accept(cv, ClassReader.EXPAND_FRAMES | ClassReader.SKIP_DEBUG);
    byte[] bytecode = cw.toByteArray();
    classLoader.defineClass0(INVALID_STACK_MAP_FRAME, bytecode);
    final Class<?> aClass = Class.forName(INVALID_STACK_MAP_FRAME, true, classLoader);
    Assert.assertSame(aClass.getClassLoader(), classLoader);
    final ASMBytecodeDisassembler bytecodeDisassembler = new ASMBytecodeDisassembler();
    final String dumpBytecode = bytecodeDisassembler.dumpBytecode(bytecode);
    logger.debug("dumpBytecode:{}", dumpBytecode);
    final String verify = bytecodeDisassembler.dumpVerify(bytecode, classLoader);
    logger.debug("dumpVerify:{}", verify);
//        final String dumpAsm = bytecodeDisassembler.dumpASM(bytecode);
//        logger.debug("dumpAsm :{}", dumpAsm);
}
Also used : BytecodeVerifyTestClassVisitor(bug_regression_jdk7.javassist.asm.BytecodeVerifyTestClassVisitor) InputStream(java.io.InputStream) ASMBytecodeDisassembler(com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler) ClassReader(org.objectweb.asm.ClassReader) BytecodeVerifyTestClassVisitor(bug_regression_jdk7.javassist.asm.BytecodeVerifyTestClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Aggregations

ASMBytecodeDisassembler (com.navercorp.pinpoint.profiler.instrument.ASMBytecodeDisassembler)2 Test (org.junit.Test)2 BytecodeVerifyTestClassVisitor (bug_regression_jdk7.javassist.asm.BytecodeVerifyTestClassVisitor)1 InputStream (java.io.InputStream)1 ClassPool (javassist.ClassPool)1 CtClass (javassist.CtClass)1 CtMethod (javassist.CtMethod)1 LoaderClassPath (javassist.LoaderClassPath)1 Ignore (org.junit.Ignore)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1