Example usage for org.objectweb.asm Opcodes RETURN

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

Introduction

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

Prototype

int RETURN

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

Click Source Link

Usage

From source file:dyco4j.instrumentation.LoggerInitializingClassVisitor.java

License:BSD License

public void visitEnd() {
    if (!this.isClinitVisited) {
        final org.objectweb.asm.MethodVisitor _mv = super.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V",
                null, null);// w ww  .java 2  s .c o m
        if (_mv != null) {
            LoggingHelper.emitInsnToLoadAndInitializeLogger(_mv);
            _mv.visitInsn(Opcodes.RETURN);
        }
    }
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("<init>".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override/*from  w w  w.j  av  a2s.  c  om*/
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    Label l0 = new Label();
                    mv.visitJumpInsn(Opcodes.IFNULL, l0);
                    mv.visitVarInsn(Opcodes.ALOAD, 0);
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitVarInsn(Opcodes.ALOAD, 1);
                    mv.visitInsn(Opcodes.ARRAYLENGTH);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "copyOf",
                            "([Ljava/lang/Object;I)[Ljava/lang/Object;", false);
                    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
                    mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/util/concurrent/ConcurrentHashMap$Node;");
                    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/concurrent/ConcurrentHashMap$Traverser",
                            "tab", "[Ljava/util/concurrent/ConcurrentHashMap$Node;");
                    mv.visitLabel(l0);
                    mv.visitFrame(Opcodes.F_FULL, 5,
                            new Object[] { "java/util/concurrent/ConcurrentHashMap$Traverser",
                                    "[Ljava/util/concurrent/ConcurrentHashMap$Node;", Opcodes.INTEGER,
                                    Opcodes.INTEGER, Opcodes.INTEGER },
                            0, new Object[] {});
                    mv.visitInsn(Opcodes.RETURN);
                }
                super.visitInsn(opcode);
            }
        };
    }

    return super.visitMethod(access, name, desc, signature, exceptions);
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("<init>".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override/*  w  ww. j  a v a  2s  .c o  m*/
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitTypeInsn(Opcodes.NEW, "java/util/HashMap$HashIterator$HashIteratorShuffler");
                    super.visitInsn(Opcodes.DUP);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL,
                            "java/util/HashMap$HashIterator$HashIteratorShuffler", "<init>",
                            "(Ljava/util/HashMap$HashIterator;Ljava/util/HashMap$HashIterator;)V", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/HashMap$HashIterator", "shuffler",
                            "Ljava/util/HashMap$HashIterator$HashIteratorShuffler;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    if ("hasNext".equals(name)) {
        return super.visitMethod(access, "original_hasNext", desc, signature, exceptions);
    }
    if (name.equals("next" + type)) {
        return super.visitMethod(access, "original_next" + type, desc, signature, exceptions);
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("hasNext".equals(name)) {
        return super.visitMethod(access, "originalHasNext", desc, signature, exceptions);
    }/*from   w  ww .  ja va 2s.c om*/
    if ("nextIndex".equals(name)) {
        return super.visitMethod(access, "originalNextIndex", desc, signature, exceptions);
    }
    if ("<init>".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "size", "I");
                    Label l0 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l0);
                    super.visitInsn(Opcodes.ICONST_0);
                    Label l1 = new Label();
                    super.visitJumpInsn(Opcodes.GOTO, l1);
                    super.visitLabel(l0);
                    super.visitFrame(Opcodes.F_FULL, 2,
                            new Object[] { "java/util/IdentityHashMap$IdentityHashMapIterator",
                                    "java/util/IdentityHashMap" },
                            1, new Object[] { "java/util/IdentityHashMap$IdentityHashMapIterator" });
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table",
                            "[Ljava/lang/Object;");
                    super.visitInsn(Opcodes.ARRAYLENGTH);
                    super.visitLabel(l1);
                    super.visitFrame(Opcodes.F_FULL, 2,
                            new Object[] { "java/util/IdentityHashMap$IdentityHashMapIterator",
                                    "java/util/IdentityHashMap" },
                            2, new Object[] { "java/util/IdentityHashMap$IdentityHashMapIterator",
                                    Opcodes.INTEGER });
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "index", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "modCount", "I");
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "expectedModCount", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ICONST_M1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "lastReturnedIndex", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table",
                            "[Ljava/lang/Object;");
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "traversalTable", "[Ljava/lang/Object;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
                    super.visitInsn(Opcodes.DUP);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "order", "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
                    super.visitInsn(Opcodes.DUP);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "keys", "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ICONST_0);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "idx", "I");
                    Label l2 = new Label();
                    super.visitLabel(l2);
                    super.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                            "java/util/IdentityHashMap$IdentityHashMapIterator", "originalHasNext", "()Z",
                            false);
                    Label l3 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l3);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "order", "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                            "java/util/IdentityHashMap$IdentityHashMapIterator", "originalNextIndex", "()I",
                            false);
                    super.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf",
                            "(I)Ljava/lang/Integer;", false);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add",
                            "(Ljava/lang/Object;)Z", true);
                    super.visitInsn(Opcodes.POP);
                    super.visitJumpInsn(Opcodes.GOTO, l2);
                    super.visitLabel(l3);
                    super.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "order", "Ljava/util/List;");
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "(Ljava/util/List;)Ljava/util/List;", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "order", "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "order", "Ljava/util/List;");
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "iterator",
                            "()Ljava/util/Iterator;", true);
                    super.visitVarInsn(Opcodes.ASTORE, 2);
                    Label l4 = new Label();
                    super.visitLabel(l4);
                    super.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/util/Iterator" }, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 2);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z",
                            true);
                    Label l5 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l5);
                    super.visitVarInsn(Opcodes.ALOAD, 2);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next",
                            "()Ljava/lang/Object;", true);
                    super.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Integer");
                    super.visitVarInsn(Opcodes.ASTORE, 3);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "keys", "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap$IdentityHashMapIterator",
                            "this$0", "Ljava/util/IdentityHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/IdentityHashMap", "table",
                            "[Ljava/lang/Object;");
                    super.visitVarInsn(Opcodes.ALOAD, 3);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
                    super.visitInsn(Opcodes.AALOAD);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add",
                            "(Ljava/lang/Object;)Z", true);
                    super.visitInsn(Opcodes.POP);
                    super.visitJumpInsn(Opcodes.GOTO, l4);
                    super.visitLabel(l5);
                    super.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
                }
                super.visitInsn(opcode);
            }
        };
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("hasNext".equals(name)) {
        return super.visitMethod(access, "originalHasNext", desc, signature, exceptions);
    }//  w  ww . j  av  a  2 s. co m
    if ("next".equals(name)) {
        return super.visitMethod(access, "originalNext", desc, signature, exceptions);
    }
    if ("<init>".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "this$0",
                            "Ljava/util/PriorityQueue;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ICONST_0);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "cursor", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ICONST_M1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "forgetMeNot",
                            "Ljava/util/ArrayDeque;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt",
                            "Ljava/lang/Object;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "this$0",
                            "Ljava/util/PriorityQueue;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue", "modCount", "I");
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "expectedModCount",
                            "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
                    super.visitInsn(Opcodes.DUP);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "elements",
                            "Ljava/util/List;");
                    Label l0 = new Label();
                    super.visitLabel(l0);
                    super.visitFrame(Opcodes.F_FULL, 2,
                            new Object[] { "java/util/PriorityQueue$Itr", "java/util/PriorityQueue" }, 0,
                            new Object[] {});
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/PriorityQueue$Itr",
                            "originalHasNext", "()Z", false);
                    Label l1 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l1);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements",
                            "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/PriorityQueue$Itr", "originalNext",
                            "()Ljava/lang/Object;", false);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add",
                            "(Ljava/lang/Object;)Z", true);
                    super.visitInsn(Opcodes.POP);
                    super.visitJumpInsn(Opcodes.GOTO, l0);
                    super.visitLabel(l1);
                    super.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements",
                            "Ljava/util/List;");
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "(Ljava/util/List;)Ljava/util/List;", false);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "elements",
                            "Ljava/util/List;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "elements",
                            "Ljava/util/List;");
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "iterator",
                            "()Ljava/util/Iterator;", true);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "iter",
                            "Ljava/util/Iterator;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ICONST_M1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt",
                            "Ljava/lang/Object;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

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

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("hasNext".equals(name)) {
        return super.visitMethod(access, "originalHasNext", desc, signature, exceptions);
    }/*  ww w  . java  2  s. c om*/
    if ("nextEntry".equals(name)) {
        return super.visitMethod(access, "originalNextEntry", desc, signature, exceptions);
    }
    if ("<init>".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "this$0",
                            "Ljava/util/WeakHashMap;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "entry",
                            "Ljava/util/WeakHashMap$Entry;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "lastReturned",
                            "Ljava/util/WeakHashMap$Entry;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap$HashIterator", "this$0",
                            "Ljava/util/WeakHashMap;");
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap", "modCount", "I");
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator",
                            "expectedModCount", "I");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "nextKey",
                            "Ljava/lang/Object;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "currentKey",
                            "Ljava/lang/Object;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "iter",
                            "Ljava/util/Iterator;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/WeakHashMap", "isEmpty", "()Z",
                            false);
                    Label l0 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l0);
                    super.visitInsn(Opcodes.ICONST_0);
                    Label l1 = new Label();
                    super.visitJumpInsn(Opcodes.GOTO, l1);
                    super.visitLabel(l0);
                    super.visitFrame(Opcodes.F_FULL, 2,
                            new Object[] { "java/util/WeakHashMap$HashIterator", "java/util/WeakHashMap" }, 1,
                            new Object[] { "java/util/WeakHashMap$HashIterator" });
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitFieldInsn(Opcodes.GETFIELD, "java/util/WeakHashMap", "table",
                            "[Ljava/util/WeakHashMap$Entry;");
                    super.visitInsn(Opcodes.ARRAYLENGTH);
                    super.visitLabel(l1);
                    super.visitFrame(Opcodes.F_FULL, 2,
                            new Object[] { "java/util/WeakHashMap$HashIterator", "java/util/WeakHashMap" }, 2,
                            new Object[] { "java/util/WeakHashMap$HashIterator", Opcodes.INTEGER });
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "index", "I");
                    super.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
                    super.visitInsn(Opcodes.DUP);
                    super.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
                    super.visitVarInsn(Opcodes.ASTORE, 2);
                    Label l2 = new Label();
                    super.visitLabel(l2);
                    super.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/util/List" }, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/WeakHashMap$HashIterator",
                            "originalHasNext", "()Z", false);
                    Label l3 = new Label();
                    super.visitJumpInsn(Opcodes.IFEQ, l3);
                    super.visitVarInsn(Opcodes.ALOAD, 2);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/WeakHashMap$HashIterator",
                            "originalNextEntry", "()Ljava/util/WeakHashMap$Entry;", false);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add",
                            "(Ljava/lang/Object;)Z", true);
                    super.visitInsn(Opcodes.POP);
                    super.visitJumpInsn(Opcodes.GOTO, l2);
                    super.visitLabel(l3);
                    super.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 2);
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "(Ljava/util/List;)Ljava/util/List;", false);
                    super.visitVarInsn(Opcodes.ASTORE, 2);
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitVarInsn(Opcodes.ALOAD, 2);
                    super.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "iterator",
                            "()Ljava/util/Iterator;", true);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "iter",
                            "Ljava/util/Iterator;");
                    super.visitVarInsn(Opcodes.ALOAD, 0);
                    super.visitInsn(Opcodes.ACONST_NULL);
                    super.visitFieldInsn(Opcodes.PUTFIELD, "java/util/WeakHashMap$HashIterator", "lastReturned",
                            "Ljava/util/WeakHashMap$Entry;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void findBlockBoundaries() {
    InsnList insns = methodNode.instructions;
    //We find the indices of any block-ending instruction and of any jump
    //target, sort, remove duplicates, then use pairs to define blocks. Note
    //these are end-exclusive indices, thus one after the block-enders, but
    //right on the jump targets (they're one-past-the-end of the preceding
    //block)./*from ww  w  .jav  a  2s .  c o m*/
    List<Integer> indices = new ArrayList<>();
    indices.add(0);
    for (int i = 0; i < insns.size(); ++i) {
        AbstractInsnNode insn = insns.get(i);
        int opcode = insn.getOpcode();
        //Terminator opcodes end blocks.
        if (insn instanceof JumpInsnNode || insn instanceof LookupSwitchInsnNode
                || insn instanceof TableSwitchInsnNode || opcode == Opcodes.ATHROW || opcode == Opcodes.IRETURN
                || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN || opcode == Opcodes.DRETURN
                || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN) {
            indices.add(i + 1);
        }
        //Jump targets of this instruction end blocks.
        if (insn instanceof JumpInsnNode)
            indices.add(insns.indexOf(((JumpInsnNode) insn).label));
        else if (insn instanceof LookupSwitchInsnNode) {
            indices.add(insns.indexOf(((LookupSwitchInsnNode) insn).dflt));
            for (Object label : ((LookupSwitchInsnNode) insn).labels)
                indices.add(insns.indexOf((LabelNode) label));
        } else if (insn instanceof TableSwitchInsnNode) {
            indices.add(insns.indexOf(((TableSwitchInsnNode) insn).dflt));
            for (Object label : ((TableSwitchInsnNode) insn).labels)
                indices.add(insns.indexOf((LabelNode) label));
        }

        //While we're scanning the instructions, make the UninitializedValue
        //values for 'new' opcodes.
        if (opcode == Opcodes.NEW) {
            Klass k = getKlassByInternalName(((TypeInsnNode) insn).desc);
            ReferenceType t = typeFactory.getReferenceType(k);
            newValues.put(insn, new UninitializedValue(t, "new" + (counter++)));
        }
    }

    //Remove duplicates and sort via TreeSet.
    indices = new ArrayList<>(new TreeSet<>(indices));
    for (int i = 1; i < indices.size(); ++i)
        blocks.add(new BBInfo(indices.get(i - 1), indices.get(i), i - 1));
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void interpret(InsnNode insn, FrameState frame, BBInfo block) {
    ReturnType returnType = block.block.getParent().getType().getReturnType();
    switch (insn.getOpcode()) {
    case Opcodes.NOP:
        break;// w w  w . j av  a2  s .c o  m
    //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)">
    case Opcodes.POP:
        assert frame.stack.peek().getType().getCategory() == 1;
        frame.stack.pop();
        break;
    case Opcodes.POP2:
        final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } };
        conditionallyPermute(frame, pop2Permutations);
        break;
    case Opcodes.DUP:
        final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } };
        conditionallyPermute(frame, dupPermutations);
        break;
    case Opcodes.DUP_X1:
        final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x1Permutations);
        break;
    case Opcodes.DUP_X2:
        final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup_x2Permutations);
        break;
    case Opcodes.DUP2:
        final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } };
        conditionallyPermute(frame, dup2Permutations);
        break;
    case Opcodes.DUP2_X1:
        final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x1Permutations);
        break;
    case Opcodes.DUP2_X2:
        final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } },
                { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } },
                { { 2, 2 }, { 1, 2, 1 } } };
        conditionallyPermute(frame, dup2_x2Permutations);
        break;
    case Opcodes.SWAP:
        final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } };
        conditionallyPermute(frame, swapPermutations);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)">
    case Opcodes.ACONST_NULL:
        frame.stack.push(module.constants().getNullConstant());
        break;
    case Opcodes.ICONST_M1:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        break;
    case Opcodes.ICONST_0:
        frame.stack.push(module.constants().getSmallestIntConstant(0));
        break;
    case Opcodes.ICONST_1:
        frame.stack.push(module.constants().getSmallestIntConstant(1));
        break;
    case Opcodes.ICONST_2:
        frame.stack.push(module.constants().getSmallestIntConstant(2));
        break;
    case Opcodes.ICONST_3:
        frame.stack.push(module.constants().getSmallestIntConstant(3));
        break;
    case Opcodes.ICONST_4:
        frame.stack.push(module.constants().getSmallestIntConstant(4));
        break;
    case Opcodes.ICONST_5:
        frame.stack.push(module.constants().getSmallestIntConstant(5));
        break;
    case Opcodes.LCONST_0:
        frame.stack.push(module.constants().getConstant(0L));
        break;
    case Opcodes.LCONST_1:
        frame.stack.push(module.constants().getConstant(1L));
        break;
    case Opcodes.FCONST_0:
        frame.stack.push(module.constants().getConstant(0f));
        break;
    case Opcodes.FCONST_1:
        frame.stack.push(module.constants().getConstant(1f));
        break;
    case Opcodes.FCONST_2:
        frame.stack.push(module.constants().getConstant(2f));
        break;
    case Opcodes.DCONST_0:
        frame.stack.push(module.constants().getConstant(0d));
        break;
    case Opcodes.DCONST_1:
        frame.stack.push(module.constants().getConstant(1d));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Return opcodes">
    case Opcodes.IRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(int.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.LRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(long.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.FRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(float.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.DRETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(double.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.ARETURN:
        assert returnType.isSubtypeOf(typeFactory.getType(Object.class));
        assert frame.stack.peek().getType().isSubtypeOf(returnType);
        block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop()));
        break;
    case Opcodes.RETURN:
        assert returnType instanceof VoidType || method.isConstructor();
        block.block.instructions().add(new ReturnInst(typeFactory.getVoidType()));
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)">
    //Unary minus is rendered as a multiplication by -1.  (The obvious
    //other choice, subtraction from 0, is not equivalent for floats and
    //doubles due to negative zero.)
    case Opcodes.INEG:
        frame.stack.push(module.constants().getSmallestIntConstant(-1));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.LNEG:
        frame.stack.push(module.constants().getConstant(-1L));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.FNEG:
        frame.stack.push(module.constants().getConstant(-1f));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.DNEG:
        frame.stack.push(module.constants().getConstant(-1d));
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Binary math opcodes">
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        binary(BinaryInst.Operation.ADD, frame, block);
        break;
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        binary(BinaryInst.Operation.SUB, frame, block);
        break;
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        binary(BinaryInst.Operation.MUL, frame, block);
        break;
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        binary(BinaryInst.Operation.DIV, frame, block);
        break;
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        binary(BinaryInst.Operation.REM, frame, block);
        break;
    case Opcodes.ISHL:
    case Opcodes.LSHL:
        binary(BinaryInst.Operation.SHL, frame, block);
        break;
    case Opcodes.ISHR:
    case Opcodes.LSHR:
        binary(BinaryInst.Operation.SHR, frame, block);
        break;
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        binary(BinaryInst.Operation.USHR, frame, block);
        break;
    case Opcodes.IAND:
    case Opcodes.LAND:
        binary(BinaryInst.Operation.AND, frame, block);
        break;
    case Opcodes.IOR:
    case Opcodes.LOR:
        binary(BinaryInst.Operation.OR, frame, block);
        break;
    case Opcodes.IXOR:
    case Opcodes.LXOR:
        binary(BinaryInst.Operation.XOR, frame, block);
        break;
    case Opcodes.LCMP:
    case Opcodes.FCMPL:
    case Opcodes.DCMPL:
        binary(BinaryInst.Operation.CMP, frame, block);
        break;
    case Opcodes.FCMPG:
    case Opcodes.DCMPG:
        binary(BinaryInst.Operation.CMPG, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Primitive casts">
    case Opcodes.I2L:
        cast(int.class, long.class, frame, block);
        break;
    case Opcodes.I2F:
        cast(int.class, float.class, frame, block);
        break;
    case Opcodes.I2D:
        cast(int.class, double.class, frame, block);
        break;
    case Opcodes.L2I:
        cast(long.class, int.class, frame, block);
        break;
    case Opcodes.L2F:
        cast(long.class, float.class, frame, block);
        break;
    case Opcodes.L2D:
        cast(long.class, double.class, frame, block);
        break;
    case Opcodes.F2I:
        cast(float.class, int.class, frame, block);
        break;
    case Opcodes.F2L:
        cast(float.class, long.class, frame, block);
        break;
    case Opcodes.F2D:
        cast(float.class, double.class, frame, block);
        break;
    case Opcodes.D2I:
        cast(double.class, int.class, frame, block);
        break;
    case Opcodes.D2L:
        cast(double.class, long.class, frame, block);
        break;
    case Opcodes.D2F:
        cast(double.class, float.class, frame, block);
        break;
    case Opcodes.I2B:
        cast(int.class, byte.class, frame, block);
        break;
    case Opcodes.I2C:
        cast(int.class, char.class, frame, block);
        break;
    case Opcodes.I2S:
        cast(int.class, short.class, frame, block);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array store opcodes">
    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
        Value data = frame.stack.pop();
        Value index = frame.stack.pop();
        Value array = frame.stack.pop();
        ArrayStoreInst asi = new ArrayStoreInst(array, index, data);
        block.block.instructions().add(asi);
        break;
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Array load opcodes">
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.AALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        Value index2 = frame.stack.pop();
        Value array2 = frame.stack.pop();
        ArrayLoadInst ali = new ArrayLoadInst(array2, index2);
        block.block.instructions().add(ali);
        frame.stack.push(ali);
        break;
    //</editor-fold>
    case Opcodes.ARRAYLENGTH:
        ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop());
        block.block.instructions().add(lengthInst);
        frame.stack.push(lengthInst);
        break;
    case Opcodes.ATHROW:
        block.block.instructions().add(new ThrowInst(frame.stack.pop()));
        break;
    default:
        throw new UnsupportedOperationException("" + insn.getOpcode());
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(ReturnInst i, InsnList insns) {
    ReturnType rt = i.getReturnType();//w w w .j a v  a2 s  .  c om
    if (rt instanceof VoidType)
        insns.add(new InsnNode(Opcodes.RETURN));
    else {
        load(i.getOperand(0), insns);
        if (rt instanceof ReferenceType)
            insns.add(new InsnNode(Opcodes.ARETURN));
        else if (rt.isSubtypeOf(intType))
            insns.add(new InsnNode(Opcodes.IRETURN));
        else if (rt.equals(longType))
            insns.add(new InsnNode(Opcodes.LRETURN));
        else if (rt.equals(floatType))
            insns.add(new InsnNode(Opcodes.FRETURN));
        else if (rt.equals(doubleType))
            insns.add(new InsnNode(Opcodes.DRETURN));
        else
            throw new AssertionError(i);
    }
}

From source file:edu.ubc.mirrors.holograms.HologramClassGenerator.java

License:Open Source License

@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {//  www  .  j  a  v  a 2  s .  c  o  m
    this.name = name;
    this.isInterface = (Opcodes.ACC_INTERFACE & access) != 0;
    this.superName = getHologramSuperclassName(isInterface, name, superName);
    interfaces = getHologramInterfaces(name, isInterface, interfaces);

    // Force everything to be public, since HologramClassLoader has to reflectively
    // construct holograms. Again, not a problem because the VM will see the original flags on the ClassMirror instead.
    // Also remove enum flags.
    int hologramAccess = forcePublic(access);
    // Also remove abstract flag. Shouldn't be necessary, but the VM (OpenJDK at least)
    // creates objects that claim to be an instance of VirtualMachineError, which is abstract.
    if (name.equals("hologram/java/lang/VirtualMachineError")) {
        hologramAccess = ~Opcodes.ACC_ABSTRACT & access;
    }

    // We need at least 1.5 to use class literal constants
    // TODO-RS: Work out a better way to interpret 45.X numbers correctly
    if (version == Opcodes.V1_1 || version < Opcodes.V1_5) {
        version = 49;
    }

    super.visit(version, hologramAccess, name, signature, this.superName, interfaces);

    if (this.name.equals(hologramThrowableType.getInternalName())) {
        // Generate aliases for the original superclass' fillInStackTrace and getStackTrace methods,
        // so we can call them in stubs without hitting hologram code.
        MethodVisitor v = super.visitMethod(Opcodes.ACC_PUBLIC, "superFillInStackTrace",
                Type.getMethodDescriptor(Type.VOID_TYPE), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "fillInStackTrace",
                Type.getMethodDescriptor(Type.getType(Throwable.class)));
        v.visitInsn(Opcodes.RETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();

        v = super.visitMethod(Opcodes.ACC_PUBLIC, "superGetStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)), null, null);
        v.visitCode();
        v.visitVarInsn(Opcodes.ALOAD, 0);
        v.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Throwable.class), "getStackTrace",
                Type.getMethodDescriptor(Type.getType(StackTraceElement[].class)));
        v.visitInsn(Opcodes.ARETURN);
        v.visitMaxs(1, 1);
        v.visitEnd();
    }
}