Java Code Examples for org.objectweb.asm.MethodVisitor#visitTryCatchBlock()

The following examples show how to use org.objectweb.asm.MethodVisitor#visitTryCatchBlock() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gizmo   File: TryBlockImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void writeOperations(final MethodVisitor visitor) {
    // this is everything between top & bottom labels
    super.writeOperations(visitor);
    // this is outside of the "try"
    if (getTop().getOffset() != getBottom().getOffset()) {
        // only generate catch blocks if the try body is non-empty
        final Label foot = new Label();
        visitor.visitJumpInsn(Opcodes.GOTO, foot);
        for (Map.Entry<String, CatchBlockCreatorImpl> entry : catchBlocks.entrySet()) {
            final CatchBlockCreatorImpl value = entry.getValue();
            value.writeOperations(visitor);
            visitor.visitJumpInsn(Opcodes.GOTO, foot);
            visitor.visitTryCatchBlock(getTop(), getBottom(), value.getTop(), entry.getKey());
        }
        visitor.visitLabel(foot);
    }
}
 
Example 2
Source Project: glowroot   File: WeavingClassVisitor.java    License: Apache License 2.0 6 votes vote down vote up
private static void addLoadClassConditional(MethodVisitor mv, Object[] locals) {
    Label label0 = new Label();
    Label label1 = new Label();
    Label label2 = new Label();
    mv.visitTryCatchBlock(label0, label1, label2, "java/lang/ClassNotFoundException");
    mv.visitVarInsn(ALOAD, 1);
    mv.visitLdcInsn("org.glowroot.agent");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z",
            false);
    Label label3 = new Label();
    mv.visitJumpInsn(IFEQ, label3);
    mv.visitLabel(label0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(ICONST_0);
    mv.visitInsn(ACONST_NULL);
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName",
            "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;", false);
    mv.visitLabel(label1);
    mv.visitInsn(ARETURN);
    mv.visitLabel(label2);
    mv.visitFrame(F_NEW, locals.length, locals, 1,
            new Object[] {"java/lang/ClassNotFoundException"});
    mv.visitInsn(POP);
    mv.visitLabel(label3);
    mv.visitFrame(F_NEW, locals.length, locals, 0, new Object[0]);
}
 
Example 3
@Test
public void testNormalTryCatch() throws Exception {
    String testClassName = "TestClass";
    ClassWriter writer = new ClassWriter(0);
    TryCatchCountingVisitor counter = new TryCatchCountingVisitor(writer);
    LoopingExceptionStrippingVisitor visitor = new LoopingExceptionStrippingVisitor();
    visitor.setDelegate(counter);
    visitor.visit(Opcodes.V10, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, testClassName, null, "java/lang/Object", null);
    
    // Create our labels.
    Label start = new Label();
    Label end = new Label();
    Label handler = new Label();
    String type = null;
    
    // Write a target method.
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_STATIC, "targetMethod", "()V", null, null);
    methodVisitor.visitCode();
    methodVisitor.visitInsn(Opcodes.ACONST_NULL);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitLabel(start);
    methodVisitor.visitInsn(Opcodes.ACONST_NULL);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitLabel(end);
    methodVisitor.visitLabel(handler);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitTryCatchBlock(start, end, handler, type);
    methodVisitor.visitMaxs(1, 0);
    methodVisitor.visitEnd();
    
    // Finish.
    visitor.visitEnd();
    
    Assert.assertEquals(1, counter.counter);
}
 
Example 4
@Test
public void testBackwardFinally() throws Exception {
    String testClassName = "TestClass";
    ClassWriter writer = new ClassWriter(0);
    TryCatchCountingVisitor counter = new TryCatchCountingVisitor(writer);
    LoopingExceptionStrippingVisitor visitor = new LoopingExceptionStrippingVisitor();
    visitor.setDelegate(counter);
    visitor.visit(Opcodes.V10, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, testClassName, null, "java/lang/Object", null);
    
    // Create our labels.
    Label methodStart = new Label();
    Label start = new Label();
    Label end = new Label();
    Label handler = new Label();
    String type = null;
    
    // Write a target method.
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_STATIC, "targetMethod", "()V", null, null);
    methodVisitor.visitCode();
    methodVisitor.visitJumpInsn(Opcodes.GOTO, methodStart);
    methodVisitor.visitLabel(handler);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitLabel(methodStart);
    methodVisitor.visitInsn(Opcodes.ACONST_NULL);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitLabel(start);
    methodVisitor.visitInsn(Opcodes.ACONST_NULL);
    methodVisitor.visitInsn(Opcodes.POP);
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitLabel(end);
    methodVisitor.visitTryCatchBlock(start, end, handler, type);
    methodVisitor.visitMaxs(1, 0);
    methodVisitor.visitEnd();
    
    // Finish.
    visitor.visitEnd();
    
    Assert.assertEquals(0, counter.counter);
}
 
