Example usage for org.objectweb.asm Opcodes F_SAME1

List of usage examples for org.objectweb.asm Opcodes F_SAME1

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes F_SAME1.

Prototype

int F_SAME1

To view the source code for org.objectweb.asm Opcodes F_SAME1.

Click Source Link

Document

A compressed frame with exactly the same locals as the previous frame and with a single value on the stack.

Usage

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) {
    {//w  ww  . j a v  a 2 s. 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.sun.fortress.compiler.asmbytecodeoptimizer.VisitFrame.java

License:Open Source License

public String toString() {
    String result = "VisitFrame: type = ";
    switch (type) {
    case Opcodes.F_NEW:
        result = result + " F_NEW ";
        break;/*from  w w  w .  ja va 2 s.  c  o m*/
    case Opcodes.F_FULL:
        result = result + " F_FULL ";
        break;
    case Opcodes.F_APPEND:
        result = result + " F_APPEND ";
        break;
    case Opcodes.F_CHOP:
        result = result + " F_CHOP ";
        break;
    case Opcodes.F_SAME:
        result = result + " F_SAME ";
        break;
    case Opcodes.F_SAME1:
        result = result + " F_SAME1 ";
        break;
    default:
        throw new RuntimeException("Unknown Frame Type " + type);
    }

    result = result + "locals = [";
    for (int i = 0; i < nLocal; i++)
        result = result + local[i] + "  ";
    result = result + "] Stack = [";
    for (int i = 0; i < nStack; i++)
        result = result + stack[i] + "  ";
    result = result + "]";
    return result;
}

From source file:com.sun.fortress.compiler.codegen.CodeGen.java

License:Open Source License

public void forTry(Try x) {
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    Label lfinally = new Label();

    Block body = x.getBody();//  w  ww .  j  a v  a  2s.c  o m
    Option<Catch> catchClauses = x.getCatchClause();
    List<BaseType> forbid = x.getForbidClause();
    Option<Block> finallyClause = x.getFinallyClause();
    if (!forbid.isEmpty())
        throw new RuntimeException("NYI: Forbid clauses are not yet implemented");

    mv.visitTryCatchBlock(l0, l1, l2, "com/sun/fortress/compiler/runtimeValues/FException");
    mv.visitLabel(l0);
    body.accept(this);
    mv.visitLabel(l1);
    mv.visitJumpInsn(GOTO, lfinally);
    mv.visitLabel(l2);
    // We really should have desugared this into typecase, but for now...

    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1,
            new Object[] { "com/sun/fortress/compiler/runtimeValues/FException" });

    if (catchClauses.isSome()) {
        Catch _catch = catchClauses.unwrap();
        Id name = _catch.getName();

        Label done = new Label(); // first statement after the whole try-catch statement
        List<CatchClause> clauses = _catch.getClauses();
        for (CatchClause clause : clauses) {
            Label end = new Label(); // if catch clause does not match, skip clause body
            BaseType match = clause.getMatchType();

            mv.visitInsn(DUP); // Save Java exception while we fiddle with Fortress data
            mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/fortress/compiler/runtimeValues/FException", "getValue",
                    "()Lcom/sun/fortress/compiler/runtimeValues/FValue;");

            InstantiatingClassloader.generalizedInstanceOf(mv, NamingCzar.jvmBoxedTypeName(match, thisApi()));
            mv.visitJumpInsn(IFEQ, end);
            mv.visitInsn(POP);
            clause.getBody().accept(this);
            mv.visitJumpInsn(GOTO, done);
            mv.visitLabel(end);
        }
        mv.visitInsn(ATHROW); // Rethrow if no match
        mv.visitLabel(done);
    }
    mv.visitLabel(lfinally);
    if (finallyClause.isSome()) {
        finallyClause.unwrap().accept(this);
        popAll(mv, 1);
    }
}

From source file:com.sun.fortress.compiler.codegen.CodeGen.java

License:Open Source License

