Example usage for org.objectweb.asm MethodVisitor visitFrame

List of usage examples for org.objectweb.asm MethodVisitor visitFrame

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitFrame.

Prototype

public void visitFrame(final int type, final int numLocal, final Object[] local, final int numStack,
        final Object[] stack) 

Source Link

Document

Visits the current state of the local variables and operand stack elements.

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 w w  .  ja v  a2 s .  co m
        fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC, "unsafe", "Lsun/misc/Unsafe;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "containsVLA", "()Z", null, null);
        mv.visitCode();
        //if layout contains VLA return true, otherwise false
        if (layoutContainsVLA) {
            mv.visitInsn(ICONST_1);
        } else {
            mv.visitInsn(ICONST_0);
        }
        mv.visitInsn(IRETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        fv = cw.visitField(ACC_PROTECTED, "location", "Lcom/ibm/layout/Location;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "bindLocation", "(Lcom/ibm/layout/Location;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "checkDataFits", "(J)Z", false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFEQ, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitFieldInsn(PUTFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(RETURN);
        mv.visitMaxs(3, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "writeToByteArray", "(J[BII)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(I2L);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitInsn(LCMP);
        Label l0 = new Label();
        mv.visitJumpInsn(IFLE, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitInsn(L2I);
        mv.visitVarInsn(ISTORE, 5);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        Label l1 = new Label();
        mv.visitJumpInsn(IFNULL, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitInsn(L2I);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitVarInsn(ILOAD, 4);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy",
                "(Ljava/lang/Object;ILjava/lang/Object;II)V", false);
        Label l2 = new Label();
        mv.visitJumpInsn(GOTO, l2);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;");
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitInsn(LADD);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;");
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "arrayBaseOffset", "(Ljava/lang/Class;)I", false);
        mv.visitInsn(I2L);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(I2L);
        mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "copyMemory",
                "(Ljava/lang/Object;JLjava/lang/Object;JJ)V", false);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(9, 6);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "readFromByteArray", "(J[BII)I", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(I2L);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitInsn(LCMP);
        Label l0 = new Label();
        mv.visitJumpInsn(IFLE, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitInsn(L2I);
        mv.visitVarInsn(ISTORE, 5);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        Label l1 = new Label();
        mv.visitJumpInsn(IFNULL, l1);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitVarInsn(ILOAD, 4);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitInsn(L2I);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy",
                "(Ljava/lang/Object;ILjava/lang/Object;II)V", false);
        Label l2 = new Label();
        mv.visitJumpInsn(GOTO, l2);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;");
        mv.visitVarInsn(ALOAD, 3);
        mv.visitFieldInsn(GETSTATIC, typeName, "unsafe", "Lsun/misc/Unsafe;");
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "arrayBaseOffset", "(Ljava/lang/Class;)I", false);
        mv.visitVarInsn(ILOAD, 4);
        mv.visitInsn(IADD);
        mv.visitInsn(I2L);
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitInsn(LADD);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(I2L);
        mv.visitMethodInsn(INVOKEVIRTUAL, "sun/misc/Unsafe", "copyMemory",
                "(Ljava/lang/Object;JLjava/lang/Object;JJ)V", false);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ILOAD, 5);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(9, 6);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "asByteBuffer", "()Ljava/nio/ByteBuffer;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFNULL, l0);
        mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
        mv.visitInsn(DUP);
        mv.visitLdcInsn("not off-heap");
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
                "(Ljava/lang/String;)V", false);
        mv.visitInsn(ATHROW);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, typeName, "sizeof", "()J", false);
        mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/UnsafeHelper", "bufferFromAddress",
                "(JJ)Ljava/nio/ByteBuffer;", false);
        mv.visitVarInsn(ASTORE, 1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "java/nio/ByteOrder", "nativeOrder", "()Ljava/nio/ByteOrder;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/nio/ByteBuffer", "order",
                "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;", false);
        mv.visitInsn(POP);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(4, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "asByteBuffer",
                "(Lcom/ibm/layout/Location;J)Ljava/nio/ByteBuffer;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getData", "()[B", false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFNULL, l0);
        mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
        mv.visitInsn(DUP);
        mv.visitLdcInsn("not off-heap");
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
                "(Ljava/lang/String;)V", false);
        mv.visitInsn(ATHROW);
        mv.visitLabel(l0);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/Location", "getOffset", "()J", false);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/UnsafeHelper", "bufferFromAddress",
                "(JJ)Ljava/nio/ByteBuffer;", false);
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitMethodInsn(INVOKESTATIC, "java/nio/ByteOrder", "nativeOrder", "()Ljava/nio/ByteOrder;", false);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/nio/ByteBuffer", "order",
                "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;", false);
        mv.visitInsn(POP);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(4, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "unsafeCast", "(Ljava/lang/Class;)Lcom/ibm/layout/Layout;",
                "<T::Lcom/ibm/layout/Layout;>(Ljava/lang/Class<TT;>;)TT;", null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException");
        Label l3 = new Label();
        mv.visitTryCatchBlock(l0, l1, l3, "java/lang/SecurityException");
        Label l4 = new Label();
        mv.visitTryCatchBlock(l0, l1, l4, "java/lang/InstantiationException");
        Label l5 = new Label();
        mv.visitTryCatchBlock(l0, l1, l5, "java/lang/IllegalAccessException");
        Label l6 = new Label();
        mv.visitTryCatchBlock(l0, l1, l6, "java/lang/IllegalArgumentException");
        Label l7 = new Label();
        mv.visitTryCatchBlock(l0, l1, l7, "java/lang/reflect/InvocationTargetException");
        mv.visitLabel(l0);
        mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/LayoutHelper", "getFactory",
                "()Lcom/ibm/layout/LayoutHelper;", false);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genLayoutImpl",
                "(Ljava/lang/Class;)Ljava/lang/Class;", false);
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitInsn(ICONST_0);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Class");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor",
                "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false);
        mv.visitVarInsn(ASTORE, 3);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false);
        mv.visitVarInsn(ALOAD, 3);
        mv.visitInsn(ICONST_0);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance",
                "([Ljava/lang/Object;)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Layout");
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Layout", "bindLocation",
                "(Lcom/ibm/layout/Location;)V", true);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitLabel(l1);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V", false);
        Label l8 = new Label();
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/SecurityException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/SecurityException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l4);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/InstantiationException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/InstantiationException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l5);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalAccessException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalAccessException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l6);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalArgumentException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalArgumentException", "printStackTrace", "()V",
                false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l7);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1,
                new Object[] { "java/lang/reflect/InvocationTargetException" });
        mv.visitVarInsn(ASTORE, 2);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace",
                "()V", false);
        mv.visitLabel(l8);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(ACONST_NULL);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(2, 5);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "unsafeCast",
                "(Ljava/lang/Class;J)Lcom/ibm/layout/Array1D;",
                "<T::Lcom/ibm/layout/Layout;>(Ljava/lang/Class<TT;>;J)Lcom/ibm/layout/Array1D<TT;>;", null);
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchMethodException");
        Label l3 = new Label();
        mv.visitTryCatchBlock(l0, l1, l3, "java/lang/SecurityException");
        Label l4 = new Label();
        mv.visitTryCatchBlock(l0, l1, l4, "java/lang/InstantiationException");
        Label l5 = new Label();
        mv.visitTryCatchBlock(l0, l1, l5, "java/lang/IllegalAccessException");
        Label l6 = new Label();
        mv.visitTryCatchBlock(l0, l1, l6, "java/lang/IllegalArgumentException");
        Label l7 = new Label();
        mv.visitTryCatchBlock(l0, l1, l7, "java/lang/reflect/InvocationTargetException");
        mv.visitLabel(l0);
        mv.visitMethodInsn(INVOKESTATIC, "com/ibm/layout/LayoutHelper", "getFactory",
                "()Lcom/ibm/layout/LayoutHelper;", false);
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genLayoutImpl",
                "(Ljava/lang/Class;)Ljava/lang/Class;", false);
        mv.visitVarInsn(ASTORE, 5);
        mv.visitVarInsn(ALOAD, 5);
        mv.visitInsn(ICONST_0);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Class");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor",
                "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false);
        mv.visitVarInsn(ASTORE, 6);
        mv.visitVarInsn(ALOAD, 6);
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false);
        mv.visitVarInsn(ALOAD, 6);
        mv.visitInsn(ICONST_0);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance",
                "([Ljava/lang/Object;)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Layout");
        mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Layout", "sizeof", "()J", true);
        mv.visitVarInsn(LSTORE, 7);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "com/ibm/layout/LayoutHelper", "genArray1DImpl",
                "(Ljava/lang/Class;)Ljava/lang/Class;", false);
        mv.visitVarInsn(ASTORE, 9);
        mv.visitVarInsn(ALOAD, 9);
        mv.visitInsn(ICONST_2);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Class");
        mv.visitInsn(DUP);
        mv.visitInsn(ICONST_0);
        mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
        mv.visitInsn(AASTORE);
        mv.visitInsn(DUP);
        mv.visitInsn(ICONST_1);
        mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
        mv.visitInsn(AASTORE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getDeclaredConstructor",
                "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;", false);
        mv.visitVarInsn(ASTORE, 10);
        mv.visitVarInsn(ALOAD, 10);
        mv.visitInsn(ICONST_1);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "setAccessible", "(Z)V", false);
        mv.visitVarInsn(ALOAD, 10);
        mv.visitInsn(ICONST_2);
        mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
        mv.visitInsn(DUP);
        mv.visitInsn(ICONST_0);
        mv.visitVarInsn(LLOAD, 2);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
        mv.visitInsn(AASTORE);
        mv.visitInsn(DUP);
        mv.visitInsn(ICONST_1);
        mv.visitVarInsn(LLOAD, 7);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
        mv.visitInsn(AASTORE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Constructor", "newInstance",
                "([Ljava/lang/Object;)Ljava/lang/Object;", false);
        mv.visitTypeInsn(CHECKCAST, "com/ibm/layout/Array1D");
        mv.visitVarInsn(ASTORE, 11);
        mv.visitVarInsn(ALOAD, 11);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, typeName, "location", "Lcom/ibm/layout/Location;");
        mv.visitMethodInsn(INVOKEINTERFACE, "com/ibm/layout/Array1D", "bindLocation",
                "(Lcom/ibm/layout/Location;)V", true);
        mv.visitVarInsn(ALOAD, 11);
        mv.visitLabel(l1);
        mv.visitInsn(ARETURN);
        mv.visitLabel(l2);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchMethodException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/NoSuchMethodException", "printStackTrace", "()V", false);
        Label l8 = new Label();
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/SecurityException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/SecurityException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l4);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/InstantiationException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/InstantiationException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l5);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalAccessException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalAccessException", "printStackTrace", "()V", false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l6);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/IllegalArgumentException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/IllegalArgumentException", "printStackTrace", "()V",
                false);
        mv.visitJumpInsn(GOTO, l8);
        mv.visitLabel(l7);
        mv.visitFrame(Opcodes.F_SAME1, 0, null, 1,
                new Object[] { "java/lang/reflect/InvocationTargetException" });
        mv.visitVarInsn(ASTORE, 4);
        mv.visitVarInsn(ALOAD, 4);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "printStackTrace",
                "()V", false);
        mv.visitLabel(l8);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(ACONST_NULL);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(6, 12);
        mv.visitEnd();
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java