Example 5
Source Project: HttpSessionReplacer   File: CommonHelpers.java    License: MIT License 5 votes vote down vote up
static void addIsServlet3(ClassVisitor cw) {
  FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "$$isServlet3", "Z", null, null);
  fv.visitEnd();

  MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "$$isServlet3", "()Z", null, null);
  mv.visitCode();
  Label l0 = new Label();
  Label l1 = new Label();
  Label l2 = new Label();
  mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException");
  mv.visitLabel(l0);
  mv.visitLineNumber(446, l0);
  mv.visitLdcInsn(Type.getType("Ljavax/servlet/ServletRequest;"));
  mv.visitLdcInsn("startAsync");
  mv.visitInsn(ICONST_0);
  mv.visitTypeInsn(ANEWARRAY, "java/lang/Class");
  mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethod",
      "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false);
  mv.visitInsn(POP);
  mv.visitLabel(l1);
  mv.visitLineNumber(447, l1);
  mv.visitInsn(ICONST_1);
  mv.visitInsn(IRETURN);
  mv.visitLabel(l2);
  mv.visitLineNumber(448, l2);
  mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" });
  mv.visitVarInsn(ASTORE, 0);
  Label l3 = new Label();
  mv.visitLabel(l3);
  mv.visitLineNumber(449, l3);
  mv.visitInsn(ICONST_0);
  mv.visitInsn(IRETURN);
  Label l4 = new Label();
  mv.visitLabel(l4);
  mv.visitLocalVariable("e", "Ljava/lang/NoSuchMethodException;", null, l3, l4, 0);
  mv.visitMaxs(3, 1);
  mv.visitEnd();
}
 
Example 6
Source Project: yql-plus   File: ExpressionHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BytecodeExpression fallback(Location loc, final BytecodeExpression primary, final BytecodeExpression caught) {
    TypeWidget unified = unify(primary.getType(), caught.getType());
    return new BaseTypeExpression(unified) {
        @Override
        public void generate(CodeEmitter code) {
            MethodVisitor mv = code.getMethodVisitor();
            final Label start = new Label();
            final Label endCatch = new Label();
            final Label handler = new Label();
            Label done = new Label();
            // this probably should not be catching throwable and instead should be catching Exception
            // or permit certain Errors through only
            mv.visitTryCatchBlock(start, endCatch, handler, "java/lang/Throwable");
            mv.visitLabel(start);
            code.exec(primary);
            Label isNull = new Label();
            boolean maybeNull = code.cast(getType(), primary.getType(), isNull);
            mv.visitJumpInsn(Opcodes.GOTO, done);
            mv.visitLabel(endCatch);
            mv.visitLabel(handler);
            mv.visitInsn(Opcodes.POP);
            if (maybeNull) {
                mv.visitLabel(isNull);
            }
            code.exec(caught);
            code.cast(getType(), caught.getType());
            mv.visitLabel(done);
        }
    };
}
 
Example 7
Source Project: groovy   File: CompileStack.java    License: Apache License 2.0 5 votes vote down vote up
public void writeExceptionTable(final BlockRecorder block, final Label goal, final String sig) {
    if (block.isEmpty) return;
    MethodVisitor mv = controller.getMethodVisitor();
    for (LabelRange range : block.ranges) {
        mv.visitTryCatchBlock(range.start, range.end, goal, sig);
    }
}
 