private void RttiClassAndInterface(TraitObjectDecl tod, ClassNameBundle cnb, Naming.XlationData xldata) {

    TraitTypeHeader header = tod.getHeader();

    IdOrOpOrAnonymousName name = header.getName();
    List<StaticParam> sparams = header.getStaticParams();

    HashMap<Id, TraitIndex> transitive_extends = STypesUtil.allSupertraits(tod, typeAnalyzer);

    HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> transitive_extends_opr_tagged = oprTagSupertraitsAndArgs(
            STypesUtil.allSupertraitsAndStaticArgs(tod, typeAnalyzer));

    HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> direct_extends_opr_tagged = oprTagSupertraitsAndArgs(
            STypesUtil.immediateSupertraitsAndStaticArgs(tod, typeAnalyzer));

    HashMap<Id, TraitIndex> direct_extends = STypesUtil.immediateSupertraits(tod, typeAnalyzer);

    HashMap<Id, List<StaticArg>> direct_extends_args = STypesUtil.immediateSupertraitsStaticArgs(tod,
            typeAnalyzer);/*www.  jav a 2s .  c o m*/

    int d_e_size = direct_extends.size();

    CodeGenClassWriter prev = cw;
    cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, prev);

    /*
     * x$RTTIi
     * extends y$RTTIi for each y in extend_s
            
     * for each static parameter of x, declares method "asX"#number
            
     * x$RTTIc
     * implements x$RTTIi
            
     * fields
     * for each y in extend_s, one field, initially null, type y$RttiClass
     * for each z in static parameters, one field, init in constructor
            
     * constructor (init method)
     * parameters for static parameters, if any.
     * 
     * if no static parameters, then a static field initialized to the
     * single value of the type.
     * if static parameters, then a static field initialized to a map of
     * some sort, plus a factory receiving static parameters, that checks
     * the map, and allocates the type as necessary.
            
     * lazy_init method
     * for each y in extend_s, field = new y$RTTIc(type parameters).
     * type parameters need thinking about how we put them together.
     * If extends A[B[T]], should be new A$RTTIc(new B$RTTIc(T))
     * Seems like a factory would be appropriate, to avoid senseless
     * duplication of type parameters.
            
     * methods
     * for each static parameter #N of each type T in transitive_extends,
     * there needs to be a method as"T"#N.  For all non-self types, the
     * method will check lazy_init, and then delegate to the first type
     * in extend_s that has T in its own transitive_extends.  For T=self,
     * return the value of the appropriate static parameter.
            
     */

    /*
     * x$RTTIi
     * extends y$RTTIi for each y in extend_s
     */

    Naming.XlationData original_xldata = xldata;
    List<String> opr_params = oprsFromKindParamList(xldata.staticParameterKindNamePairs());
    xldata = opr_params.size() == 0 ? null : xlationData(Naming.RTTI_GENERIC_TAG);
    for (String opr_param : opr_params)
        xldata.addKindAndNameToStaticParams(Naming.XL_OPR, opr_param);
    String stemClassName = Naming.oprArgAnnotatedRTTI(cnb.stemClassName, opr_params);

    String rttiInterfaceName = Naming.stemInterfaceToRTTIinterface(stemClassName);
    String rttiInterfaceFileName = opr_params.size() == 0 ? rttiInterfaceName
            : Naming.stemInterfaceToRTTIinterface(Naming.fileForOprTaggedGeneric(cnb.stemClassName));

    String[] superInterfaces = new String[d_e_size];

    Id[] direct_extends_keys = new Id[d_e_size]; // will use in lazyInit
    {
        int i = 0;
        for (Id extendee : direct_extends.keySet()) {
            List<StaticArg> ti_args = direct_extends_args.get(extendee);
            String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args);

            //            String extendeeIlk =
            //                NamingCzar.jvmClassForToplevelTypeDecl(extendee,"",
            //                        packageAndClassName);
            direct_extends_keys[i] = extendee;
            superInterfaces[i++] = Naming.stemInterfaceToRTTIinterface(extendeeIlk);
        }
    }

    cw.visitSource(NodeUtil.getSpan(tod).begin.getFileName(), null);
    cw.visit(InstantiatingClassloader.JVM_BYTECODE_VERSION, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE,
            rttiInterfaceName, null, NamingCzar.internalObject, superInterfaces);

    /*
     * for each static parameter of x, declares method "asX"#number
     */
    {
        int i = Naming.STATIC_PARAMETER_ORIGIN;
        for (StaticParam sp : sparams) {
            if (!(sp.getKind() instanceof KindOp)) {
                String method_name = Naming.staticParameterGetterName(stemClassName, i);
                mv = cw.visitCGMethod(ACC_ABSTRACT + ACC_PUBLIC, method_name,
                        Naming.STATIC_PARAMETER_GETTER_SIG, null, null);
                mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter);
                mv.visitEnd();
                i++;
            }
        }
    }

    cw.dumpClass(rttiInterfaceFileName, xldata);

    cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, prev);

    /*
     * x$RTTIc
     * implements x$RTTIi
     */

    superInterfaces = new String[1];
    superInterfaces[0] = rttiInterfaceName;
    String rttiClassName = Naming.stemClassToRTTIclass(stemClassName);
    String rttiClassFileName = opr_params.size() == 0 ? rttiClassName
            : Naming.stemClassToRTTIclass(Naming.fileForOprTaggedGeneric(cnb.stemClassName));

    cw.visitSource(NodeUtil.getSpan(tod).begin.getFileName(), null);
    cw.visit(InstantiatingClassloader.JVM_BYTECODE_VERSION, ACC_PUBLIC, rttiClassName, null,
            Naming.RTTI_CONTAINER_TYPE, superInterfaces);

    /*
     * fields
     * for each y in extend_s, one field, initially null, type y$RttiClass
     * for each z in static parameters, one field, init in constructor
     */

    for (Id extendee : direct_extends.keySet()) {

        // This yutch is repeated below in lazyInit; needs cleanup.
        List<StaticArg> ti_args = direct_extends_args.get(extendee);
        String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args);

        // note fields are volatile because of double-checked locking below
        cw.visitField(ACC_PRIVATE + ACC_VOLATILE, extendeeIlk, Naming.RTTI_CONTAINER_DESC, null, null);
    }

    // Fields and Getters for static parameters
    int count_non_opr_sparams;
    {
        int i = Naming.STATIC_PARAMETER_ORIGIN;
        for (StaticParam sp : sparams) {
            if (!(sp.getKind() instanceof KindOp)) {
                String spn = sp.getName().getText();
                String stem_name = stemClassName;
                InstantiatingClassloader.fieldAndGetterForStaticParameter(cw, stem_name, spn, i);
                i++;
            }
        }
        count_non_opr_sparams = i - Naming.STATIC_PARAMETER_ORIGIN;
    }

    /*
     * constructor (init method)
     * parameters for static parameters, if any.
     */
    final int sparams_size = count_non_opr_sparams;
    {
        // Variant of this code in InstantiatingClassloader
        String init_sig = InstantiatingClassloader.jvmSignatureForOnePlusNTypes("java/lang/Class", sparams_size,
                Naming.RTTI_CONTAINER_TYPE, "V");
        mv = cw.visitCGMethod(ACC_PUBLIC, "<init>", init_sig, null, null);
        mv.visitCode();

        mv.visitVarInsn(ALOAD, 0); // this
        mv.visitVarInsn(ALOAD, 1); // class
        mv.visitMethodInsn(INVOKESPECIAL, Naming.RTTI_CONTAINER_TYPE, "<init>", "(Ljava/lang/Class;)V");

        int pno = 2; // 1 is java class
        for (StaticParam sp : sparams) {
            if (!(sp.getKind() instanceof KindOp)) {
                String spn = sp.getName().getText();
                // not yet this;  sp.getKind();
                mv.visitVarInsn(ALOAD, 0);
                mv.visitVarInsn(ALOAD, pno);
                mv.visitFieldInsn(PUTFIELD, rttiClassName, spn, Naming.RTTI_CONTAINER_DESC);
                pno++;
            }
        }

        voidEpilogue();
    }

    cw.visitField(ACC_PRIVATE + ACC_VOLATILE, "initFlag", "Ljava/lang/Object;", null, null);

    /*
     * static singleton or static map + factory.
     */
    if (sparams_size == 0) {
        // static, initialized to single instance of self
        cw.visitField(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, Naming.RTTI_SINGLETON, Naming.RTTI_CONTAINER_DESC,
                null, null);

        mv = cw.visitCGMethod(ACC_STATIC, "<clinit>", "()V", null, null);
        mv.visitCode();
        // new
        mv.visitTypeInsn(NEW, rttiClassName);
        // init
        mv.visitInsn(DUP);
        mv.visitLdcInsn(org.objectweb.asm.Type.getType(cnb.classDesc));
        mv.visitMethodInsn(INVOKESPECIAL, rttiClassName, "<init>", "(Ljava/lang/Class;)V");
        // store
        mv.visitFieldInsn(PUTSTATIC, rttiClassName, Naming.RTTI_SINGLETON, Naming.RTTI_CONTAINER_DESC);

        voidEpilogue();
    } else {
        InstantiatingClassloader.emitDictionaryAndFactoryForGenericRTTIclass(cw, rttiClassName, sparams_size,
                original_xldata);
    }

    /*
     * lazy_init method
     * for each y in extend_s, field = new y$RTTIc(type parameters).
     * type parameters need thinking about how we put them together.
     * If extends A[B[T]], should be new A$RTTIc(new B$RTTIc(T))
     * Seems like a factory would be appropriate, to avoid senseless
     * duplication of type parameters.
     */
    if (d_e_size > 0) {
        mv = cw.visitCGMethod(ACC_PUBLIC, "lazyInit", "()V", null, null);
        mv.visitCode();

        Label do_ret = new Label();
        Label do_monitor_ret = new Label();

        //debugging - catch exceptions thrown inside the monitor
        Label debugTryStart = new Label();
        Label debugTryEnd = new Label();
        Label debugHandler = new Label();
        mv.visitTryCatchBlock(debugTryStart, debugTryEnd, debugHandler, "java/lang/Throwable");
        mv.visitLabel(debugTryStart);
        //end debugging - more below    

        // Double-checked locking.
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;");
        mv.visitJumpInsn(IFNONNULL, do_ret);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(MONITORENTER);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;");
        mv.visitJumpInsn(IFNONNULL, do_monitor_ret);

        HashSet<String> spns = new HashSet<String>();
        for (StaticParam sp : sparams) {
            IdOrOp spn = sp.getName();
            String s = spn.getText();
            spns.add(s);
        }

        // Do the initialization.
        // Push all the type parameters
        for (Id extendee : direct_extends_keys) {
            TraitIndex ti = direct_extends.get(extendee);
            List<StaticArg> ti_args = direct_extends_args.get(extendee);
            String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args);

            mv.visitVarInsn(ALOAD, 0); // this ptr for store.
            // invoke factory method for value to store.
            generateTypeReference(mv, rttiClassName, extendee, ti_args, spns);
            mv.visitFieldInsn(PUTFIELD, rttiClassName, extendeeIlk, Naming.RTTI_CONTAINER_DESC);
        }

        // Mark as inited.  Just store a self-pointer and be done with it.
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(PUTFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;");

        //more debugging
        mv.visitLabel(debugTryEnd);
        Label debugPassCatch = new Label();
        mv.visitJumpInsn(GOTO, debugPassCatch);
        mv.visitLabel(debugHandler);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
        mv.visitVarInsn(ASTORE, 0);
        Label debugInternal = new Label();
        mv.visitLabel(debugInternal);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "com/sun/fortress/runtimeSystem/InstantiatingClassloader", "eep",
                "(Ljava/lang/Throwable;)V");
        mv.visitLabel(debugPassCatch);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        //end more debugging

        mv.visitLabel(do_monitor_ret);

        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(MONITOREXIT);

        mv.visitLabel(do_ret);
        voidEpilogue();
    }

    /*
     * methods
     * for each static parameter #N of each type T in transitive_extends,
     * there needs to be a method as"T"#N.  For all non-self types, the
     * method will check lazy_init, and then delegate to the first type
     * in extend_s that has T in its own transitive_extends.  For T=self,
     * return the value of the appropriate static parameter.
     */

    /* 
     * First map extends to what they transitively extend for delegation
     * The keys of this map are the members of the extends list;
     * the values, for each car, are those things that further
     * transitively extend that extender.  Each static-parameter-probing
     * method for the type (T) whose RTTI is being generated, will either
     * return a field (static parameter) of T, or will delegate to one
     * of the types extending T.
     */
    HashMap<String, Map<String, Tuple2<TraitIndex, List<StaticArg>>>> transitive_extends_from_extends = new HashMap<String, Map<String, Tuple2<TraitIndex, List<StaticArg>>>>();

    for (Map.Entry<Id, TraitIndex> entry : direct_extends.entrySet()) {
        Id te_id = entry.getKey();
        TraitIndex te_ti = entry.getValue();
        HashMap<Id, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends_tmp = STypesUtil
                .allSupertraitsAndStaticArgs(te_ti.ast(), typeAnalyzer);

        Tuple2<TraitIndex, List<StaticArg>> te_pair = new Tuple2<TraitIndex, List<StaticArg>>(te_ti,
                direct_extends_args.get(te_id));
        extends_transitive_extends_tmp.put(te_id, te_pair); // put self in set.

        HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends = oprTagSupertraitsAndArgs(
                extends_transitive_extends_tmp);

        String te_id_stem = oprTaggedGenericStemNameSA(te_id, direct_extends_args.get(te_id));

        transitive_extends_from_extends.put(te_id_stem, extends_transitive_extends);
    }

    // Future opt: sort by transitive_extends, use largest as class ancestor

    // For each type in extends list, emit forwarding functions (delegates)
    // remove traits from transitive_extends as they are dealt with.

    for (Map.Entry<Id, TraitIndex> entry : direct_extends.entrySet()) {
        if (transitive_extends.size() == 0)
            break;
        Id de_id = entry.getKey();
        String de_id_stem = oprTaggedGenericStemNameSA(de_id, direct_extends_args.get(de_id));
        TraitIndex de_ti = entry.getValue();

        // iterate over all traits transitively extended by delegate (de_)            
        Map<String, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends = transitive_extends_from_extends
                .get(de_id_stem);
        Set<Map.Entry<String, Tuple2<TraitIndex, List<StaticArg>>>> entryset = extends_transitive_extends
                .entrySet();

        for (Map.Entry<String, Tuple2<TraitIndex, List<StaticArg>>> extends_entry : entryset) {

            // delegate for extended te_id, if not already done.
            String te_id = extends_entry.getKey();
            if (!transitive_extends_opr_tagged.containsKey(te_id))
                continue; // already done.
            else
                transitive_extends_opr_tagged.remove(te_id);

            Tuple2<TraitIndex, List<StaticArg>> te_ti = extends_entry.getValue();
            List<StaticParam> te_sp = te_ti._1.staticParameters();

            if (te_sp.size() == 0)
                continue; // no static parameters to delegate for.

            String te_stem = te_id;
            // emit delegates here
            // asX#number
            int i = Naming.STATIC_PARAMETER_ORIGIN;
            for (StaticParam a_sparam : te_sp) {
                StaticParamKind spk = a_sparam.getKind();
                if (spk instanceof KindOp)
                    continue;
                String method_name = Naming.staticParameterGetterName(te_stem, i);

                mv = cw.visitCGMethod(ACC_PUBLIC, method_name, Naming.STATIC_PARAMETER_GETTER_SIG, null, null);
                mv.visitCode();

                // lazyInit();
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKEVIRTUAL, rttiClassName, "lazyInit", "()V");

                String delegate_id = null;
                // invoke delegate -- work in progress here
                if (direct_extends_opr_tagged.containsKey(te_id) || te_id.equals(name)) {
                    delegate_id = te_id;
                } else { //need to find a direct extend that extends the trait we're looking for
                    for (String direct_extend_id : direct_extends_opr_tagged.keySet()) {
                        if (transitive_extends_from_extends.get(direct_extend_id).containsKey(te_id)) {
                            delegate_id = direct_extend_id;
                            break;
                        }
                    }
                }
                if (delegate_id == null)
                    throw new CompilerError(
                            "Could not find directly extended trait that transitively extends" + te_id);

                mv.visitVarInsn(ALOAD, 0);
                getExtendeeField(rttiClassName, delegate_id);
                String extendeeIlk = delegate_id; // NamingCzar.jvmClassForToplevelTypeDecl(delegate_id,"",packageAndClassName);
                String field_type = Naming.stemClassToRTTIclass(extendeeIlk);
                mv.visitMethodInsn(INVOKEVIRTUAL, field_type, method_name, Naming.STATIC_PARAMETER_GETTER_SIG);

                areturnEpilogue();
                i++;
            }
        }
    }
    cw.dumpClass(rttiClassFileName, xldata);
    cw = prev;
}