License:Open Source License

/**
 * generate void main(String[])/*from  w  ww  .  ja  va  2  s  .c om*/
 * <p>
 * <code>
 * public static void main(String[] args) {
 *   ExampleProgram exampleProgram = new ExampleProgram();
 *  try {
 *       exampleProgram.inputStream = System.in;
 *       exampleProgram.outputStream = System.out;
 *       exampleProgram.program();
 *   } catch (Exception e) {
 *       e.printStackTrace();
 *    }
 *  }
 * </code>
 * </p>
 */
protected void generateMain(String classname, ClassWriter classWriter) throws Exception {
    try {
        /*
         * make method
         */
        final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
                "main", "([Ljava/lang/String;)V", null, null);
        methodVisitor.visitCode();
        final Label l0 = new Label();
        final Label l1 = new Label();
        final Label l2 = new Label();
        methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
        final Label l3 = new Label();
        methodVisitor.visitLabel(l3);
        /*
         * declare a local instance of the class in the void() main, store as variable 1.
         */
        methodVisitor.visitTypeInsn(Opcodes.NEW, classname);
        methodVisitor.visitInsn(Opcodes.DUP);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V");
        methodVisitor.visitVarInsn(Opcodes.ASTORE, 1);
        /*
         * assign the input stream
         */
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;");
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;");
        /*
         * assign the output stream
         */
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;");
        /*
         * load the class instance from variable 1 and call "program"
         */
        methodVisitor.visitLabel(l0);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V");
        methodVisitor.visitLabel(l1);
        final Label l4 = new Label();
        methodVisitor.visitJumpInsn(Opcodes.GOTO, l4);
        methodVisitor.visitLabel(l2);
        methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1,
                new Object[] { "java/lang/Exception" });
        methodVisitor.visitVarInsn(Opcodes.ASTORE, 2);
        final Label l5 = new Label();
        methodVisitor.visitLabel(l5);
        methodVisitor.visitLineNumber(21, l5);
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 2);
        methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V");
        /*
         * return
         */
        methodVisitor.visitLabel(l4);
        methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        methodVisitor.visitInsn(Opcodes.RETURN);
        /*
         * declare the parameters
         */
        final Label l6 = new Label();
        methodVisitor.visitLabel(l6);
        methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0);
        methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1);
        methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2);
        /*
         * done
         */
        methodVisitor.visitMaxs(2, 3);
        methodVisitor.visitEnd();
    } catch (final Exception e) {
        throw new Exception("Exception in generateMain", e);
    }
}

