List of usage examples for org.objectweb.asm MethodVisitor visitTryCatchBlock
public void visitTryCatchBlock(final Label start, final Label end, final Label handler, final String type)
From source file:com.googlecode.ddom.weaver.asm.MethodVisitorTee.java
License:Apache License
public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { for (MethodVisitor visitor : visitors) { visitor.visitTryCatchBlock(start, end, handler, type); }//w w w. java2s .c o m }
From source file:com.ibm.layout.ImplHelper.java
License:Open Source License
static void genLayoutTypeImpl(ClassVisitor cw, MethodVisitor mv, FieldVisitor fv, String typeName, boolean layoutContainsVLA) { {//from w ww . ja v a2s .c o m fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "unsafe", "Lsun/misc/Unsafe;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "containsVLA", "()Z", null, null); mv.visitCode(); //if layout contains VLA return true, otherwise false if (layoutContainsVLA) { mv.visitInsn(ICONST_1); } else { mv.visitInsn(ICONST_0); } mv.visitInsn(IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { fv = cw.visitField(ACC_PROTECTED, "location", "Lcom/ibm/layout/Location;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "bindLocation", "(Lcom/ibm/layout/Location;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "checkDataFits", "(J)Z", false); Label l0 = new Label(); mv.visitJumpInsn(IFEQ, l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(3, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "writeToByteArray", "(J[BII)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(I2L); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFLE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitInsn(L2I); mv.visitVarInsn(ISTORE, 5); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); Label l1 = new Label(); mv.visitJumpInsn(IFNULL, l1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(L2I); mv.visitVarInsn(ALOAD, 3); mv.visitVarInsn(ILOAD, 4); mv.visitVarInsn(ILOAD, 5); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", false); Label l2 = new Label(); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;"); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LADD); mv.visitVarInsn(ALOAD, 3); mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;"); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "arrayBaseOffset", "(Ljava/lang/Class;)I", false); mv.visitInsn(I2L); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(I2L); mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "copyMemory", "(Ljava/lang/Object;JLjava/lang/Object;JJ)V", false); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(IRETURN); mv.visitMaxs(9, 6); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "readFromByteArray", "(J[BII)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(I2L); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFLE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitInsn(L2I); mv.visitVarInsn(ISTORE, 5); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); Label l1 = new Label(); mv.visitJumpInsn(IFNULL, l1); mv.visitVarInsn(ALOAD, 3); mv.visitVarInsn(ILOAD, 4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(L2I); mv.visitVarInsn(ILOAD, 5); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", false); Label l2 = new Label(); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;"); mv.visitVarInsn(ALOAD, 3); mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;"); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "arrayBaseOffset", "(Ljava/lang/Class;)I", false); mv.visitVarInsn(ILOAD, 4); mv.visitInsn(IADD); mv.visitInsn(I2L); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LADD); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(I2L); mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "copyMemory", "(Ljava/lang/Object;JLjava/lang/Object;JJ)V", false); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(IRETURN); mv.visitMaxs(9, 6); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "asByteBuffer", "()Ljava/nio/ByteBuffer;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); Label l0 = new Label(); mv.visitJumpInsn(IFNULL, l0); mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException"); mv.visitInsn(DUP); mv.visitLdcInsn("not off-heap"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false); mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/UnsafeHelper", "bufferFromAddress", "(JJ)Ljava/nio/ByteBuffer;", false); mv.visitVarInsn(ASTORE, 1); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/nio/ByteOrder", "nativeOrder", "()Ljava/nio/ByteOrder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/nio/ByteBuffer", "order", "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;", false); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ARETURN); mv.visitMaxs(4, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "asByteBuffer", "(Lcom/ibm/layout/Location;J)Ljava/nio/ByteBuffer;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false); Label l0 = new Label(); mv.visitJumpInsn(IFNULL, l0); mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException"); mv.visitInsn(DUP); mv.visitLdcInsn("not off-heap"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(ATHROW); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false); mv.visitVarInsn(LLOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/UnsafeHelper", "bufferFromAddress", "(JJ)Ljava/nio/ByteBuffer;", false); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "java/nio/ByteOrder", "nativeOrder", "()Ljava/nio/ByteOrder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/nio/ByteBuffer", "order", "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;", false); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(ARETURN); mv.visitMaxs(4, 4); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "unsafeCast", "(Ljava/lang/Class;)Lcom/ibm/layout/Layout;", "<T::Lcom/ibm/layout/Layout;>(Ljava/lang/Class<TT;>;)TT;", null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/SecurityException"); Label l4 = new Label(); mv.visitTryCatchBlock(l0, l1, l4, "java/lang/InstantiationException"); Label l5 = new Label(); mv.visitTryCatchBlock(l0, l1, l5, "java/lang/IllegalAccessException"); Label l6 = new Label(); mv.visitTryCatchBlock(l0, l1, l6, "java/lang/IllegalArgumentException"); Label l7 = new Label(); mv.visitTryCatchBlock(l0, l1, l7, "java/lang/reflect/InvocationTargetException"); mv.visitLabel(l0); mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/LayoutHelper", "getFactory", "()Lcom/ibm/layout/LayoutHelper;", false); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genLayoutImpl", "(Ljava/lang/Class;)Ljava/lang/Class;", false); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;", false); mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Layout"); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Layout", "bindLocation", "(Lcom/ibm/layout/Location;)V", true); mv.visitVarInsn(ALOAD, 4); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V", false); Label l8 = new Label(); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/SecurityException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/SecurityException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/InstantiationException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/InstantiationException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalAccessException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalAccessException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalArgumentException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalArgumentException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/reflect/InvocationTargetException" }); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace", "()V", false); mv.visitLabel(l8); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitMaxs(2, 5); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "unsafeCast", "(Ljava/lang/Class;J)Lcom/ibm/layout/Array1D;", "<T::Lcom/ibm/layout/Layout;>(Ljava/lang/Class<TT;>;J)Lcom/ibm/layout/Array1D<TT;>;", null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/SecurityException"); Label l4 = new Label(); mv.visitTryCatchBlock(l0, l1, l4, "java/lang/InstantiationException"); Label l5 = new Label(); mv.visitTryCatchBlock(l0, l1, l5, "java/lang/IllegalAccessException"); Label l6 = new Label(); mv.visitTryCatchBlock(l0, l1, l6, "java/lang/IllegalArgumentException"); Label l7 = new Label(); mv.visitTryCatchBlock(l0, l1, l7, "java/lang/reflect/InvocationTargetException"); mv.visitLabel(l0); mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/LayoutHelper", "getFactory", "()Lcom/ibm/layout/LayoutHelper;", false); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genLayoutImpl", "(Ljava/lang/Class;)Ljava/lang/Class;", false); mv.visitVarInsn(ASTORE, 5); mv.visitVarInsn(ALOAD, 5); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false); mv.visitVarInsn(ASTORE, 6); mv.visitVarInsn(ALOAD, 6); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false); mv.visitVarInsn(ALOAD, 6); mv.visitInsn(ICONST_0); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;", false); mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Layout"); mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Layout", "sizeof", "()J", true); mv.visitVarInsn(LSTORE, 7); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genArray1DImpl", "(Ljava/lang/Class;)Ljava/lang/Class;", false); mv.visitVarInsn(ASTORE, 9); mv.visitVarInsn(ALOAD, 9); mv.visitInsn(ICONST_2); mv.visitTypeInsn(ANEWARRAY, "java/lang/Class"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;"); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false); mv.visitVarInsn(ASTORE, 10); mv.visitVarInsn(ALOAD, 10); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false); mv.visitVarInsn(ALOAD, 10); mv.visitInsn(ICONST_2); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitVarInsn(LLOAD, 2); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitVarInsn(LLOAD, 7); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;", false); mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Array1D"); mv.visitVarInsn(ASTORE, 11); mv.visitVarInsn(ALOAD, 11); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;"); mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Array1D", "bindLocation", "(Lcom/ibm/layout/Location;)V", true); mv.visitVarInsn(ALOAD, 11); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V", false); Label l8 = new Label(); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/SecurityException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/SecurityException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/InstantiationException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/InstantiationException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalAccessException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalAccessException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalArgumentException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalArgumentException", "printStackTrace", "()V", false); mv.visitJumpInsn(GOTO, l8); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/reflect/InvocationTargetException" }); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace", "()V", false); mv.visitLabel(l8); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitMaxs(6, 12); mv.visitEnd(); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate void main(String[])//from w w w . ja v a 2 s . c o m * <p> * <code> * public static void main(String[] args) { * ExampleProgram exampleProgram = new ExampleProgram(); * try { * exampleProgram.inputStream = System.in; * exampleProgram.outputStream = System.out; * exampleProgram.program(); * } catch (Exception e) { * e.printStackTrace(); * } * } * </code> * </p> */ protected void generateMain(String classname, ClassWriter classWriter) throws Exception { try { /* * make method */ final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); methodVisitor.visitCode(); final Label l0 = new Label(); final Label l1 = new Label(); final Label l2 = new Label(); methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); final Label l3 = new Label(); methodVisitor.visitLabel(l3); /* * declare a local instance of the class in the void() main, store as variable 1. */ methodVisitor.visitTypeInsn(Opcodes.NEW, classname); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V"); methodVisitor.visitVarInsn(Opcodes.ASTORE, 1); /* * assign the input stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;"); /* * assign the output stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;"); /* * load the class instance from variable 1 and call "program" */ methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V"); methodVisitor.visitLabel(l1); final Label l4 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, l4); methodVisitor.visitLabel(l2); methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1, new Object[] { "java/lang/Exception" }); methodVisitor.visitVarInsn(Opcodes.ASTORE, 2); final Label l5 = new Label(); methodVisitor.visitLabel(l5); methodVisitor.visitLineNumber(21, l5); methodVisitor.visitVarInsn(Opcodes.ALOAD, 2); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V"); /* * return */ methodVisitor.visitLabel(l4); methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare the parameters */ final Label l6 = new Label(); methodVisitor.visitLabel(l6); methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0); methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1); methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2); /* * done */ methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateMain", e); } }
From source file:com.nginious.http.xsp.ForEachTagPart.java
License:Apache License
/** * Creates bytecode in a separate method for evaluating this for each tag part. * // w w w.ja va2 s . c om * @param intClassName the binary class name of the class being created * @param writer the class writer * @throws XspException if unable to create bytecode */ void compileMethod(String intClassName, ClassWriter writer) throws XspException { String[] exceptions = { "com/nginious/http/xsp/XspException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PRIVATE, this.methodName, "(Lcom/nginious/http/HttpRequest;Lcom/nginious/http/HttpResponse;Ljava/lang/StringBuffer;)V", null, exceptions); visitor.visitCode(); Label tryLabel = new Label(); Label startCatchLabel = new Label(); // Start try block visitor.visitTryCatchBlock(tryLabel, startCatchLabel, startCatchLabel, "java/lang/Exception"); visitor.visitLabel(tryLabel); try { String expression = setValue.getExpressionContent(); ExpressionParser parser = new ExpressionParser(); TreeExpression expr = parser.parse(expression); if (expr.getType() != Type.ANY) { throw new XspException("Expression in attribute set in tag " + getName() + " is not an attribute or bean property " + " at line " + getLocationDescriptor()); } expr.compile(visitor, Type.ANY); visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Collection"); visitor.visitVarInsn(Opcodes.ASTORE, 4); } catch (ExpressionException e) { throw new XspException("Invalid expression in attribute set in tag " + getName() + " at line " + getLocationDescriptor(), e); } Label labelOut = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitJumpInsn(Opcodes.IFNULL, labelOut); // Start if (this.start != null) { start.compile(visitor, Type.INT); } else { visitor.visitLdcInsn((int) 0); } visitor.visitVarInsn(Opcodes.ISTORE, 5); // End if (this.end != null) { end.compile(visitor, Type.INT); } else { visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I"); } visitor.visitVarInsn(Opcodes.ISTORE, 6); // Step if (this.step != null) { step.compile(visitor, Type.INT); } else { visitor.visitLdcInsn((int) 1); } visitor.visitVarInsn(Opcodes.ISTORE, 7); // Current pos visitor.visitLdcInsn(0); visitor.visitVarInsn(Opcodes.ISTORE, 8); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;"); visitor.visitVarInsn(Opcodes.ASTORE, 9); Label labelStart = new Label(); // Start of loop visitor.visitLabel(labelStart); // iterator.hasNext(); visitor.visitVarInsn(Opcodes.ALOAD, 9); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z"); visitor.visitJumpInsn(Opcodes.IFEQ, labelOut); // iterator.next(); visitor.visitVarInsn(Opcodes.ALOAD, 9); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;"); visitor.visitVarInsn(Opcodes.ASTORE, 10); // pos >= start && pos <= end && (pos - start) % step == 0 Label labelIncr = new Label(); visitor.visitVarInsn(Opcodes.ILOAD, 8); visitor.visitVarInsn(Opcodes.ILOAD, 5); visitor.visitJumpInsn(Opcodes.IF_ICMPLT, labelIncr); visitor.visitVarInsn(Opcodes.ILOAD, 8); visitor.visitVarInsn(Opcodes.ILOAD, 6); visitor.visitJumpInsn(Opcodes.IF_ICMPGT, labelIncr); visitor.visitVarInsn(Opcodes.ILOAD, 8); visitor.visitVarInsn(Opcodes.ILOAD, 5); visitor.visitInsn(Opcodes.ISUB); visitor.visitVarInsn(Opcodes.ILOAD, 7); visitor.visitInsn(Opcodes.IREM); visitor.visitJumpInsn(Opcodes.IFNE, labelIncr); visitor.visitVarInsn(Opcodes.ALOAD, 1); varName.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ALOAD, 10); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpRequest", "setAttribute", "(Ljava/lang/String;Ljava/lang/Object;)V"); // Call sub parts for (XspPart part : this.contentParts) { part.compile(intClassName, writer, visitor); } // pos++ visitor.visitLabel(labelIncr); visitor.visitIincInsn(8, 1); visitor.visitJumpInsn(Opcodes.GOTO, labelStart); visitor.visitLabel(labelOut); visitor.visitInsn(Opcodes.RETURN); visitor.visitLabel(startCatchLabel); visitor.visitVarInsn(Opcodes.ASTORE, 3); visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/XspException"); visitor.visitInsn(Opcodes.DUP); visitor.visitLdcInsn("Attribute set contains an invalid collection for tag " + getName() + " at " + getLocationDescriptor()); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/XspException", "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); visitor.visitInsn(Opcodes.ATHROW); visitor.visitMaxs(11, 11); visitor.visitEnd(); }
From source file:com.nginious.http.xsp.FormatDateTagPart.java
License:Apache License
/** * Creates bytecode in a separate method for evaluating this format date tag part. * /*from w ww . j ava 2 s . c o m*/ * @param intClassName the binary class name of the class being created * @param writer the class writer * @throws XspException if unable to create bytecode */ void compileMethod(String intClassName, ClassWriter writer) throws XspException { String[] exceptions = { "com/nginious/http/xsp/XspException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PRIVATE, this.methodName, "(Lcom/nginious/http/HttpRequest;Lcom/nginious/http/HttpResponse;Ljava/lang/StringBuffer;)V", null, exceptions); visitor.visitCode(); Label tryLabel = new Label(); Label startCatchLabel = new Label(); // Start try block visitor.visitTryCatchBlock(tryLabel, startCatchLabel, startCatchLabel, "java/lang/Exception"); visitor.visitLabel(tryLabel); visitor.visitTypeInsn(Opcodes.NEW, "java/text/SimpleDateFormat"); visitor.visitInsn(Opcodes.DUP); pattern.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpResponse", "getLocale", "()Ljava/util/Locale;"); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/text/SimpleDateFormat", "<init>", "(Ljava/lang/String;Ljava/util/Locale;)V"); visitor.visitVarInsn(Opcodes.ASTORE, 4); if (this.timeZone != null) { visitor.visitVarInsn(Opcodes.ALOAD, 4); String timeZoneDesc = timeZone.getStringContent(); visitor.visitLdcInsn(timeZoneDesc); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/text/SimpleDateFormat", "setTimeZone", "(Ljava/util/TimeZone;)V"); } try { String expression = value.getExpressionContent(); ExpressionParser parser = new ExpressionParser(); TreeExpression expr = parser.parse(expression); if (expr.getType() != Type.ANY) { throw new XspException("Expression in attribute value in tag " + getName() + " is not an attribute or bean property " + " at line " + getLocationDescriptor()); } expr.compile(visitor, Type.ANY); visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Date"); visitor.visitVarInsn(Opcodes.ASTORE, 5); } catch (ExpressionException e) { throw new XspException("Invalid expression in attribute value in tag " + getName() + " at line " + getLocationDescriptor(), e); } Label nullLabel = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/text/SimpleDateFormat", "format", "(Ljava/util/Date;)Ljava/lang/String;"); visitor.visitVarInsn(Opcodes.ASTORE, 5); if (this.var != null) { visitor.visitVarInsn(Opcodes.ALOAD, 1); var.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpRequest", "setAttribute", "(Ljava/lang/String;Ljava/lang/Object;)V"); } else { visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); visitor.visitInsn(Opcodes.POP); } visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.RETURN); visitor.visitLabel(startCatchLabel); visitor.visitVarInsn(Opcodes.ASTORE, 3); visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/XspException"); visitor.visitInsn(Opcodes.DUP); visitor.visitLdcInsn( "Attribute value contains an invalid date for tag " + getName() + " at " + getLocationDescriptor()); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/XspException", "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); visitor.visitInsn(Opcodes.ATHROW); visitor.visitMaxs(6, 6); visitor.visitEnd(); super.compileMethod(intClassName, writer); }
From source file:com.nginious.http.xsp.FormatNumberTagPart.java
License:Apache License
/** * Creates bytecode in a separate method for evaluating this format number tag part. * //from w w w . ja v a 2s .c om * @param intClassName the binary class name of the class being created * @param writer the class writer * @throws XspException if unable to create bytecode */ void compileMethod(String intClassName, ClassWriter writer) throws XspException { String[] exceptions = { "com/nginious/http/xsp/XspException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PRIVATE, this.methodName, "(Lcom/nginious/http/HttpRequest;Lcom/nginious/http/HttpResponse;Ljava/lang/StringBuffer;)V", null, exceptions); visitor.visitCode(); Label tryLabel = new Label(); Label startCatchLabel = new Label(); // Start try block visitor.visitTryCatchBlock(tryLabel, startCatchLabel, startCatchLabel, "java/lang/Exception"); visitor.visitLabel(tryLabel); visitor.visitTypeInsn(Opcodes.NEW, "java/text/DecimalFormat"); visitor.visitInsn(Opcodes.DUP); pattern.compile(visitor, Type.STRING); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/text/DecimalFormat", "<init>", "(Ljava/lang/String;)V"); visitor.visitVarInsn(Opcodes.ASTORE, 4); ExpressionParser parser = null; TreeExpression expr = null; try { String expression = value.getExpressionContent(); parser = new ExpressionParser(); expr = parser.parse(expression); if (expr.getType() != Type.ANY) { throw new XspException("Expression in attribute value in tag " + getName() + " is not an attribute or bean property " + " at line " + getLocationDescriptor()); } } catch (ExpressionException e) { throw new XspException("Invalid expression in attribute value in tag " + getName() + " at line " + getLocationDescriptor(), e); } visitor.visitVarInsn(Opcodes.ALOAD, 4); expr.compile(visitor, Type.DOUBLE); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/text/DecimalFormat", "format", "(D)Ljava/lang/String;"); visitor.visitVarInsn(Opcodes.ASTORE, 5); if (this.var != null) { visitor.visitVarInsn(Opcodes.ALOAD, 1); var.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpRequest", "setAttribute", "(Ljava/lang/String;Ljava/lang/Object;)V"); } else { visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); visitor.visitInsn(Opcodes.POP); } visitor.visitInsn(Opcodes.RETURN); visitor.visitLabel(startCatchLabel); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/XspException"); visitor.visitInsn(Opcodes.DUP); visitor.visitLdcInsn("Attribute value contains an invalid number for tag " + getName() + " at " + getLocationDescriptor()); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/XspException", "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); visitor.visitInsn(Opcodes.ATHROW); visitor.visitMaxs(6, 6); visitor.visitEnd(); super.compileMethod(intClassName, writer); }
From source file:com.nginious.http.xsp.XspCompiler.java
License:Apache License
/** * Creates subclass of {@link XspService} for the XSP file represented by the specified document * tree node structure./* ww w . jav a 2 s .c om*/ * * @param document the document tree node structure * @param srcFilePath the XSP file source path * @return a descriptor for the generated subclass * @throws XspException if unable to create subclass */ private ClassDescriptor compileService(DocumentPart document, String srcFilePath) throws XspException { ClassWriter writer = new ClassWriter(0); // Create class String packageName = document.getMetaContent("package"); String intServiceClazzName = createIntServiceClassName(packageName, srcFilePath); String serviceClazzName = createServiceClassName(packageName, srcFilePath); writer.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, intServiceClazzName, "Lcom/nginious/http/xsp/XspService;", "com/nginious/http/xsp/XspService", null); // Create constructor createConstructor(writer, "com/nginious/http/xsp/XspService"); // Create xsp service method MethodVisitor visitor = createXspMethod(writer); Label tryLabel = new Label(); Label startCatchLabel = new Label(); Label endCatchLabel = new Label(); // Start try block visitor.visitTryCatchBlock(tryLabel, startCatchLabel, endCatchLabel, "java/lang/Throwable"); visitor.visitLabel(tryLabel); visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/expr/HttpRequestVariables"); visitor.visitInsn(Opcodes.DUP); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/expr/HttpRequestVariables", "<init>", "(Lcom/nginious/http/HttpRequest;)V"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/nginious/http/xsp/expr/Expression", "setVariables", "(Lcom/nginious/http/xsp/expr/Variables;)V"); document.compile(intServiceClazzName, writer, visitor); visitor.visitLabel(startCatchLabel); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/nginious/http/xsp/expr/Expression", "removeVariables", "()V"); visitor.visitLdcInsn(true); visitor.visitInsn(Opcodes.IRETURN); // Start finally block visitor.visitLabel(endCatchLabel); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/nginious/http/xsp/expr/Expression", "removeVariables", "()V"); visitor.visitInsn(Opcodes.ATHROW); visitor.visitMaxs(12, 12); visitor.visitEnd(); document.compileMethod(intServiceClazzName, writer); writer.visitEnd(); byte[] clazzBytes = writer.toByteArray(); return new ClassDescriptor(serviceClazzName, clazzBytes); }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.TryCatchBlock.java
License:Open Source License
public void toAsm(MethodVisitor mv) { mv.visitTryCatchBlock(start, end, handler, type); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.BytecodeCatchBuilder.java
@Override public BytecodeSequence build() { return new BytecodeSequence() { @Override/*from w ww. ja v a 2s . c o m*/ public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); for (CatchClause catchClause : catchClauses) { if (catchClause.exceptionInternalNames.isEmpty()) { mv.visitTryCatchBlock(body.getStart(), body.getEnd(), catchClause.getStart(), null); } else { for (String name : catchClause.exceptionInternalNames) { mv.visitTryCatchBlock(body.getStart(), body.getEnd(), catchClause.getStart(), name); } } } Label done = new Label(); body.generate(code); mv.visitJumpInsn(Opcodes.GOTO, done); for (CatchClause catchClause : catchClauses.subList(0, catchClauses.size() - 1)) { catchClause.generate(code); mv.visitJumpInsn(Opcodes.GOTO, done); } catchClauses.get(catchClauses.size() - 1).generate(code); mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java
@Override public BytecodeExpression fallback(Location loc, final BytecodeExpression primary, final BytecodeExpression caught) { TypeWidget unified = unify(primary.getType(), caught.getType()); return new BaseTypeExpression(unified) { @Override//from w ww. j a va2 s . com 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); } }; }