From source file:de.dynamicfiles.projects.gradle.plugins.javafx.tasks.internal.MonkeyPatcher.java

License:Apache License

private static void doMonkeyPatchFileHandleLeak(ClassReader classReader, ClassWriter classWriter) {
    classReader.accept(new ClassVisitor(Opcodes.ASM5, classWriter) {
        @Override/*w  w w  .j  a  va 2  s . com*/
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            if (!(name.equals(METHOD_TO_MONKEY_PATCH) && desc.equals(METHOD_SIGNATURE_TO_MONKEY_PATCH))) {
                return super.visitMethod(access, name, desc, signature, exceptions);
            }
            // helpful source: http://web.cs.ucla.edu/~msb/cs239-tutorial/
            // "We will do this using the Adapter Pattern. Adapters wrap an object, overriding some of its methods, and delegating to the others."
            // ugly adapter-pattern ... took me more time than I really can tell here <.<
            return getMonkeyPatchedFileHandleLeakMethodVisitor(access, name, desc, signature, exceptions);
        }

        private MethodVisitor getMonkeyPatchedFileHandleLeakMethodVisitor(int access, String name, String desc,
                String signature, String[] exceptions) {
            return new MethodVisitor(Opcodes.ASM5,
                    super.visitMethod(access, name, desc, signature, exceptions)) {

                /*
                 TODO improve detection of lambda-positions, numbers might vary on different compile-versions
                 */
                @Override
                public void visitCode() {
                    // This mostly got generated from ASM itself, except some adjustments for lambda-IDs and removed "visitMaxs()"-call
                    String javalangThrowable = "java/lang/Throwable";
                    String javaioFile = "java/io/File";
                    String javalangString = "java/lang/String";

                    Label l0 = new Label();
                    Label l1 = new Label();
                    Label l2 = new Label();
                    mv.visitTryCatchBlock(l0, l1, l2, javalangThrowable);
                    Label l3 = new Label();
                    Label l4 = new Label();
                    Label l5 = new Label();
                    mv.visitTryCatchBlock(l3, l4, l5, javalangThrowable);
                    Label l6 = new Label();
                    mv.visitTryCatchBlock(l3, l4, l6, null);
                    Label l7 = new Label();
                    Label l8 = new Label();
                    Label l9 = new Label();
                    mv.visitTryCatchBlock(l7, l8, l9, javalangThrowable);
                    Label l10 = new Label();
                    mv.visitTryCatchBlock(l5, l10, l6, null);
                    mv.visitInsn(Opcodes.ACONST_NULL);
                    mv.visitVarInsn(Opcodes.ASTORE, 3);
                    mv.visitVarInsn(Opcodes.ALOAD, 2);
                    Label l11 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l11);
                    mv.visitVarInsn(Opcodes.ALOAD, 2);
                    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "isDirectory", "()Z", false);
                    Label l12 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNE, l12);
                    mv.visitLabel(l11);
                    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { javalangString }, 0, null);
                    mv.visitTypeInsn(Opcodes.NEW, javaioFile);
                    mv.visitInsn(Opcodes.DUP);
                    mv.visitLdcInsn("java.home");
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "getProperty",
                            "(Ljava/lang/String;)Ljava/lang/String;", false);
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, javaioFile, "<init>", "(Ljava/lang/String;)V",
                            false);
                    mv.visitVarInsn(Opcodes.ASTORE, 2);
                    mv.visitLabel(l12);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitFieldInsn(Opcodes.GETSTATIC, "com/oracle/tools/packager/windows/WinAppBundler",
                            "VS_VERS", "[Ljava/lang/String;");
                    mv.visitVarInsn(Opcodes.ASTORE, 4);
                    mv.visitVarInsn(Opcodes.ALOAD, 4);
                    mv.visitInsn(Opcodes.ARRAYLENGTH);
                    mv.visitVarInsn(Opcodes.ISTORE, 5);
                    mv.visitInsn(Opcodes.ICONST_0);
                    mv.visitVarInsn(Opcodes.ISTORE, 6);
                    Label l13 = new Label();
                    mv.visitLabel(l13);
                    mv.visitFrame(Opcodes.F_APPEND, 3,
                            new Object[] { "[Ljava/lang/String;", Opcodes.INTEGER, Opcodes.INTEGER }, 0, null);
                    mv.visitVarInsn(Opcodes.ILOAD, 6);
                    mv.visitVarInsn(Opcodes.ILOAD, 5);
                    Label l14 = new Label();
                    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l14);
                    mv.visitVarInsn(Opcodes.ALOAD, 4);
                    mv.visitVarInsn(Opcodes.ILOAD, 6);
                    mv.visitInsn(Opcodes.AALOAD);
                    mv.visitVarInsn(Opcodes.ASTORE, 7);
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/oracle/tools/packager/windows/WinAppBundler",
                            "copyMSVCDLLs", "(Ljava/io/File;Ljava/lang/String;)Z", false);
                    Label l15 = new Label();
                    mv.visitJumpInsn(Opcodes.IFEQ, l15);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    mv.visitVarInsn(Opcodes.ASTORE, 3);
                    mv.visitJumpInsn(Opcodes.GOTO, l14);
                    mv.visitLabel(l15);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitIincInsn(6, 1);
                    mv.visitJumpInsn(Opcodes.GOTO, l13);
                    mv.visitLabel(l14);
                    mv.visitFrame(Opcodes.F_CHOP, 3, null, 0, null);
                    mv.visitVarInsn(Opcodes.ALOAD, 3);
                    Label l16 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNONNULL, l16);
                    mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException");
                    mv.visitInsn(Opcodes.DUP);
                    mv.visitLdcInsn("Not found MSVC dlls");
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                            "(Ljava/lang/String;)V", false);
                    mv.visitInsn(Opcodes.ATHROW);
                    mv.visitLabel(l16);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitTypeInsn(Opcodes.NEW, "java/util/concurrent/atomic/AtomicReference");
                    mv.visitInsn(Opcodes.DUP);
                    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/concurrent/atomic/AtomicReference",
                            "<init>", "()V", false);
                    mv.visitVarInsn(Opcodes.ASTORE, 4);
                    mv.visitVarInsn(Opcodes.ALOAD, 3);
                    mv.visitVarInsn(Opcodes.ASTORE, 5);
                    mv.visitVarInsn(Opcodes.ALOAD, 2);
                    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "toPath", "()Ljava/nio/file/Path;",
                            false);
                    mv.visitLdcInsn("bin");
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/nio/file/Path", "resolve",
                            "(Ljava/lang/String;)Ljava/nio/file/Path;", true);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "list",
                            "(Ljava/nio/file/Path;)Ljava/util/stream/Stream;", false);
                    mv.visitVarInsn(Opcodes.ASTORE, 6);
                    mv.visitInsn(Opcodes.ACONST_NULL);
                    mv.visitVarInsn(Opcodes.ASTORE, 7);
                    mv.visitLabel(l3);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitInvokeDynamicInsn("test", "()Ljava/util/function/Predicate;", new Handle(
                            Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
                            "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"),
                            new Object[] { Type.getType("(Ljava/lang/Object;)Z"),
                                    new Handle(Opcodes.H_INVOKESTATIC,
                                            "com/oracle/tools/packager/windows/WinAppBundler",
                                            "lambda$copyMSVCDLLs$261", "(Ljava/nio/file/Path;)Z"),
                                    Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter",
                            "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true);
                    mv.visitVarInsn(Opcodes.ALOAD, 5);
                    mv.visitInvokeDynamicInsn("test", "(Ljava/lang/String;)Ljava/util/function/Predicate;",
                            new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
                                    "metafactory",
                                    "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"),
                            new Object[] { Type.getType("(Ljava/lang/Object;)Z"), new Handle(
                                    Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler",
                                    "lambda$copyMSVCDLLs$262", "(Ljava/lang/String;Ljava/nio/file/Path;)Z"),
                                    Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter",
                            "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true);
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitVarInsn(Opcodes.ALOAD, 4);
                    mv.visitInvokeDynamicInsn("accept",
                            "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;)Ljava/util/function/Consumer;",
                            new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
                                    "metafactory",
                                    "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"),
                            new Object[] { Type.getType("(Ljava/lang/Object;)V"), new Handle(
                                    Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler",
                                    "lambda$copyMSVCDLLs$263",
                                    "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;Ljava/nio/file/Path;)V"),
                                    Type.getType("(Ljava/nio/file/Path;)V") }); // modified lambda-name
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "forEach",
                            "(Ljava/util/function/Consumer;)V", true);
                    mv.visitLabel(l4);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    Label l17 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l17);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    Label l18 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l18);
                    mv.visitLabel(l0);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V",
                            true);
                    mv.visitLabel(l1);
                    mv.visitJumpInsn(Opcodes.GOTO, l17);
                    mv.visitLabel(l2);
                    mv.visitFrame(Opcodes.F_FULL, 8,
                            new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile,
                                    javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference",
                                    javalangString, "java/util/stream/Stream", javalangThrowable },
                            1, new Object[] { javalangThrowable });
                    mv.visitVarInsn(Opcodes.ASTORE, 8);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    mv.visitVarInsn(Opcodes.ALOAD, 8);
                    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed",
                            "(Ljava/lang/Throwable;)V", false);
                    mv.visitJumpInsn(Opcodes.GOTO, l17);
                    mv.visitLabel(l18);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V",
                            true);
                    mv.visitJumpInsn(Opcodes.GOTO, l17);
                    mv.visitLabel(l5);
                    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable });
                    mv.visitVarInsn(Opcodes.ASTORE, 8);
                    mv.visitVarInsn(Opcodes.ALOAD, 8);
                    mv.visitVarInsn(Opcodes.ASTORE, 7);
                    mv.visitVarInsn(Opcodes.ALOAD, 8);
                    mv.visitInsn(Opcodes.ATHROW);
                    mv.visitLabel(l6);
                    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable });
                    mv.visitVarInsn(Opcodes.ASTORE, 9);
                    mv.visitLabel(l10);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    Label l19 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l19);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    Label l20 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l20);
                    mv.visitLabel(l7);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V",
                            true);
                    mv.visitLabel(l8);
                    mv.visitJumpInsn(Opcodes.GOTO, l19);
                    mv.visitLabel(l9);
                    mv.visitFrame(Opcodes.F_FULL, 10,
                            new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile,
                                    javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference",
                                    javalangString, "java/util/stream/Stream", javalangThrowable, Opcodes.TOP,
                                    javalangThrowable },
                            1, new Object[] { javalangThrowable });
                    mv.visitVarInsn(Opcodes.ASTORE, 10);
                    mv.visitVarInsn(Opcodes.ALOAD, 7);
                    mv.visitVarInsn(Opcodes.ALOAD, 10);
                    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed",
                            "(Ljava/lang/Throwable;)V", false);
                    mv.visitJumpInsn(Opcodes.GOTO, l19);
                    mv.visitLabel(l20);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V",
                            true);
                    mv.visitLabel(l19);
                    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    mv.visitVarInsn(Opcodes.ALOAD, 9);
                    mv.visitInsn(Opcodes.ATHROW);
                    mv.visitLabel(l17);
                    mv.visitFrame(Opcodes.F_FULL, 6,
                            new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile,
                                    javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference",
                                    javalangString },
                            0, new Object[] {});
                    mv.visitVarInsn(Opcodes.ALOAD, 4);
                    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicReference",
                            "get", "()Ljava/lang/Object;", false);
                    mv.visitTypeInsn(Opcodes.CHECKCAST, "java/io/IOException");
                    mv.visitVarInsn(Opcodes.ASTORE, 6);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    Label l21 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l21);
                    mv.visitVarInsn(Opcodes.ALOAD, 6);
                    mv.visitInsn(Opcodes.ATHROW);
                    mv.visitLabel(l21);
                    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/io/IOException" }, 0, null);
                    mv.visitInsn(Opcodes.RETURN);
                }

            };
        }

    }, ClassReader.EXPAND_FRAMES); // ClassReader.EXPAND_FRAMES required for Java 8
}