Example 8
Source Project: Concurnas   File: Globalizer.java    License: MIT License 4 votes vote down vote up
public void visitEnd() {
  	if(!visitedClinit   ){//didnt have a clinit, so create a simple init and getter now...
  		if(!this.staticFinalVars.isEmpty()) {
  			addInitforStaticFinalVars();
  			createInializerAndSupportMethods(true);
  		}else {
   		createInializerAndSupportMethods(false);
  		}
  		//TODO: this code is only really useful in case where u do this class X{ fromouter = 99 class Y{ y = 1 + fromouter }} //since fromouter is from psar which is static...
  		addEmptyInit();
  	}
  	
  	
if(!shareInitsToMake.isEmpty()) {

	String origClassName = this.fromName;//this.className.peek();
	String globalClass = this.globName;//this.origClassClinitToNewOne.get(origClassName);
	
	for(String sharedinit : shareInitsToMake) {
		String initOnceVarName = sharedinit + "$onceVar";
		{
			FieldVisitor fv = super.visitField(ACC_PRIVATE + ACC_VOLATILE + ACC_STATIC, initOnceVarName, "Ljava/lang/Object;", null, null);
		    fv.visitEnd();
		}
		
		{
			MethodVisitor mv = super.visitMethod(ACC_PUBLIC, sharedinit, "()V", null, null);
			mv.visitCode();
			Label l0 = new Label();
			Label l1 = new Label();
			Label l2 = new Label();
			mv.visitTryCatchBlock(l0, l1, l2, null);
			Label l3 = new Label();
			mv.visitTryCatchBlock(l2, l3, l2, null);
			Label l4 = new Label();
			mv.visitLabel(l4);
			mv.visitFieldInsn(GETSTATIC, globalClass, initOnceVarName, "Ljava/lang/Object;");
			Label l5 = new Label();
			mv.visitJumpInsn(IFNONNULL, l5);
			Label l6 = new Label();
			mv.visitLabel(l6);
			mv.visitVarInsn(ALOAD, 0);
			mv.visitInsn(DUP);
			mv.visitVarInsn(ASTORE, 1);
			mv.visitInsn(MONITORENTER);
			mv.visitLabel(l0);
			mv.visitFieldInsn(GETSTATIC, globalClass, initOnceVarName, "Ljava/lang/Object;");
			Label l7 = new Label();
			mv.visitJumpInsn(IFNONNULL, l7);
			Label l8 = new Label();
			mv.visitLabel(l8);
			mv.visitIntInsn(BIPUSH, 111);
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
			mv.visitFieldInsn(PUTSTATIC, globalClass, initOnceVarName, "Ljava/lang/Object;");
			Label l9 = new Label();
			mv.visitLabel(l9);
			mv.visitMethodInsn(INVOKESTATIC, origClassName, sharedinit, "()V", false);//this is called only once
			mv.visitLabel(l7);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitInsn(MONITOREXIT);
			mv.visitLabel(l1);
			mv.visitJumpInsn(GOTO, l5);
			mv.visitLabel(l2);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitInsn(MONITOREXIT);
			mv.visitLabel(l3);
			mv.visitInsn(ATHROW);
			mv.visitLabel(l5);
			mv.visitInsn(RETURN);
			mv.visitMaxs(2, 2);
			mv.visitEnd();
		}
	}
}
  	
  	super.visitEnd();
  }
 
Example 9
private static byte[] gen(final String name, final String exName) { // "cpw/mods/fml/SafeExitJVMLegacy", "exit"

        final ClassWriter classWriter = new ClassWriter(0);
        MethodVisitor methodVisitor;

        classWriter.visit(V1_8, ACC_PUBLIC | ACC_SUPER, name, null, "java/lang/Object", null);

        {
            methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            methodVisitor.visitCode();
            methodVisitor.visitVarInsn(ALOAD, 0);
            methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
            methodVisitor.visitInsn(RETURN);
            methodVisitor.visitMaxs(1, 1);
            methodVisitor.visitEnd();
        }
        {
            methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_STATIC, exName, "(I)V", null, null);
            methodVisitor.visitCode();
            final Label label0 = new Label();
            final Label label1 = new Label();
            final Label label2 = new Label();
            methodVisitor.visitTryCatchBlock(label0, label1, label2, "java/lang/Throwable");
            methodVisitor.visitLabel(label0);
            methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;",
                    false);
            methodVisitor.visitVarInsn(ILOAD, 0);
            methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false);
            methodVisitor.visitLabel(label1);
            final Label label3 = new Label();
            methodVisitor.visitJumpInsn(GOTO, label3);
            methodVisitor.visitLabel(label2);
            methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[]{"java/lang/Throwable"});
            methodVisitor.visitVarInsn(ASTORE, 1);
            methodVisitor.visitVarInsn(ILOAD, 0);
            methodVisitor.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false);
            methodVisitor.visitLabel(label3);
            methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
            methodVisitor.visitInsn(RETURN);
            methodVisitor.visitMaxs(2, 2);
            methodVisitor.visitEnd();
        }
        classWriter.visitEnd();
        return classWriter.toByteArray();
    }
 
