Example usage for org.objectweb.asm Opcodes CHECKCAST

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

Introduction

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

Prototype

int CHECKCAST

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

Click Source Link

Usage

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

private TypeInstruction(final ReadMethod readMethod, final int lineNumber, final int opcode,
        final String typeDesc, final int index, int newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber, index);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = typeDesc;
    this.newObjectIdentifierSeqIndex = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

@Override
public String toString() {
    String instruction;/*w  ww . ja  v  a  2  s  .  c  om*/
    switch (getOpcode()) {
    case Opcodes.NEW:
        instruction = "NEW";
        break;
    case Opcodes.ANEWARRAY:
        instruction = "ANEWARRAY";
        break;
    case Opcodes.CHECKCAST:
        instruction = "CHECKCAST";
        break;
    case Opcodes.INSTANCEOF:
        instruction = "INSTANCEOF";
        break;
    default:
        instruction = "-ERROR-";
    }
    return new StringBuilder(instruction.length() + this.className.length() + 1).append(instruction).append(' ')
            .append(this.className).toString();
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction2.java

License:Open Source License

public TypeInstruction2(final ReadMethod readMethod, final int opcode, final int lineNumber,
        final String className, long newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = className;
    this.newObjectIdentifier = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction2.java

License:Open Source License

public TypeInstruction2(final ReadMethod readMethod, final int lineNumber, final int opcode,
        final String typeDesc, final int index, long newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber, index);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = typeDesc;
    this.newObjectIdentifier = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction2.java

License:Open Source License

@Override
public <InstanceType> InstanceType getNextInstance(TraceIterator infoProv, int stackDepth, long instanceNr,
        InstructionInstanceFactory<InstanceType> instanceFactory) throws TracerException {
    long newobjIndentifier = this.newObjectIdentifier;
    TypeInstrInstanceInfo info;// ww  w .  j  a v  a2 s.  com
    if (this.getOpcode() == Opcodes.CHECKCAST || this.getOpcode() == Opcodes.INSTANCEOF)
        info = TypeInstrInstanceInfo.NO_INFO;
    else
        info = new TypeInstrInstanceInfo(newobjIndentifier);
    return instanceFactory.createInstructionInstance(this,
            infoProv.getNextInstructionOccurenceNumber(getIndex()), stackDepth, instanceNr, info);
}

From source file:de.unisb.cs.st.javaslicer.instructionSimulation.Simulator.java

License:Open Source License

private DynamicInformation simulateTypeInsn(InstructionInstance inst, SimulationEnvironment simEnv) {
    assert inst.getInstruction().getType() == InstructionType.TYPE;
    TypeInstrInstanceInfo info = (TypeInstrInstanceInfo) inst.getAdditionalInfo();
    int stackDepth = inst.getStackDepth();
    switch (inst.getInstruction().getOpcode()) {
    case Opcodes.NEW:
        return new SimpleVariableUsage(DynamicInformation.EMPTY_VARIABLE_SET,
                Collections.<Variable>singleton(
                        simEnv.getOpStackEntry(stackDepth, simEnv.decAndGetOpStack(stackDepth))),
                Collections.<Long, Collection<? extends Variable>>singletonMap(info.getNewObjectIdentifier(),
                        getAllFields(((TypeInstruction) inst.getInstruction()).getJavaClassName(),
                                info.getNewObjectIdentifier())));
    case Opcodes.ANEWARRAY:
        int stackSize = simEnv.getOpStack(stackDepth) - 1;
        IntHolder h = this.maxArrayElem.remove(info.getNewObjectIdentifier());
        Collection<Variable> stackEntryColl = Collections
                .<Variable>singleton(simEnv.getOpStackEntry(stackDepth, stackSize));
        return new SimpleVariableUsage(stackEntryColl, stackEntryColl,
                Collections.<Long, Collection<? extends Variable>>singletonMap(info.getNewObjectIdentifier(),
                        new ArrayElementsList(h == null ? 0 : (h.get() + 1), info.getNewObjectIdentifier())));
    case Opcodes.CHECKCAST:
        return new SimpleVariableUsage(simEnv.getOpStackEntry(stackDepth, simEnv.getOpStack(stackDepth) - 1),
                DynamicInformation.EMPTY_VARIABLE_SET);
    case Opcodes.INSTANCEOF:
        return stackManipulation(simEnv, stackDepth, 1, 1);
    default:/*from  w ww. j a  va  2  s.c o m*/
        assert false;
        return null;
    }
}

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 a  va2 s .  c o  m
            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.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  w  w .  jav  a  2  s . c  o m
    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.MethodShufflingAdder.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ("getExceptionTypes".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override//from www  . ja v a  2 s .  c om
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
                    super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Class;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    if ("getGenericExceptionTypes".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
                    super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/reflect/Type;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    if ("getDeclaredAnnotations".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
                    super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;");
                }
                super.visitInsn(opcode);
            }
        };
    }
    if ("getParameterAnnotations".equals(name)) {
        return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
            @Override
            public void visitInsn(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    super.visitVarInsn(Opcodes.ASTORE, 1);
                    super.visitInsn(Opcodes.ICONST_0);
                    super.visitVarInsn(Opcodes.ISTORE, 2);
                    Label l0 = new Label();
                    super.visitLabel(l0);
                    super.visitFrame(Opcodes.F_APPEND, 2,
                            new Object[] { "[[Ljava/lang/annotation/Annotation;", Opcodes.INTEGER }, 0, null);
                    super.visitVarInsn(Opcodes.ILOAD, 2);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitInsn(Opcodes.ARRAYLENGTH);
                    Label l1 = new Label();
                    super.visitJumpInsn(Opcodes.IF_ICMPGE, l1);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitVarInsn(Opcodes.ILOAD, 2);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                    super.visitVarInsn(Opcodes.ILOAD, 2);
                    super.visitInsn(Opcodes.AALOAD);
                    super.visitMethodInsn(Opcodes.INVOKESTATIC,
                            "edu/illinois/nondex/shuffling/ControlNondeterminism", "shuffle",
                            "([Ljava/lang/Object;)[Ljava/lang/Object;", false);
                    super.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/annotation/Annotation;");
                    super.visitInsn(Opcodes.AASTORE);
                    super.visitIincInsn(2, 1);
                    super.visitJumpInsn(Opcodes.GOTO, l0);
                    super.visitLabel(l1);
                    super.visitFrame(Opcodes.F_CHOP, 1, null, 0, null);
                    super.visitVarInsn(Opcodes.ALOAD, 1);
                }
                super.visitInsn(opcode);
            }
        };
    }

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

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 ww. j  a  v  a  2 s  . co 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();
}