From source file:edu.illinois.nondex.instr.IdentityHashMapShufflingAdder.java

License:Open Source License

public void addHasNext() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "hasNext", "()Z", null, null);
    mv.visitCode();/*from   w  ww. j  a  va  2 s .  c o m*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "order",
            "Ljava/util/List;");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I", true);
    Label l0 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l0);
    mv.visitInsn(Opcodes.ICONST_1);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l1);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();
}

From source file:io.awacs.plugin.springmvc.ServiceWrapper.java

License:Apache License

/**
 * origin method: (XXX)X//  ww w.j av a  2  s  .  co m
 * <p>
 * proxy method: (XXXLjavax/servlet/http/HttpServletRequest;)X
 * req -> localIndex - 1
 *
 * @param cn
 * @param origin
 * @return
 */
private MethodNode doProxy(ClassNode cn, MethodNode origin) {

    MethodNode newNode = copyMethod(origin);
    //move annotations
    hideAnnotations(origin);

    LabelNode l0 = new LabelNode();
    LabelNode l1 = new LabelNode();
    LabelNode l2 = new LabelNode();

    String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1);

    int localIndex = copyParameters(origin, newNode, l0, l2);

    newNode.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception"));

    //localIndex -> elapsedTime
    newNode.localVariables.add(new LocalVariableNode("elapsedTime", "J", null, l0, l1, localIndex));

    //
    newNode.instructions.add(l0);

    // long elapsedTime = System.currentTimeMillis();
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"));
    newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex));

    int paramCount = getParamCount(origin.desc, origin.access);

    //load?
    for (int i = 0; i < paramCount; i++) {
        LocalVariableNode node = (LocalVariableNode) newNode.localVariables.get(i);
        switch (node.desc) {
        case "J":
            newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, node.index));
            break;
        case "D":
            newNode.instructions.add(new VarInsnNode(Opcodes.DLOAD, node.index));
            break;
        case "F":
            newNode.instructions.add(new VarInsnNode(Opcodes.FLOAD, node.index));
            break;
        case "I":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "S":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "Z":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "B":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        case "C":
            newNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, node.index));
            break;
        default:
            newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, node.index));
            break;
        }
    }
    //
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, cn.name, origin.name, origin.desc));

    //
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"));
    newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex));
    newNode.instructions.add(new InsnNode(Opcodes.LSUB));
    newNode.instructions.add(new VarInsnNode(Opcodes.LSTORE, localIndex));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1));
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE,
            "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;"));

    //?
    newNode.instructions.add(new VarInsnNode(Opcodes.LLOAD, localIndex));
    //SpringmvcPlugin.incrAccess(uri, elapsedTime);
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/springmvc/SpringmvcPlugin", "incrAccess", "(Ljava/lang/String;J)V"));
    //
    newNode.instructions.add(l1);
    switch (returnType) {
    case "J":
        newNode.instructions.add(new InsnNode(Opcodes.LRETURN));
        break;
    case "D":
        newNode.instructions.add(new InsnNode(Opcodes.DRETURN));
        break;
    case "F":
        newNode.instructions.add(new InsnNode(Opcodes.FRETURN));
        break;
    case "I":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "S":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "C":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "B":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "Z":
        newNode.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    default:
        newNode.instructions.add(new InsnNode(Opcodes.ARETURN));
        break;
    }

    newNode.instructions.add(l2);
    newNode.instructions
            .add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" }));
    newNode.instructions.add(new VarInsnNode(Opcodes.ASTORE, localIndex));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex - 1));
    newNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE,
            "javax/servlet/http/HttpServletRequest", "getRequestURI", "()Ljava/lang/String;"));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex));
    newNode.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/springmvc/SpringmvcPlugin",
                    "incrFailure", "(Ljava/lang/String;Ljava/lang/Throwable;)V"));

    newNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, localIndex));
    newNode.instructions.add(new InsnNode(Opcodes.ATHROW));
    newNode.maxLocals = origin.maxLocals + 3;
    newNode.maxStack = Math.max(localIndex + 2, 6);
    return newNode;
}