From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java

License:Apache License

public void addSupportMethod() {
    int access = Opcodes.ACC_PUBLIC;
    Method m = new Method("isSupport", "(I)Z");
    MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null);

    mv.visitCode();//from www .  j  a  v  a 2s .  com
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    //        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);

    int[] hashArray = new int[fixMtds.size()];
    Label[] labelArray = new Label[fixMtds.size()];
    Label l0 = new Label();
    Label l1 = new Label();
    for (int i = 0; i < fixMtds.size(); i++) {
        hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i));
        labelArray[i] = l0;
    }

    mv.visitLookupSwitchInsn(l1, hashArray, labelArray);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(1, 2);
    mv.visitEnd();

    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java

License:Open Source License

private static byte[] instantiateAnyConcreteTuple(String dename, List<String> parameters) {
    /*//from www . ja v  a  2 s.com
     * Single parameter, N, which is the arity of the tuple.
     * 
     * extends Ljava/util/AbstractList;
     * implements LAnyTuple[\N\];
     * int size() { return N; }
     * Object get(int n) {
     *    if (n >= N || n < 0) {
     *       throw new IndexOutOfBoundsException();
     *    } else {
     *      // binary search tree returning o1 ... oN
     *    }
     * }
     */

    ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    final String super_type = "java/lang/Object";

    final int n = Integer.parseInt(parameters.get(0));
    final String any_tuple_n = ANY_TUPLE + Naming.LEFT_OXFORD + n + Naming.RIGHT_OXFORD;
    String[] superInterfaces = { any_tuple_n };
    cw.visit(JVM_BYTECODE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, dename, null, super_type,
            superInterfaces);

    simpleInitMethod(cw, super_type);

    { // size method
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "size", "()I", null, null);
        mv.visitCode();
        mv.visitIntInsn(BIPUSH, n);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }

    { // get method  
        final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(I)Ljava/lang/Object;", null, null);
        mv.visitCode();
        mv.visitVarInsn(ILOAD, 1);
        mv.visitIntInsn(BIPUSH, n);
        Label l1 = new Label();
        mv.visitJumpInsn(IF_ICMPGE, l1);
        mv.visitVarInsn(ILOAD, 1);
        Label l2 = new Label();
        mv.visitJumpInsn(IFGE, l2);
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitTypeInsn(NEW, "java/lang/IndexOutOfBoundsException");
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IndexOutOfBoundsException", "<init>", "()V");
        mv.visitInsn(ATHROW);

        FnVoidVoid geti = new FnVoidVoid() {

            @Override
            public void apply() {
                mv.visitVarInsn(ILOAD, 1);
            }

        };

        FnVoid<Integer> leaf = new FnVoid<Integer>() {

            @Override
            public void apply(Integer x) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKEINTERFACE, any_tuple_n,
                        TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + x), UNTYPED_GETTER_SIG);
                mv.visitInsn(ARETURN);
            }

        };

        visitBinaryTree(mv, 0, n - 1, l2, geti, leaf);

        mv.visitMaxs(2, 2);
        mv.visitEnd();

    }

    cw.visitEnd();
    return cw.toByteArray();
}