Example 10
private static void tryBlockForPlatform(MethodVisitor methodVisitor, String platformType) {
  methodVisitor.visitCode();

  // Generate the enveloping try/catch block:
  //
  //   try {
  //     ...
  //   } catch (NoClassDefFoundError | IllegalAccessException | InstantiationException
  //       | InvocationTargetException | NoSuchMethodException e) {
  //     ...
  //   }
  //
  // Note that the exception types need to be listed explicitly (rather than using
  // java.lang.ReflectiveOperationException) because that parent exception type isn't available
  // on Android until API level 19.
  Label startLabel = new Label();
  Label endLabel = new Label();
  Label handlerLabel = new Label();
  methodVisitor.visitTryCatchBlock(
      startLabel, endLabel, handlerLabel, "java/lang/NoClassDefFoundError");
  methodVisitor.visitTryCatchBlock(
      startLabel, endLabel, handlerLabel, "java/lang/IllegalAccessException");
  methodVisitor.visitTryCatchBlock(
      startLabel, endLabel, handlerLabel, "java/lang/InstantiationException");
  methodVisitor.visitTryCatchBlock(
      startLabel, endLabel, handlerLabel, "java/lang/reflect/InvocationTargetException");
  methodVisitor.visitTryCatchBlock(
      startLabel, endLabel, handlerLabel, "java/lang/NoSuchMethodException");
  methodVisitor.visitLabel(startLabel);

  // Generate the actual reflective constructor call inside the try block:
  //
  //   return (Platform) PlatformClass.class.getDeclaredConstructor().newInstance();
  //
  // Note that the constructor call happens reflectively to make sure that the platform class
  // isn't loaded until actually executing this instruction. That is important because an
  // earlier class load could happen outside of the try/catch block where we are explicitly
  // handling the case of the class not being present.
  methodVisitor.visitLdcInsn(Type.getType(platformType));
  methodVisitor.visitInsn(ICONST_0);
  methodVisitor.visitTypeInsn(ANEWARRAY, "java/lang/Class");
  methodVisitor.visitMethodInsn(
      INVOKEVIRTUAL,
      "java/lang/Class",
      "getDeclaredConstructor",
      "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;",
      false);
  methodVisitor.visitInsn(ICONST_0);
  methodVisitor.visitTypeInsn(ANEWARRAY, "java/lang/Object");
  methodVisitor.visitMethodInsn(
      INVOKEVIRTUAL,
      "java/lang/reflect/Constructor",
      "newInstance",
      "([Ljava/lang/Object;)Ljava/lang/Object;",
      false);
  methodVisitor.visitTypeInsn(CHECKCAST, "com/google/common/flogger/backend/Platform");
  methodVisitor.visitLabel(endLabel);
  methodVisitor.visitInsn(ARETURN);

  // Generate the catch block of the overall try/catch. The catch block is actually just empty,
  // but Java does require the catch handler to have at least a frame in it to declare the
  // exception variable that is available within the catch block scope:
  // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-3.html#jvms-3.12
  methodVisitor.visitLabel(handlerLabel);
  methodVisitor.visitFrame(F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"});
  methodVisitor.visitVarInsn(ASTORE, 0);
}
 
Example 11
public void visit(MethodVisitor mv) {
  mv.visitTryCatchBlock(label, label1, label2, type);
}
 
Example 12
private static void visitBlockStructured(ClassWriter cw, boolean normalReturnError, boolean tooMany) {
    String name = (tooMany ? "tooMany" : "tooFew") + "Exits" + (normalReturnError ? "" : "Exceptional");
    // Generate too many or too few exits down the either the normal or exceptional return paths
    int exceptionalExitCount = normalReturnError ? 1 : (tooMany ? 2 : 0);
    int normalExitCount = normalReturnError ? (tooMany ? 2 : 0) : 1;
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, name, "(Ljava/lang/Object;Ljava/lang/Object;)Z", null, null);
    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    mv.visitTryCatchBlock(l2, l3, l2, null);
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    mv.visitTryCatchBlock(l4, l5, l6, null);
    Label l7 = new Label();
    mv.visitTryCatchBlock(l2, l7, l6, null);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l1);
    for (int i = 0; i < normalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l5);
    mv.visitInsn(IRETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
                    "java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l3);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
                    new Object[]{"java/lang/Throwable"});
    for (int i = 0; i < exceptionalExitCount; i++) {
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(MONITOREXIT);
    }
    mv.visitLabel(l7);
    mv.visitInsn(ATHROW);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
}
 
Example 13
private static void visitWrongOrder(ClassWriter cw) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "wrongOrder", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    mv.visitTryCatchBlock(l2, l3, l2, null);
    Label l4 = new Label();
    Label l5 = new Label();
    Label l6 = new Label();
    mv.visitTryCatchBlock(l4, l5, l6, null);
    Label l7 = new Label();
    mv.visitTryCatchBlock(l2, l7, l6, null);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 3);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 4);
    mv.visitInsn(MONITORENTER);
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitVarInsn(ALOAD, 3);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l1);
    // Swapped exit order with exit above
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l5);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 5, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object",
                    "java/lang/Object"}, 1, new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 4);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l3);
    mv.visitInsn(ATHROW);
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_FULL, 4, new Object[]{INNER_CLASS_NAME_INTERNAL, "java/lang/Object", "java/lang/Object", "java/lang/Object"}, 1,
                    new Object[]{"java/lang/Throwable"});
    mv.visitVarInsn(ALOAD, 3);
    mv.visitInsn(MONITOREXIT);
    mv.visitLabel(l7);
    mv.visitInsn(ATHROW);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitMaxs(2, 5);
    mv.visitEnd();
}
 