From source file:io.awacs.plugin.stacktrace.ClassTransformer.java

License:Apache License

/**
 * ?/*  www  .j a v  a  2s.c  o m*/
 * 1?try catch?                 try{
 * 2????        io.awacs.plugin.stacktrace.StackFrames.init();
 * 3????                io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,0);
 * 4?                          Object val = methodName_origin_className(args);
 * 5?????                io.awacs.plugin.stacktrace.StackFrames.push(className,methodName,1);
 * 5???          List list = io.awacs.plugin.stacktrace.StackFrames.dump();
 * 7?????          io.awacs.plugin.stacktrace.StackTracePlugin.incrAccess(list);
 * 8?                          return val;
 * }catch(java.lang.Exception e){
 * 9??                io.awacs.plugin.stacktrace.StackTracePlugin.incrFailure(e);
 * 10?               throw e;
 * }
 */
private void transformTerminatedMethod(MethodNode origin, MethodNode proxy, ClassNode owner) {
    LabelNode l0 = new LabelNode();
    LabelNode l1 = new LabelNode();
    LabelNode l2 = new LabelNode();
    //try catch?
    proxy.tryCatchBlocks.add(new TryCatchBlockNode(l0, l1, l2, "java/lang/Exception"));
    proxy.instructions.add(l0);
    //?
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "init", "()V", false));
    proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", ".")));
    proxy.instructions.add(new LdcInsnNode(proxy.name));
    proxy.instructions.add(new LdcInsnNode(0));
    //
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false));
    int varIndex = 0;//???
    //???,????this?
    if ((proxy.access & Opcodes.ACC_STATIC) != Opcodes.ACC_STATIC) {
        proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
        varIndex = 1;
    }
    List<String> parameters = resolveParameters(proxy.desc);
    //???
    for (String param : parameters) {
        VarInsnNode insnNode;
        switch (param) {
        case "J":
            insnNode = new VarInsnNode(Opcodes.LLOAD, varIndex);
            varIndex += 2;
            break;
        case "D":
            insnNode = new VarInsnNode(Opcodes.DLOAD, varIndex);
            varIndex += 2;
            break;
        case "F":
            insnNode = new VarInsnNode(Opcodes.FLOAD, varIndex++);
            break;
        case "I":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "S":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "Z":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "B":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        case "C":
            insnNode = new VarInsnNode(Opcodes.ILOAD, varIndex++);
            break;
        default:
            insnNode = new VarInsnNode(Opcodes.ALOAD, varIndex++);
            break;
        }
        proxy.instructions.add(insnNode);
    }
    //
    if ((origin.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC)
        proxy.instructions
                .add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner.name, origin.name, origin.desc, false));
    else
        proxy.instructions
                .add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, owner.name, origin.name, origin.desc, false));
    proxy.instructions.add(new LdcInsnNode(owner.name.replaceAll("/", ".")));
    proxy.instructions.add(new LdcInsnNode(proxy.name));
    proxy.instructions.add(new LdcInsnNode(1));
    //?
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "push", "(Ljava/lang/String;Ljava/lang/String;I)V", false));
    //??
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "io/awacs/plugin/stacktrace/StackFrames",
            "dump", "()Ljava/util/List;", false));
    //???
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/stacktrace/StackTracePlugin", "incrAccess", "(Ljava/util/List;)V", false));
    proxy.instructions.add(l1);
    //
    String returnType = origin.desc.substring(origin.desc.indexOf(')') + 1);
    switch (returnType) {
    case "J":
        proxy.instructions.add(new InsnNode(Opcodes.LRETURN));
        break;
    case "D":
        proxy.instructions.add(new InsnNode(Opcodes.DRETURN));
        break;
    case "F":
        proxy.instructions.add(new InsnNode(Opcodes.FRETURN));
        break;
    case "I":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "S":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "C":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "B":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "Z":
        proxy.instructions.add(new InsnNode(Opcodes.IRETURN));
        break;
    case "V":
        proxy.instructions.add(new InsnNode(Opcodes.RETURN));
        break;
    default:
        proxy.instructions.add(new InsnNode(Opcodes.ARETURN));
        break;
    }
    proxy.instructions.add(l2);
    //?
    proxy.instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Exception" }));
    proxy.instructions.add(new VarInsnNode(Opcodes.ASTORE, varIndex));
    proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex));
    proxy.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
            "io/awacs/plugin/stacktrace/StackTracePlugin", "incrFailure", "(Ljava/lang/Throwable;)V", false));
    proxy.instructions.add(new VarInsnNode(Opcodes.ALOAD, varIndex));
    proxy.instructions.add(new InsnNode(Opcodes.ATHROW));
    proxy.maxLocals = varIndex + 1;
    proxy.maxStack = Math.max(varIndex, 5);
}