From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java

License:Open Source License

/**
 * Generates a binary search tree for integers in the range [lo,hi]
 * (INCLUSIVE!).  Target, if not null, is to be attached to the generated code.
 * geti pushes the integer in question onto the top of the stack.
 * leaf handles the leaf case where lo=hi.
 * //from w  w  w  .ja  v a 2 s .  c  om
 * Cases are generated into ascending order, just because.
 * 
 * @param mv
 * @param lo
 * @param hi
 * @param target
 * @param geti
 * @param leaf
 */

static void visitBinaryTree(MethodVisitor mv, int lo, int hi, Label target, FnVoidVoid geti,
        FnVoid<Integer> leaf) {
    if (target != null)
        mv.visitLabel(target);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);

    if (lo == hi) {
        leaf.apply(lo);
    } else {
        /*
         * 0,1 -> 0,0; 1,1
         * 0,2 -> 0,1; 2,2 
         */
        int mid = (lo + hi) / 2;
        Label small = null;
        Label large = new Label();
        geti.apply();
        mv.visitIntInsn(BIPUSH, mid);
        mv.visitJumpInsn(IF_ICMPGT, large);
        visitBinaryTree(mv, lo, mid, small, geti, leaf);
        visitBinaryTree(mv, mid + 1, hi, large, geti, leaf);
    }
}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generatePropertyMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(property.writeAccessLevel + ACC_FINAL, property.propertyMethodName,
            "()" + property.propertyInterfaceSignature,
            property.propertyInterfaceSignatureGeneric != null
                    ? "()" + property.propertyInterfaceSignatureGeneric
                    : null,//ww w . j av  a2  s .  co m
            null);
    {
        AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";",
                true);
        av0.visit("writeable", Boolean.TRUE);
        av0.visit("name", property.propertyName);
        av0.visit("dataSignature", property.dataSignature);
        av0.visit("dataSignatureGeneric",
                property.dataSignatureGeneric != null ? property.dataSignatureGeneric : "");
        av0.visit("humanReadableName",
                property.humanReadablePropertyName != null ? property.humanReadablePropertyName : "");
        av0.visitEnd();
    }
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, property.propertyDataType);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(property.propertyName);
    mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>",
            "(Ljava/lang/Object;Ljava/lang/String;)V");
    mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitLabel(l1);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitTypeInsn(CHECKCAST, property.propertyInterfaceType);
    mv.visitInsn(ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0);
    mv.visitMaxs(5, 1);
    mv.visitEnd();
}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generateReadOnlyPropertyMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(property.readAccessLevel + ACC_FINAL, property.readOnlyPropertyMethodName,
            "()" + property.readOnlyPropertyInterfaceSignature,
            property.readOnlyPropertyInterfaceSignatureGeneric != null
                    ? "()" + property.readOnlyPropertyInterfaceSignatureGeneric
                    : null,/* ww w  .  j  av a 2 s  .com*/
            null);
    {
        AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";",
                true);
        av0.visit("writeable", Boolean.FALSE);
        av0.visit("name", property.propertyName);
        av0.visit("dataSignature", property.dataSignature);
        av0.visit("dataSignatureGeneric",
                property.dataSignatureGeneric != null ? property.dataSignatureGeneric : "");
        av0.visit("humanReadableName",
                property.humanReadablePropertyName != null ? property.humanReadablePropertyName : "");
        av0.visitEnd();
    }
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, property.propertyDataType);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(property.propertyName);
    mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>",
            "(Ljava/lang/Object;Ljava/lang/String;)V");
    mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitLabel(l1);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyDataType, "getReadOnlyProperty",
            "()" + property.readOnlyPropertyInterfaceSignature);
    mv.visitTypeInsn(CHECKCAST, property.readOnlyPropertyInterfaceType);
    mv.visitInsn(ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0);
    mv.visitMaxs(5, 1);
    mv.visitEnd();
}

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