Example 14
@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
    final String[] exceptions) {
    final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);

    final String signCode = getBehaviorSignCode(name, desc);
    if (!isMatchedBehavior(signCode)) {
        return mv;
    }


    return new ThirdReWriteMethod(api, mv) {
        @Override
        public void visitInsn(final int opcode) {
            switch (opcode) {
                case RETURN:
                case IRETURN:
                case FRETURN:
                case ARETURN:
                case LRETURN:
                case DRETURN:
                    onExit();
                    break;
                default:
                    break;
            }
            super.visitInsn(opcode);
        }

        private void onExit() {
            Label startTryBlock = new Label();
            Label endTryBlock = new Label();
            Label startCatchBlock = new Label();
            Label endCatchBlock = new Label();
            mv.visitLabel(startTryBlock);
            //静态调用
            Type type = Type.getType(Math.class);
            String owner = type.getInternalName();
            mv.visitMethodInsn(INVOKESTATIC, owner, method.getName(), method.getDescriptor(), false);
            mv.visitInsn(POP2);
            mv.visitLabel(endTryBlock);
            mv.visitJumpInsn(GOTO,endCatchBlock);
            mv.visitLabel(startCatchBlock);
            mv.visitInsn(POP);
            mv.visitLabel(endCatchBlock);
            mv.visitTryCatchBlock(startTryBlock,endTryBlock,startCatchBlock,ASM_TYPE_THROWABLE.getInternalName());
        }
    };
}
 
Example 15
Source Project: HttpSessionReplacer   File: FilterAdapter.java    License: MIT License 4 votes vote down vote up
private void addInitMethod() {
  MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "init", "(Ljavax/servlet/FilterConfig;)V", null,
      new String[] { "javax/servlet/ServletException" });
  mv.visitCode();
  Label l0 = new Label();
  Label l1 = new Label();
  Label l2 = new Label();
  mv.visitTryCatchBlock(l0, l1, l2, "javax/servlet/ServletException");
  Label l3 = new Label();
  mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Throwable");
  Label l4 = new Label();
  mv.visitLabel(l4);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitMethodInsn(INVOKEVIRTUAL, filterClass, "$$injected_initForSession", "(Ljavax/servlet/FilterConfig;)V", false);
  Label l5 = new Label();
  mv.visitLabel(l5);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_superInit", "Ljava/lang/invoke/MethodHandle;");
  Label l6 = new Label();
  mv.visitJumpInsn(IFNULL, l6);
  mv.visitLabel(l0);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_superInit", "Ljava/lang/invoke/MethodHandle;");
  mv.visitVarInsn(ALOAD, 0);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact",
      "(L" + filterClass + ";Ljavax/servlet/FilterConfig;)V", false);
  mv.visitLabel(l1);
  mv.visitJumpInsn(GOTO, l6);
  mv.visitLabel(l2);
  mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "javax/servlet/ServletException" });
  mv.visitVarInsn(ASTORE, 2);
  Label l7 = new Label();
  mv.visitLabel(l7);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitInsn(ATHROW);
  mv.visitLabel(l3);
  mv.visitLineNumber(1, l3);
  mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
  mv.visitVarInsn(ASTORE, 2);
  Label l8 = new Label();
  mv.visitLabel(l8);
  mv.visitLineNumber(1, l8);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitTypeInsn(INSTANCEOF, "java/lang/Error");
  Label l9 = new Label();
  mv.visitJumpInsn(IFEQ, l9);
  Label l10 = new Label();
  mv.visitLabel(l10);
  mv.visitLineNumber(1, l10);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitTypeInsn(CHECKCAST, "java/lang/Error");
  mv.visitInsn(ATHROW);
  mv.visitLabel(l9);
  mv.visitLineNumber(1, l9);
  mv.visitFrame(F_APPEND, 1, new Object[] { "java/lang/Throwable" }, 0, null);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException");
  Label l11 = new Label();
  mv.visitJumpInsn(IFEQ, l11);
  Label l12 = new Label();
  mv.visitLabel(l12);
  mv.visitLineNumber(1, l12);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException");
  mv.visitInsn(ATHROW);
  mv.visitLabel(l11);
  mv.visitLineNumber(1, l11);
  mv.visitFrame(F_SAME, 0, null, 0, null);
  mv.visitTypeInsn(NEW, "javax/servlet/ServletException");
  mv.visitInsn(DUP);
  mv.visitLdcInsn("An exception occured while invoking super-class method init");
  mv.visitVarInsn(ALOAD, 2);
  mv.visitMethodInsn(INVOKESPECIAL, "javax/servlet/ServletException", "<init>",
      "(Ljava/lang/String;Ljava/lang/Throwable;)V", false);
  mv.visitInsn(ATHROW);
  mv.visitLabel(l6);
  mv.visitLineNumber(1, l6);
  mv.visitFrame(F_CHOP, 1, null, 0, null);
  mv.visitInsn(RETURN);
  Label l13 = new Label();
  mv.visitLabel(l13);
  mv.visitLocalVariable("this", "L" + filterClass + ";", null, l4, l13, 0);
  mv.visitLocalVariable("config", "Ljavax/servlet/FilterConfig;", null, l4, l13, 1);
  mv.visitLocalVariable("e", "Ljavax/servlet/ServletException;", null, l7, l3, 2);
  mv.visitLocalVariable("e", "Ljava/lang/Throwable;", null, l8, l6, 2);
  mv.visitMaxs(4, 3);
  mv.visitEnd();
}
 