From source file:io.github.btpka3.asm.H.java

public static byte[] dump() throws Exception {

    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;/*from  ww w. j  a  v a  2 s  .  c  o  m*/
    MethodVisitor mv;
    AnnotationVisitor av0;

    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "JP/co/esm/caddies/jomt/license/h", null, "java/lang/Object", null);

    {
        fv = cw.visitField(ACC_PUBLIC + ACC_STATIC, "a", "Ljava/lang/String;", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "b", "Z", null, null);
        fv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "c", "Lorg/slf4j/Logger;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }

    // public static boolean a()
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "a", "()Z", null, null);
        mv.visitCode();
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/license/h", "a", "Ljava/lang/String;");
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "(Ljava/lang/String;)Z",
                false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/license/h", "a", "Ljava/lang/String;");
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "d", "(Ljava/lang/String;)V",
                false);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/jsystem/c", "q", "Z");
        Label l1 = new Label();
        mv.visitJumpInsn(IFEQ, l1);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "Z");
        Label l2 = new Label();
        mv.visitJumpInsn(IFNE, l2);
        mv.visitLdcInsn("app");
        mv.visitLdcInsn("without_any_license");
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jview/eO", "d",
                "(Ljava/lang/String;Ljava/lang/String;)V", false);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "Z");
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/jsystem/c", "q", "Z");
        Label l3 = new Label();
        mv.visitJumpInsn(IFNE, l3);
        mv.visitInsn(ICONST_1);
        Label l4 = new Label();
        mv.visitJumpInsn(GOTO, l4);
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(ICONST_0);
        mv.visitLabel(l4);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
        mv.visitInsn(IRETURN);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "()Ljava/lang/String;",
                false);
        mv.visitVarInsn(ASTORE, 0);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/license/h", "a", "Ljava/lang/String;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "a",
                "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
        mv.visitInsn(POP);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/jsystem/c", "p", "Z");
        mv.visitInsn(ICONST_1);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/String");
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "a",
                "(Ljava/lang/String;)Ljava/lang/String;", false);
        mv.visitInsn(AASTORE);
        mv.visitLdcInsn("app");
        mv.visitLdcInsn("license_evaluation_term.message");
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jview/eO", "e",
                "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V", false);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/p", "c",
                "()LJP/co/esm/caddies/jomt/license/p;", false);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jsystem/j", "d", "()Ljava/lang/String;",
                false);
        mv.visitLdcInsn("P");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
        Label l5 = new Label();
        mv.visitJumpInsn(IFEQ, l5);
        mv.visitLdcInsn("astah_professional");
        Label l6 = new Label();
        mv.visitJumpInsn(GOTO, l6);
        mv.visitLabel(l5);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "JP/co/esm/caddies/jomt/license/p" });
        mv.visitLdcInsn("astah_UML");
        mv.visitLabel(l6);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 2,
                new Object[] { "JP/co/esm/caddies/jomt/license/p", "java/lang/String" });
        mv.visitLdcInsn("USER_TYPE");
        mv.visitLdcInsn("Evaluation");
        mv.visitMethodInsn(INVOKEVIRTUAL, "JP/co/esm/caddies/jomt/license/p", "a",
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(4, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "b", "()Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitLdcInsn("yyyy/MM/dd");
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jutil/JomtUtilities", "getDateString",
                "(Ljava/lang/String;)Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(1, 0);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "f", "(Ljava/lang/String;)Ljava/util/GregorianCalendar;",
                null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(ICONST_4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitVarInsn(ISTORE, 1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_5);
        mv.visitIntInsn(BIPUSH, 7);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(ISUB);
        mv.visitVarInsn(ISTORE, 2);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitIntInsn(BIPUSH, 8);
        mv.visitIntInsn(BIPUSH, 10);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitVarInsn(ISTORE, 3);
        mv.visitTypeInsn(NEW, "java/util/GregorianCalendar");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitVarInsn(ILOAD, 2);
        mv.visitVarInsn(ILOAD, 3);
        mv.visitMethodInsn(INVOKESPECIAL, "java/util/GregorianCalendar", "<init>", "(III)V", false);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(5, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "c", "()Ljava/util/GregorianCalendar;", null, null);
        mv.visitCode();
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "()Ljava/lang/String;",
                false);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "f",
                "(Ljava/lang/String;)Ljava/util/GregorianCalendar;", false);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(1, 0);
        mv.visitEnd();
    }

    // private static GregorianCalendar g(String var0)
    {
        mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC, "g", "(Ljava/lang/String;)Ljava/util/GregorianCalendar;",
                null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(ICONST_4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitVarInsn(ISTORE, 1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitInsn(ICONST_5);
        mv.visitIntInsn(BIPUSH, 7);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(ISUB);
        mv.visitVarInsn(ISTORE, 2);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitIntInsn(BIPUSH, 8);
        mv.visitIntInsn(BIPUSH, 10);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;", false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I", false);
        mv.visitVarInsn(ISTORE, 3);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "c",
                "()Ljava/util/GregorianCalendar;", false);
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitVarInsn(ILOAD, 2);
        mv.visitVarInsn(ILOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "set", "(III)V", false);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitInsn(ICONST_5);
        //mv.visitIntInsn(BIPUSH, 20);
        mv.visitIntInsn(BIPUSH, 3650);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "add", "(II)V", false);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(4, 5);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "a", "(Ljava/lang/String;)Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "g",
                "(Ljava/lang/String;)Ljava/util/GregorianCalendar;", false);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "getTime", "()Ljava/util/Date;",
                false);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKESTATIC, "java/text/DateFormat", "getDateInstance", "(I)Ljava/text/DateFormat;",
                false);
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/text/DateFormat", "format",
                "(Ljava/util/Date;)Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(2, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "b", "(Ljava/lang/String;)Z", null, null);
        mv.visitCode();
        mv.visitTypeInsn(NEW, "java/io/File");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/File", "<init>", "(Ljava/lang/String;)V", false);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/File", "exists", "()Z", false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(3, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "c", "(Ljava/lang/String;)Ljava/lang/String;", null, null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
        mv.visitLdcInsn("");
        mv.visitVarInsn(ASTORE, 1);
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitLabel(l0);
        mv.visitTypeInsn(NEW, "java/util/zip/GZIPInputStream");
        mv.visitInsn(DUP);
        mv.visitTypeInsn(NEW, "java/io/FileInputStream");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/FileInputStream", "<init>", "(Ljava/lang/String;)V", false);
        mv.visitMethodInsn(INVOKESPECIAL, "java/util/zip/GZIPInputStream", "<init>", "(Ljava/io/InputStream;)V",
                false);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitTypeInsn(NEW, "java/io/InputStreamReader");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitLdcInsn("UTF-8");
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/InputStreamReader", "<init>",
                "(Ljava/io/InputStream;Ljava/lang/String;)V", false);
        mv.visitVarInsn(ASTORE, 3);
        mv.visitTypeInsn(NEW, "java/io/BufferedReader");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/BufferedReader", "<init>", "(Ljava/io/Reader;)V", false);
        mv.visitVarInsn(ASTORE, 4);
        Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_FULL, 5, new Object[] { Opcodes.TOP, "java/lang/String", Opcodes.TOP,
                Opcodes.TOP, "java/io/BufferedReader" }, 0, new Object[] {});
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "readLine", "()Ljava/lang/String;", false);
        mv.visitInsn(DUP);
        mv.visitVarInsn(ASTORE, 5);
        Label l4 = new Label();
        mv.visitJumpInsn(IFNULL, l4);
        mv.visitVarInsn(ALOAD, 5);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", false);
        mv.visitJumpInsn(IFLE, l3);
        mv.visitVarInsn(ALOAD, 5);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitJumpInsn(GOTO, l3);
        mv.visitLabel(l4);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedReader", "close", "()V", false);
        mv.visitLabel(l1);
        Label l5 = new Label();
        mv.visitJumpInsn(GOTO, l5);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 1, new Object[] { "java/lang/Exception" });
        mv.visitVarInsn(ASTORE, 3);
        mv.visitFieldInsn(GETSTATIC, "JP/co/esm/caddies/jomt/license/h", "c", "Lorg/slf4j/Logger;");
        mv.visitLdcInsn("error has occurred.");
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEINTERFACE, "org/slf4j/Logger", "error",
                "(Ljava/lang/String;Ljava/lang/Throwable;)V", true);
        mv.visitInsn(ACONST_NULL);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l5);
        mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { Opcodes.TOP, "java/lang/String" }, 0, null);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(5, 6);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "a",
                "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", null, null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/io/IOException");
        Label l3 = new Label();
        Label l4 = new Label();
        Label l5 = new Label();
        mv.visitTryCatchBlock(l3, l4, l5, "java/lang/Throwable");
        Label l6 = new Label();
        Label l7 = new Label();
        Label l8 = new Label();
        mv.visitTryCatchBlock(l6, l7, l8, "java/io/IOException");
        Label l9 = new Label();
        mv.visitTryCatchBlock(l3, l4, l9, null);
        Label l10 = new Label();
        mv.visitTryCatchBlock(l5, l10, l9, null);
        Label l11 = new Label();
        Label l12 = new Label();
        Label l13 = new Label();
        mv.visitTryCatchBlock(l11, l12, l13, "java/io/IOException");
        Label l14 = new Label();
        mv.visitTryCatchBlock(l9, l14, l9, null);
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitLabel(l3);
        mv.visitTypeInsn(NEW, "java/io/BufferedWriter");
        mv.visitInsn(DUP);
        mv.visitTypeInsn(NEW, "java/io/OutputStreamWriter");
        mv.visitInsn(DUP);
        mv.visitTypeInsn(NEW, "java/util/zip/GZIPOutputStream");
        mv.visitInsn(DUP);
        mv.visitTypeInsn(NEW, "java/io/FileOutputStream");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/FileOutputStream", "<init>", "(Ljava/lang/String;)V", false);
        mv.visitMethodInsn(INVOKESPECIAL, "java/util/zip/GZIPOutputStream", "<init>",
                "(Ljava/io/OutputStream;)V", false);
        mv.visitLdcInsn("UTF-8");
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/OutputStreamWriter", "<init>",
                "(Ljava/io/OutputStream;Ljava/lang/String;)V", false);
        mv.visitMethodInsn(INVOKESPECIAL, "java/io/BufferedWriter", "<init>", "(Ljava/io/Writer;)V", false);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedWriter", "write", "(Ljava/lang/String;)V", false);
        mv.visitLabel(l4);
        mv.visitVarInsn(ALOAD, 2);
        Label l15 = new Label();
        mv.visitJumpInsn(IFNULL, l15);
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedWriter", "close", "()V", false);
        mv.visitLabel(l1);
        mv.visitJumpInsn(GOTO, l15);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 1, new Object[] { "java/io/IOException" });
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "getMessage", "()Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l5);
        mv.visitFrame(Opcodes.F_FULL, 3, new Object[] { Opcodes.TOP, Opcodes.TOP, "java/io/BufferedWriter" }, 1,
                new Object[] { "java/lang/Throwable" });
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;", false);
        mv.visitVarInsn(ASTORE, 4);
        mv.visitLabel(l10);
        mv.visitVarInsn(ALOAD, 2);
        Label l16 = new Label();
        mv.visitJumpInsn(IFNULL, l16);
        mv.visitLabel(l6);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedWriter", "close", "()V", false);
        mv.visitLabel(l7);
        mv.visitJumpInsn(GOTO, l16);
        mv.visitLabel(l8);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 1, new Object[] { "java/io/IOException" });
        mv.visitVarInsn(ASTORE, 5);
        mv.visitVarInsn(ALOAD, 5);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "getMessage", "()Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l16);
        mv.visitFrame(Opcodes.F_FULL, 5,
                new Object[] { Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, "java/lang/String" }, 0,
                new Object[] {});
        mv.visitVarInsn(ALOAD, 4);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l9);
        mv.visitFrame(Opcodes.F_FULL, 3, new Object[] { Opcodes.TOP, Opcodes.TOP, "java/io/BufferedWriter" }, 1,
                new Object[] { "java/lang/Throwable" });
        mv.visitVarInsn(ASTORE, 6);
        mv.visitLabel(l14);
        mv.visitVarInsn(ALOAD, 2);
        Label l17 = new Label();
        mv.visitJumpInsn(IFNULL, l17);
        mv.visitLabel(l11);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/BufferedWriter", "close", "()V", false);
        mv.visitLabel(l12);
        mv.visitJumpInsn(GOTO, l17);
        mv.visitLabel(l13);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 1, new Object[] { "java/io/IOException" });
        mv.visitVarInsn(ASTORE, 7);
        mv.visitVarInsn(ALOAD, 7);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/IOException", "getMessage", "()Ljava/lang/String;", false);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l17);
        mv.visitFrame(Opcodes.F_FULL, 7, new Object[] { Opcodes.TOP, Opcodes.TOP, Opcodes.TOP, Opcodes.TOP,
                Opcodes.TOP, Opcodes.TOP, "java/lang/Throwable" }, 0, new Object[] {});
        mv.visitVarInsn(ALOAD, 6);
        mv.visitInsn(ATHROW);
        mv.visitLabel(l15);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 0, new Object[] {});
        mv.visitLdcInsn("");
        mv.visitInsn(ARETURN);
        mv.visitMaxs(9, 8);
        mv.visitEnd();
    }

    // public static void d(String var0)
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "d", "(Ljava/lang/String;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "c",
                "(Ljava/lang/String;)Ljava/lang/String;", false);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "e", "(Ljava/lang/String;)Z",
                false);
        mv.visitVarInsn(ISTORE, 2);
        mv.visitVarInsn(ILOAD, 2);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/jsystem/c", "p", "Z");
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/p", "c",
                "()LJP/co/esm/caddies/jomt/license/p;", false);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jsystem/j", "d", "()Ljava/lang/String;",
                false);
        mv.visitLdcInsn("P");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
        Label l1 = new Label();
        mv.visitJumpInsn(IFEQ, l1);
        mv.visitLdcInsn("astah_professional");
        Label l2 = new Label();
        mv.visitJumpInsn(GOTO, l2);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { Opcodes.TOP, "java/lang/String" }, 1,
                new Object[] { "JP/co/esm/caddies/jomt/license/p" });
        mv.visitLdcInsn("astah_UML");
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { Opcodes.TOP, "java/lang/String" }, 2,
                new Object[] { "JP/co/esm/caddies/jomt/license/p", "java/lang/String" });
        mv.visitLdcInsn("USER_TYPE");
        mv.visitLdcInsn("Evaluation");
        mv.visitMethodInsn(INVOKEVIRTUAL, "JP/co/esm/caddies/jomt/license/p", "a",
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", false);
        mv.visitInsn(ICONST_1);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/String");
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "a",
                "(Ljava/lang/String;)Ljava/lang/String;", false);
        mv.visitInsn(AASTORE);
        mv.visitLdcInsn("app");
        mv.visitLdcInsn("license_evaluation_term.message");
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jview/eO", "e",
                "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V", false);
        Label l3 = new Label();
        mv.visitJumpInsn(GOTO, l3);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_CHOP, 2, null, 0, null);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/jsystem/c", "q", "Z");
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(RETURN);
        mv.visitMaxs(4, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "e", "(Ljava/lang/String;)Z", null, null);
        mv.visitCode();
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "c",
                "()Ljava/util/GregorianCalendar;", false);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "f",
                "(Ljava/lang/String;)Ljava/util/GregorianCalendar;", false);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/license/h", "g",
                "(Ljava/lang/String;)Ljava/util/GregorianCalendar;", false);
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "equals", "(Ljava/lang/Object;)Z",
                false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_FULL, 4, new Object[] { Opcodes.TOP, "java/util/GregorianCalendar",
                "java/util/GregorianCalendar", "java/util/GregorianCalendar" }, 0, new Object[] {});
        mv.visitVarInsn(ALOAD, 3);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "equals", "(Ljava/lang/Object;)Z",
                false);
        Label l1 = new Label();
        mv.visitJumpInsn(IFEQ, l1);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "before", "(Ljava/lang/Object;)Z",
                false);
        Label l2 = new Label();
        mv.visitJumpInsn(IFEQ, l2);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/GregorianCalendar", "before", "(Ljava/lang/Object;)Z",
                false);
        mv.visitJumpInsn(IFEQ, l2);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_FULL, 0, new Object[] {}, 0, new Object[] {});
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(2, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
        mv.visitCode();
        mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
        mv.visitMethodInsn(INVOKESTATIC, "JP/co/esm/caddies/jomt/jsystem/j", "s", "()Ljava/lang/String;",
                false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitFieldInsn(GETSTATIC, "java/io/File", "separator", "Ljava/lang/String;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitLdcInsn(".ael");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/license/h", "a", "Ljava/lang/String;");
        mv.visitInsn(ICONST_0);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/license/h", "b", "Z");
        mv.visitLdcInsn(Type.getType("LJP/co/esm/caddies/jomt/license/h;"));
        mv.visitMethodInsn(INVOKESTATIC, "org/slf4j/LoggerFactory", "getLogger",
                "(Ljava/lang/Class;)Lorg/slf4j/Logger;", false);
        mv.visitFieldInsn(PUTSTATIC, "JP/co/esm/caddies/jomt/license/h", "c", "Lorg/slf4j/Logger;");
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 0);
        mv.visitEnd();
    }
    cw.visitEnd();

    return cw.toByteArray();
}