License:Open Source License

public void addNextIndex() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PROTECTED, "nextIndex", "()I", null, null);
    mv.visitCode();/*  ww  w  . ja  v  a2 s.  c  o m*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "modCount", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "expectedModCount",
            "I");
    Label l0 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l0);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/ConcurrentModificationException");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ConcurrentModificationException", "<init>", "()V",
            false);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitLabel(l0);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/IdentityHashMap$IdentityHashMapIterator", "hasNext",
            "()Z", false);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, l1);
    mv.visitTypeInsn(Opcodes.NEW, "java/util/NoSuchElementException");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/NoSuchElementException", "<init>", "()V", false);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitLabel(l1);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "keys",
            "Ljava/util/List;");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.DUP);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitInsn(Opcodes.DUP_X1);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IADD);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "idx", "I");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true);
    mv.visitVarInsn(Opcodes.ASTORE, 1);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/lang/Object", Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;");
    mv.visitInsn(Opcodes.ARRAYLENGTH);
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l3);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator", "this$0",
            "Ljava/util/IdentityHashMap;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table", "[Ljava/lang/Object;");
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    Label l4 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ACMPNE, l4);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
            "lastReturnedIndex", "I");
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l4);
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitIincInsn(2, 2);
    mv.visitJumpInsn(Opcodes.GOTO, l2);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
            "lastReturnedIndex", "I");
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitMaxs(5, 3);
    mv.visitEnd();
}

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 w  w. jav  a2 s  .co  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:edu.illinois.nondex.instr.PriorityBlockingQueueShufflingAdder.java

License:Open Source License

public void addToString() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();/* w w  w .j  ava  2  s  .c o m*/
    Label l0 = new Label();
    Label l1 = new Label();
    Label l2 = new Label();
    mv.visitTryCatchBlock(l0, l1, l2, null);
    Label l3 = new Label();
    Label l4 = new Label();
    mv.visitTryCatchBlock(l3, l4, l2, null);
    Label l5 = new Label();
    mv.visitTryCatchBlock(l2, l5, l2, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "lock",
            "Ljava/util/concurrent/locks/ReentrantLock;");
    mv.visitVarInsn(Opcodes.ASTORE, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lock", "()V", false);
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "size", "I");
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitJumpInsn(Opcodes.IFNE, l3);
    mv.visitLdcInsn("[]");
    mv.visitVarInsn(Opcodes.ASTORE, 3);
    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l3);
    mv.visitFrame(Opcodes.F_APPEND, 2,
            new Object[] { "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER }, 0, null);
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder");
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
    mv.visitVarInsn(Opcodes.ASTORE, 3);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 91);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/concurrent/PriorityBlockingQueue", "queue",
            "[Ljava/lang/Object;");
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "[Ljava/lang/Object;", "clone", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
    mv.visitVarInsn(Opcodes.ASTORE, 4);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
    mv.visitVarInsn(Opcodes.ASTORE, 4);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitVarInsn(Opcodes.ISTORE, 5);
    Label l6 = new Label();
    mv.visitLabel(l6);
    mv.visitFrame(Opcodes.F_APPEND, 3,
            new Object[] { "java/lang/StringBuilder", "[Ljava/lang/Object;", Opcodes.INTEGER }, 0, null);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    Label l7 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPGE, l7);
    mv.visitVarInsn(Opcodes.ALOAD, 4);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitInsn(Opcodes.AALOAD);
    mv.visitVarInsn(Opcodes.ASTORE, 6);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitVarInsn(Opcodes.ALOAD, 6);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    Label l8 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ACMPNE, l8);
    mv.visitLdcInsn("(this Collection)");
    Label l9 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l9);
    mv.visitLabel(l8);
    mv.visitFrame(Opcodes.F_FULL, 7,
            new Object[] { "java/util/concurrent/PriorityBlockingQueue",
                    "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder",
                    "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" },
            1, new Object[] { "java/lang/StringBuilder" });
    mv.visitVarInsn(Opcodes.ALOAD, 6);
    mv.visitLabel(l9);
    mv.visitFrame(Opcodes.F_FULL, 7,
            new Object[] { "java/util/concurrent/PriorityBlockingQueue",
                    "java/util/concurrent/locks/ReentrantLock", Opcodes.INTEGER, "java/lang/StringBuilder",
                    "[Ljava/lang/Object;", Opcodes.INTEGER, "java/lang/Object" },
            2, new Object[] { "java/lang/StringBuilder", "java/lang/Object" });
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.ISUB);
    Label l10 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ICMPEQ, l10);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 44);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitIntInsn(Opcodes.BIPUSH, 32);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitInsn(Opcodes.POP);
    mv.visitLabel(l10);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitIincInsn(5, 1);
    mv.visitJumpInsn(Opcodes.GOTO, l6);
    mv.visitLabel(l7);
    mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 3);
    mv.visitIntInsn(Opcodes.BIPUSH, 93);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
            "(C)Ljava/lang/StringBuilder;", false);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;",
            false);
    mv.visitVarInsn(Opcodes.ASTORE, 5);
    mv.visitLabel(l4);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 5);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitLabel(l2);
    mv.visitFrame(Opcodes.F_FULL, 2, new Object[] { "java/util/concurrent/PriorityBlockingQueue",
            "java/util/concurrent/locks/ReentrantLock" }, 1, new Object[] { "java/lang/Throwable" });
    mv.visitVarInsn(Opcodes.ASTORE, 7);
    mv.visitLabel(l5);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V",
            false);
    mv.visitVarInsn(Opcodes.ALOAD, 7);
    mv.visitInsn(Opcodes.ATHROW);
    mv.visitMaxs(3, 8);
    mv.visitEnd();
}