Example 16
Source Project: HttpSessionReplacer   File: FilterAdapter.java    License: MIT License 4 votes vote down vote up
/**
 * This method injects new doFilter method into the class.
 */
private void addDoFilter() {
  MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "doFilter",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V", null,
      new String[] { "java/io/IOException", "javax/servlet/ServletException" });
  mv.visitCode();
  Label l0 = new Label();
  Label l1 = new Label();
  mv.visitTryCatchBlock(l0, l1, l1, null);
  Label l2 = new Label();
  mv.visitLabel(l2);
  mv.visitLineNumber(1, l2);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitVarInsn(ASTORE, 4);
  Label l3 = new Label();
  mv.visitLabel(l3);
  mv.visitLineNumber(1, l3);
  mv.visitVarInsn(ALOAD, 4);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_servletContext", "Ljavax/servlet/ServletContext;");
  mv.visitMethodInsn(INVOKESTATIC, filterClass, "$$prepareRequest",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/ServletContext;)Ljavax/servlet/ServletRequest;",
      false);
  mv.visitVarInsn(ASTORE, 1);
  Label l4 = new Label();
  mv.visitLabel(l4);
  mv.visitLineNumber(1, l4);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_servletContext", "Ljavax/servlet/ServletContext;");
  mv.visitMethodInsn(INVOKESTATIC, filterClass, "$$prepareResponse",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/ServletContext;)Ljavax/servlet/ServletResponse;", false);
  mv.visitVarInsn(ASTORE, 2);
  mv.visitLabel(l0);
  mv.visitLineNumber(1, l0);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitVarInsn(ALOAD, 2);
  mv.visitVarInsn(ALOAD, 3);
  mv.visitMethodInsn(INVOKEVIRTUAL, filterClass, "$$renamed_doFilter",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V", false);
  Label l5 = new Label();
  mv.visitLabel(l5);
  mv.visitLineNumber(1, l5);
  Label l6 = new Label();
  mv.visitJumpInsn(GOTO, l6);
  mv.visitLabel(l1);
  mv.visitFrame(F_FULL, 5, new Object[] { filterClass, "javax/servlet/ServletRequest",
      "javax/servlet/ServletResponse", "javax/servlet/FilterChain", "javax/servlet/ServletRequest" }, 1,
      new Object[] { "java/lang/Throwable" });
  mv.visitVarInsn(ASTORE, 5);
  Label l7 = new Label();
  mv.visitLabel(l7);
  mv.visitLineNumber(1, l7);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitVarInsn(ALOAD, 4);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_servletContext", "Ljavax/servlet/ServletContext;");
  mv.visitMethodInsn(INVOKESTATIC, filterClass, "$$commitRequest",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletContext;)V", false);
  Label l8 = new Label();
  mv.visitLabel(l8);
  mv.visitLineNumber(1, l8);
  mv.visitVarInsn(ALOAD, 5);
  mv.visitInsn(ATHROW);
  mv.visitLabel(l6);
  mv.visitLineNumber(1, l6);
  mv.visitFrame(F_SAME, 0, null, 0, null);
  mv.visitVarInsn(ALOAD, 1);
  mv.visitVarInsn(ALOAD, 4);
  mv.visitVarInsn(ALOAD, 0);
  mv.visitFieldInsn(GETFIELD, filterClass, "$$injected_servletContext", "Ljavax/servlet/ServletContext;");
  mv.visitMethodInsn(INVOKESTATIC, filterClass, "$$commitRequest",
      "(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletContext;)V", false);
  Label l9 = new Label();
  mv.visitLabel(l9);
  mv.visitLineNumber(1, l9);
  mv.visitInsn(RETURN);
  Label l10 = new Label();
  mv.visitLabel(l10);
  mv.visitLocalVariable("this", "L" + filterClass + ";", null, l2, l10, 0);
  mv.visitLocalVariable("request", "Ljavax/servlet/ServletRequest;", null, l2, l10, 1);
  mv.visitLocalVariable("response", "Ljavax/servlet/ServletResponse;", null, l2, l10, 2);
  mv.visitLocalVariable("chain", "Ljavax/servlet/FilterChain;", null, l2, l10, 3);
  mv.visitLocalVariable("oldRequest", "Ljavax/servlet/ServletRequest;", null, l3, l10, 4);
  mv.visitMaxs(4, 6);
  mv.visitEnd();
}
 