From source file:io.syncframework.optimizer.OControllerStaticMethodVisitor.java

License:Apache License

public void visitInsn(int opcode) {
    if (opcode != Opcodes.RETURN) {
        mv.visitInsn(opcode);//from  ww  w  . ja v a 2 s.  c  o  m
        return;
    }

    Label start = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    Label interceptorsLabel = new Label();

    mv.visitCode();
    mv.visitTryCatchBlock(start, l1, l2, "java/lang/Throwable");

    /*
     * _asActions = new HashMap<String,Boolean>();
     */
    {
        mv.visitLabel(start);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;");
    }
    /*
     * _asActions.put("main", true);
     * _asActions.put("action1", true);
     */
    for (String name : reflector.getActions().keySet()) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asActions", "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;",
                false);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /*
     * _asInterceptors = new HashMap<String,Class<?>[]>()
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asInterceptors",
                "Ljava/util/Map;");
    }

    /*
     * List<Class<?>> l = new ArrayList<Class<?>>();
     */
    mv.visitLabel(interceptorsLabel);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
    mv.visitVarInsn(Opcodes.ASTORE, 0);

    for (String name : reflector.getActions().keySet()) {
        Class<?> interceptors[] = reflector.getInterceptors().get(name);
        if (interceptors == null || interceptors.length == 0)
            continue;

        /*
         * l.clear();
         */
        Label l01 = new Label();
        mv.visitLabel(l01);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "clear", "()V", true);

        for (Class<?> interceptor : interceptors) {
            /*
             * l.add(LoginInterceptor.class);
             */
            Label l02 = new Label();
            mv.visitLabel(l02);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitLdcInsn(Type.getType(interceptor));
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
        }

        /*
         * _asInterceptors.put("upload", l.toArray(new Class[0]));
         */
        Label l03 = new Label();
        mv.visitLabel(l03);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asInterceptors",
                "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Class");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "toArray",
                "([Ljava/lang/Object;)[Ljava/lang/Object;", true);
        mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /* 
     * _asParameters = new HashMap<String,Class<?>>() 
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
    }
    /*
     * _asParameters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asParameters",
                "Ljava/util/Map;");
        mv.visitLdcInsn(name);
        mv.visitLdcInsn(Type.getType(reflector.getParameters().get(name)));
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
        mv.visitInsn(Opcodes.POP);
    }

    /* 
     * _asConverters = new HashMap<String,Class<?>>() 
     */
    {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitTypeInsn(Opcodes.NEW, "java/util/HashMap");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false);
        mv.visitFieldInsn(Opcodes.PUTSTATIC, reflector.getClazzInternalName(), "_asConverters",
                "Ljava/util/Map;");
    }
    /*
     * _asConverters.put("name", Type.class);
     */
    for (String name : reflector.getParameters().keySet()) {
        if (reflector.getConverters().get(name) != null) {
            Class<?> converter = reflector.getConverters().get(name);
            Label l = new Label();
            mv.visitLabel(l);
            mv.visitFieldInsn(Opcodes.GETSTATIC, reflector.getClazzInternalName(), "_asConverters",
                    "Ljava/util/Map;");
            mv.visitLdcInsn(name);
            mv.visitLdcInsn(Type.getType(converter));
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "put",
                    "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
            mv.visitInsn(Opcodes.POP);
        }
    }

    /*
     * }
     * catch(Throwable t) {
     *    throw t;
     * }
     */
    Label throwableStart = new Label();
    Label throwableEnd = new Label();

    mv.visitLabel(l1);
    mv.visitJumpInsn(Opcodes.GOTO, throwableEnd);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" });
    mv.visitVarInsn(Opcodes.ASTORE, 0);
    mv.visitLabel(throwableStart);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ATHROW);

    mv.visitLabel(throwableEnd);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitLocalVariable("l", "Ljava/util/List;", null, interceptorsLabel, l1, 0);
    mv.visitLocalVariable("t", "Ljava/lang/Throwable;", null, throwableStart, throwableEnd, 0);
}