Example 17
Source Project: Despector   File: TryCatchTests.java    License: MIT License 4 votes vote down vote up
@Test
public void testTryMultiCatch() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    Label l4 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NullPointerException");
    mv.visitTryCatchBlock(l0, l1, l3, "java/lang/OutOfMemoryError");
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, l4);
    mv.visitLabel(l2);
    mv.visitVarInsn(ASTORE, 2);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NullPointerException", "printStackTrace", "()V", false);
    mv.visitJumpInsn(GOTO, l4);
    mv.visitLabel(l3);
    mv.visitVarInsn(ASTORE, 2);
    mv.visitVarInsn(ALOAD, 2);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/OutOfMemoryError", "printStackTrace", "()V", false);
    mv.visitLabel(l4);
    mv.visitInsn(RETURN);
    Label l5 = new Label();
    mv.visitLabel(l5);
    mv.visitLocalVariable("e", "Ljava/lang/NullPointerException;", null, l2, l3, 2);
    mv.visitLocalVariable("e", "Ljava/lang/OutOfMemoryError;", null, l3, l4, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "try {\n"
            + "    org.spongepowered.test.decompile.TryCatchTests.body();\n"
            + "} catch (NullPointerException e) {\n"
            + "    e.printStackTrace();\n"
            + "} catch (OutOfMemoryError e) {\n"
            + "    e.printStackTrace();\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 18
public static byte[] dump() throws Exception {

		ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
		FieldVisitor fv;
		MethodVisitor mv;
		AnnotationVisitor av0;

		cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER,
				"com/beetl/performance/lab/asm/UserAsmAccessor1", null,
				"java/lang/Object",
				new String[] { "com/beetl/performance/lab/asm/Access" });

		{
			mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
			mv.visitCode();
			mv.visitVarInsn(ALOAD, 0);
			mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
					"()V");
			mv.visitInsn(RETURN);
			mv.visitMaxs(1, 1);
			mv.visitEnd();
		}
		{
			mv = cw.visitMethod(
					ACC_PUBLIC,
					"get",
					"(Ljava/lang/Object;I)Ljava/lang/Object;",
					null,
					new String[] { "com/beetl/performance/lab/asm/ASMCastException" });
			mv.visitCode();
			Label l0 = new Label();
			Label l1 = new Label();
			Label l2 = new Label();
			mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
			mv.visitInsn(ACONST_NULL);
			mv.visitVarInsn(ASTORE, 3);
			mv.visitLabel(l0);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitTypeInsn(CHECKCAST, "com/beetl/performance/lab/User");
			mv.visitVarInsn(ASTORE, 3);
			mv.visitLabel(l1);
			Label l3 = new Label();
			mv.visitJumpInsn(GOTO, l3);
			mv.visitLabel(l2);
			mv.visitFrame(Opcodes.F_FULL, 4, new Object[] {
					"com/beetl/performance/lab/asm/UserAsmAccessor",
					"java/lang/Object", Opcodes.INTEGER,
					"com/beetl/performance/lab/User" }, 1,
					new Object[] { "java/lang/Exception" });
			mv.visitVarInsn(ASTORE, 4);
			mv.visitTypeInsn(NEW,
					"com/beetl/performance/lab/asm/ASMCastException");
			mv.visitInsn(DUP);
			mv.visitMethodInsn(INVOKESPECIAL,
					"com/beetl/performance/lab/asm/ASMCastException", "<init>",
					"()V");
			mv.visitInsn(ATHROW);
			mv.visitLabel(l3);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ILOAD, 2);
			Label l4 = new Label();
			Label l5 = new Label();
			Label l6 = new Label();
			mv.visitTableSwitchInsn(1, 2, l6, new Label[] { l4, l5 });
			mv.visitLabel(l4);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/beetl/performance/lab/User",
					"getName", "()Ljava/lang/String;");
			mv.visitInsn(ARETURN);
			mv.visitLabel(l5);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/beetl/performance/lab/User",
					"getId", "()I");
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf",
					"(I)Ljava/lang/Integer;");
			mv.visitInsn(ARETURN);
			mv.visitLabel(l6);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
			mv.visitInsn(DUP);
			mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException",
					"<init>", "()V");
			mv.visitInsn(ATHROW);
			mv.visitMaxs(2, 5);
			mv.visitEnd();
		}
		cw.visitEnd();

		return cw.toByteArray();
	}
 
Example 19
Source Project: Despector   File: TryCatchTests.java    License: MIT License 4 votes vote down vote up
@Test
public void testTryCatchNested() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    Label l4 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
    mv.visitTryCatchBlock(l0, l3, l4, "java/lang/NullPointerException");
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, THIS_TYPE.getInternalName(), "body", "()V", false);
    mv.visitLabel(l1);
    Label l5 = new Label();
    mv.visitJumpInsn(GOTO, l5);
    mv.visitLabel(l2);
    mv.visitVarInsn(ASTORE, 3);
    Label l6 = new Label();
    mv.visitLabel(l6);
    mv.visitVarInsn(ALOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V", false);
    mv.visitLabel(l3);
    mv.visitJumpInsn(GOTO, l5);
    mv.visitLabel(l4);
    mv.visitVarInsn(ASTORE, 3);
    Label l7 = new Label();
    mv.visitLabel(l7);
    mv.visitVarInsn(ALOAD, 3);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NullPointerException", "printStackTrace", "()V", false);
    mv.visitLabel(l5);
    mv.visitInsn(RETURN);
    Label l8 = new Label();
    mv.visitLabel(l8);
    mv.visitLocalVariable("e", "Ljava/lang/Exception;", null, l6, l3, 3);
    mv.visitLocalVariable("e", "Ljava/lang/NullPointerException;", null, l7, l5, 3);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "try {\n"
            + "    try {\n"
            + "        org.spongepowered.test.decompile.TryCatchTests.body();\n"
            + "    } catch (Exception e) {\n"
            + "        e.printStackTrace();\n"
            + "    }\n"
            + "} catch (NullPointerException e) {\n"
            + "    e.printStackTrace();\n"
            + "}";
    Assert.assertEquals(good, insn);
}
 
Example 20
public static byte[] dump() throws Exception {

		ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
		FieldVisitor fv;
		MethodVisitor mv;
		AnnotationVisitor av0;

		cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER,
				"com/beetl/performance/lab/asm/UserAsmAccessor1", null,
				"java/lang/Object",
				new String[] { "com/beetl/performance/lab/asm/Access" });

		{
			mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
			mv.visitCode();
			mv.visitVarInsn(ALOAD, 0);
			mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
					"()V");
			mv.visitInsn(RETURN);
			mv.visitMaxs(1, 1);
			mv.visitEnd();
		}
		{
			mv = cw.visitMethod(
					ACC_PUBLIC,
					"get",
					"(Ljava/lang/Object;I)Ljava/lang/Object;",
					null,
					new String[] { "com/beetl/performance/lab/asm/ASMCastException" });
			mv.visitCode();
			Label l0 = new Label();
			Label l1 = new Label();
			Label l2 = new Label();
			mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
			mv.visitInsn(ACONST_NULL);
			mv.visitVarInsn(ASTORE, 3);
			mv.visitLabel(l0);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitTypeInsn(CHECKCAST, "com/beetl/performance/lab/User");
			mv.visitVarInsn(ASTORE, 3);
			mv.visitLabel(l1);
			Label l3 = new Label();
			mv.visitJumpInsn(GOTO, l3);
			mv.visitLabel(l2);
			mv.visitFrame(Opcodes.F_FULL, 4, new Object[] {
					"com/beetl/performance/lab/asm/UserAsmAccessor",
					"java/lang/Object", Opcodes.INTEGER,
					"com/beetl/performance/lab/User" }, 1,
					new Object[] { "java/lang/Exception" });
			mv.visitVarInsn(ASTORE, 4);
			mv.visitTypeInsn(NEW,
					"com/beetl/performance/lab/asm/ASMCastException");
			mv.visitInsn(DUP);
			mv.visitMethodInsn(INVOKESPECIAL,
					"com/beetl/performance/lab/asm/ASMCastException", "<init>",
					"()V");
			mv.visitInsn(ATHROW);
			mv.visitLabel(l3);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ILOAD, 2);
			Label l4 = new Label();
			Label l5 = new Label();
			Label l6 = new Label();
			mv.visitTableSwitchInsn(1, 2, l6, new Label[] { l4, l5 });
			mv.visitLabel(l4);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/beetl/performance/lab/User",
					"getName", "()Ljava/lang/String;");
			mv.visitInsn(ARETURN);
			mv.visitLabel(l5);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/beetl/performance/lab/User",
					"getId", "()I");
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf",
					"(I)Ljava/lang/Integer;");
			mv.visitInsn(ARETURN);
			mv.visitLabel(l6);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
			mv.visitInsn(DUP);
			mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException",
					"<init>", "()V");
			mv.visitInsn(ATHROW);
			mv.visitMaxs(2, 5);
			mv.visitEnd();
		}
		cw.visitEnd();

		return cw.toByteArray();
	}