Example usage for org.objectweb.asm Opcodes ATHROW

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

Introduction

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

Prototype

int ATHROW

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

Click Source Link

Usage

From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java

License:Open Source License

public void visitInsn(int inst) {
    if (!methodName.equals("<clinit>") && instrumentReturns) {
        switch (inst) {
        case Opcodes.IRETURN:
            callLogIReturn();//from   w  w  w .j  a  v a2s  .c om
            callEnd();
            break;
        case Opcodes.ARETURN:
            callLogAReturn();
            callEnd();
            break;
        case Opcodes.ATHROW:
            callEnd();
            break;
        case Opcodes.DRETURN:
            callLogDReturn();
            callEnd();
            break;
        case Opcodes.FRETURN:
            callLogFReturn();
            callEnd();
            break;
        case Opcodes.LRETURN:
            callLogLReturn();
            callEnd();
            break;
        case Opcodes.RETURN:
            callEnd();
            break;
        default:
            break;
        }
    }
    super.visitInsn(inst);
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodAdapter.java

License:Open Source License

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    if (name.equals("exita") && owner.equals("java/lang/System")) {
        logger.info("Replacing System.exit ");

        Label mutationStartLabel = new Label();
        mutationStartLabel.info = new MutationMarker(true);
        mv.visitLabel(mutationStartLabel);

        mv.visitInsn(Opcodes.POP);/*from  ww  w . ja  v  a2 s .  co m*/
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException");
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn("Replaced System Exit");
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                "(Ljava/lang/String;)V");
        mv.visitInsn(Opcodes.ATHROW);

        Label mutationEndLabel = new Label();
        mutationEndLabel.info = new MutationMarker(false);
        mv.visitLabel(mutationEndLabel);

    } else {
        super.visitMethodInsn(opcode, owner, name, desc);
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodNode.java

License:Open Source License

@SuppressWarnings("unchecked")
// Call to pre-1.5 Code
@Override//from   w  w  w  . ja  va2 s.  c  o  m
public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    InsnList insns = mn.instructions;
    Iterator i = insns.iterator();
    AbstractInsnNode prev = null;
    InsnList newInstrucionList = new InsnList();
    while (i.hasNext()) {
        boolean addInstruction = true;
        AbstractInsnNode i1 = (AbstractInsnNode) i.next();
        if (i1 instanceof MethodInsnNode) {
            MethodInsnNode methotInsnNode = (MethodInsnNode) i1;
            if (methotInsnNode.name.equals("exit") && methotInsnNode.owner.equals("java/lang/System")) {
                logger.info("Replacing System.exit ");
                newInstrucionList.remove(prev);
                // insns.remove(i1);
                InsnList il = new InsnList();
                Label mutationStartLabel = new Label();
                mutationStartLabel.info = new MutationMarker(true);

                il.add(new LabelNode(mutationStartLabel));
                il.add(new TypeInsnNode(Opcodes.NEW, "java/lang/RuntimeException"));
                il.add(new InsnNode(Opcodes.DUP));
                il.add(new LdcInsnNode("Replaced System.exit()"));
                il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                        "(Ljava/lang/String;)V"));
                il.add(new InsnNode(Opcodes.ATHROW));

                Label mutationEndLabel = new Label();
                mutationEndLabel.info = new MutationMarker(false);
                il.add(new LabelNode(mutationEndLabel));
                newInstrucionList.add(il);
                addInstruction = false;
            }
        }
        if (addInstruction) {
            try {
                insns.remove(i1);
                newInstrucionList.add(i1);
            } catch (Exception e) {
                logger.error(e);
            }

        }
        prev = i1;
    }
    mn.instructions = newInstrucionList;
    mn.accept(next);
}

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

License:Open Source License

@Override
public String toString() {
    switch (getOpcode()) {
    // the not interesting ones:
    case Opcodes.NOP:
        return "NOP";
    // constants:
    case Opcodes.ACONST_NULL:
        return "ACONST_NULL";
    case Opcodes.ICONST_M1:
        return "ICONST_M1";
    case Opcodes.ICONST_0:
        return "ICONST_0";
    case Opcodes.ICONST_1:
        return "ICONST_1";
    case Opcodes.ICONST_2:
        return "ICONST_2";
    case Opcodes.ICONST_3:
        return "ICONST_3";
    case Opcodes.ICONST_4:
        return "ICONST_4";
    case Opcodes.ICONST_5:
        return "ICONST_5";
    case Opcodes.LCONST_0:
        return "LCONST_0";
    case Opcodes.LCONST_1:
        return "LCONST_1";
    case Opcodes.FCONST_0:
        return "FCONST_0";
    case Opcodes.FCONST_1:
        return "FCONST_1";
    case Opcodes.FCONST_2:
        return "FCONST_2";
    case Opcodes.DCONST_0:
        return "DCONST_0";
    case Opcodes.DCONST_1:
        return "DCONST_1";

    // array load:
    case Opcodes.IALOAD:
        return "IALOAD";
    case Opcodes.LALOAD:
        return "LALOAD";
    case Opcodes.FALOAD:
        return "FALOAD";
    case Opcodes.DALOAD:
        return "DALOAD";
    case Opcodes.AALOAD:
        return "AALOAD";
    case Opcodes.BALOAD:
        return "BALOAD";
    case Opcodes.CALOAD:
        return "CALOAD";
    case Opcodes.SALOAD:
        return "SALOAD";

    // array store:
    case Opcodes.IASTORE:
        return "IASTORE";
    case Opcodes.LASTORE:
        return "LASTORE";
    case Opcodes.FASTORE:
        return "FASTORE";
    case Opcodes.DASTORE:
        return "DASTORE";
    case Opcodes.AASTORE:
        return "AASTORE";
    case Opcodes.BASTORE:
        return "BASTORE";
    case Opcodes.CASTORE:
        return "CASTORE";
    case Opcodes.SASTORE:
        return "SASTORE";

    // stack manipulation:
    case Opcodes.POP:
        return "POP";
    case Opcodes.POP2:
        return "POP2";
    case Opcodes.DUP:
        return "DUP";
    case Opcodes.DUP_X1:
        return "DUP_X1";
    case Opcodes.DUP_X2:
        return "DUP_X2";
    case Opcodes.DUP2:
        return "DUP2";
    case Opcodes.DUP2_X1:
        return "DUP2_X1";
    case Opcodes.DUP2_X2:
        return "DUP2_X2";
    case Opcodes.SWAP:
        return "SWAP";

    // arithmetic:
    case Opcodes.IADD:
        return "IADD";
    case Opcodes.LADD:
        return "LADD";
    case Opcodes.FADD:
        return "FADD";
    case Opcodes.DADD:
        return "DADD";
    case Opcodes.ISUB:
        return "ISUB";
    case Opcodes.LSUB:
        return "LSUB";
    case Opcodes.FSUB:
        return "FSUB";
    case Opcodes.DSUB:
        return "DSUB";
    case Opcodes.IMUL:
        return "IMUL";
    case Opcodes.LMUL:
        return "LMUL";
    case Opcodes.FMUL:
        return "FMUL";
    case Opcodes.DMUL:
        return "DMUL";
    case Opcodes.IDIV:
        return "IDIV";
    case Opcodes.LDIV:
        return "LDIV";
    case Opcodes.FDIV:
        return "FDIV";
    case Opcodes.DDIV:
        return "DDIV";
    case Opcodes.IREM:
        return "IREM";
    case Opcodes.LREM:
        return "LREM";
    case Opcodes.FREM:
        return "FREM";
    case Opcodes.DREM:
        return "DREM";
    case Opcodes.INEG:
        return "INEG";
    case Opcodes.LNEG:
        return "LNEG";
    case Opcodes.FNEG:
        return "FNEG";
    case Opcodes.DNEG:
        return "DNEG";
    case Opcodes.ISHL:
        return "ISHL";
    case Opcodes.LSHL:
        return "LSHL";
    case Opcodes.ISHR:
        return "ISHR";
    case Opcodes.LSHR:
        return "LSHR";
    case Opcodes.IUSHR:
        return "IUSHR";
    case Opcodes.LUSHR:
        return "LUSHR";
    case Opcodes.IAND:
        return "IAND";
    case Opcodes.LAND:
        return "LAND";
    case Opcodes.IOR:
        return "IOR";
    case Opcodes.LOR:
        return "LOR";
    case Opcodes.IXOR:
        return "IXOR";
    case Opcodes.LXOR:
        return "LXOR";

    // type conversions:
    case Opcodes.I2L:
        return "I2L";
    case Opcodes.I2F:
        return "I2F";
    case Opcodes.I2D:
        return "I2D";
    case Opcodes.L2I:
        return "L2I";
    case Opcodes.L2F:
        return "L2F";
    case Opcodes.L2D:
        return "L2D";
    case Opcodes.F2I:
        return "F2I";
    case Opcodes.F2L:
        return "F2L";
    case Opcodes.F2D:
        return "F2D";
    case Opcodes.D2I:
        return "D2I";
    case Opcodes.D2L:
        return "D2L";
    case Opcodes.D2F:
        return "D2F";
    case Opcodes.I2B:
        return "I2B";
    case Opcodes.I2C:
        return "I2C";
    case Opcodes.I2S:
        return "I2S";

    // comparison:
    case Opcodes.LCMP:
        return "LCMP";
    case Opcodes.FCMPL:
        return "FCMPL";
    case Opcodes.FCMPG:
        return "FCMPG";
    case Opcodes.DCMPL:
        return "DCMPL";
    case Opcodes.DCMPG:
        return "DCMPG";

    // control-flow statements:
    case Opcodes.IRETURN:
        return "IRETURN";
    case Opcodes.LRETURN:
        return "LRETURN";
    case Opcodes.FRETURN:
        return "FRETURN";
    case Opcodes.DRETURN:
        return "DRETURN";
    case Opcodes.ARETURN:
        return "ARETURN";
    case Opcodes.RETURN:
        return "RETURN";

    // special things
    case Opcodes.ARRAYLENGTH:
        return "ARRAYLENGTH";
    case Opcodes.ATHROW:
        return "ATHROW";
    case Opcodes.MONITORENTER:
        return "MONITORENTER";
    case Opcodes.MONITOREXIT:
        return "MONITOREXIT";

    default:/*ww  w.j av a2 s .  co m*/
        assert false;
        return "--ERROR--";
    }
}

From source file:de.unisb.cs.st.javaslicer.dependenceAnalysis.DependencesExtractor.java

License:Open Source License

/**
 * Go backwards through the execution trace of the given threadId and extract
 * all dependences. {@link DependencesVisitor}s should have been added before
 * by calling {@link #registerVisitor(DependencesVisitor, VisitorCapability...)}.
 *
 * @param threadId identifies the thread whose trace should be analyzed
 * @param multithreaded use an extra thread to traverse the trace
 * @throws InterruptedException if the thread was interrupted during traversal
 * @throws IllegalArgumentException if the trace contains no thread with this id
 *//*  ww  w.  ja v a 2 s . com*/
public void processBackwardTrace(ThreadId threadId, boolean multithreaded) throws InterruptedException {

    final BackwardTraceIterator<InstanceType> backwardInsnItr = this.trace.getBackwardIterator(threadId, null,
            this.instanceFactory);

    if (backwardInsnItr == null)
        throw new IllegalArgumentException("No such thread");

    // store the current set of visitors of each capability in an array for better
    // performance and faster empty-check (null reference if empty)
    final DependencesVisitor<? super InstanceType>[] dataDependenceVisitorsReadAfterWrite0 = this.dataDependenceVisitorsReadAfterWrite
            .isEmpty() ? null
                    : this.dataDependenceVisitorsReadAfterWrite.toArray(
                            newDependencesVisitorArray(this.dataDependenceVisitorsReadAfterWrite.size()));
    final DependencesVisitor<? super InstanceType>[] dataDependenceVisitorsWriteAfterRead0 = this.dataDependenceVisitorsWriteAfterRead
            .isEmpty() ? null
                    : this.dataDependenceVisitorsWriteAfterRead.toArray(
                            newDependencesVisitorArray(this.dataDependenceVisitorsWriteAfterRead.size()));
    final DependencesVisitor<? super InstanceType>[] controlDependenceVisitors0 = this.controlDependenceVisitors
            .isEmpty() ? null
                    : this.controlDependenceVisitors
                            .toArray(newDependencesVisitorArray(this.controlDependenceVisitors.size()));
    final DependencesVisitor<? super InstanceType>[] instructionVisitors0 = this.instructionVisitors.isEmpty()
            ? null
            : this.instructionVisitors.toArray(newDependencesVisitorArray(this.instructionVisitors.size()));
    final DependencesVisitor<? super InstanceType>[] pendingDataDependenceVisitorsReadAfterWrite0 = this.pendingDataDependenceVisitorsReadAfterWrite
            .isEmpty() ? null
                    : this.pendingDataDependenceVisitorsReadAfterWrite.toArray(newDependencesVisitorArray(
                            this.pendingDataDependenceVisitorsReadAfterWrite.size()));
    final DependencesVisitor<? super InstanceType>[] pendingDataDependenceVisitorsWriteAfterRead0 = this.pendingDataDependenceVisitorsWriteAfterRead
            .isEmpty() ? null
                    : this.pendingDataDependenceVisitorsWriteAfterRead.toArray(newDependencesVisitorArray(
                            this.pendingDataDependenceVisitorsWriteAfterRead.size()));
    final DependencesVisitor<? super InstanceType>[] pendingControlDependenceVisitors0 = this.pendingControlDependenceVisitors
            .isEmpty() ? null
                    : this.pendingControlDependenceVisitors
                            .toArray(newDependencesVisitorArray(this.pendingControlDependenceVisitors.size()));
    final DependencesVisitor<? super InstanceType>[] methodEntryLeaveVisitors0 = this.methodEntryLeaveVisitors
            .isEmpty() ? null
                    : this.methodEntryLeaveVisitors
                            .toArray(newDependencesVisitorArray(this.methodEntryLeaveVisitors.size()));
    final DependencesVisitor<? super InstanceType>[] objectCreationVisitors0 = this.objectCreationVisitors
            .isEmpty() ? null
                    : this.objectCreationVisitors
                            .toArray(newDependencesVisitorArray(this.objectCreationVisitors.size()));

    @SuppressWarnings("unchecked")
    DependencesVisitor<? super InstanceType>[] allVisitors = union(dataDependenceVisitorsReadAfterWrite0,
            dataDependenceVisitorsWriteAfterRead0, controlDependenceVisitors0, instructionVisitors0,
            pendingDataDependenceVisitorsReadAfterWrite0, pendingDataDependenceVisitorsWriteAfterRead0,
            pendingControlDependenceVisitors0, methodEntryLeaveVisitors0, objectCreationVisitors0);

    IntegerMap<Set<Instruction>> controlDependences = new IntegerMap<Set<Instruction>>();

    Iterator<InstanceType> instanceIterator;
    ProgressInformationProvider progressInfoProv;
    Thread iteratorThread = null;
    final AtomicReference<Throwable> iteratorException = new AtomicReference<Throwable>(null);
    if (multithreaded) {
        final AtomicLong percentPerInstance = this.progressMonitors.isEmpty() ? null
                : new AtomicLong(Double.doubleToLongBits(0)); // this AtomicLong holds a double value!!

        final BlockwiseSynchronizedBuffer<InstanceType> buffer = new BlockwiseSynchronizedBuffer<InstanceType>(
                1 << 16, 1 << 20);
        final InstanceType firstInstance = backwardInsnItr.hasNext() ? backwardInsnItr.next() : null;
        iteratorThread = new Thread("Trace iterator") {
            @Override
            public void run() {
                try {
                    int num = 0;
                    while (backwardInsnItr.hasNext()) {
                        buffer.put(backwardInsnItr.next());
                        if ((++num & ((1 << 16) - 1)) == 0 && percentPerInstance != null) {
                            double percentPerInstance0 = backwardInsnItr.getPercentageDone() / num;
                            percentPerInstance.set(Double.doubleToLongBits(percentPerInstance0));
                        }
                    }
                } catch (Throwable t) {
                    iteratorException.compareAndSet(null, t);
                } finally {
                    try {
                        buffer.put(firstInstance); // to signal that this is the end of the trace
                        buffer.flush();
                    } catch (InterruptedException e) {
                        iteratorException.compareAndSet(null, e);
                    }
                }
            }
        };
        iteratorThread.start();
        final AtomicLong numInstancesSeen = percentPerInstance == null ? null : new AtomicLong(0);
        instanceIterator = new Iterator<InstanceType>() {

            private InstanceType next = firstInstance;

            @Override
            public boolean hasNext() {
                if (this.next == null) {
                    while (true) {
                        try {
                            this.next = buffer.take();
                            if (this.next == firstInstance) {
                                this.next = null;
                            }
                            break;
                        } catch (InterruptedException e) {
                            // this.next stays null
                            assert this.next == null;
                            Thread.currentThread().interrupt();
                        }
                    }
                }
                return this.next != null;
            }

            @Override
            public InstanceType next() {
                if (!hasNext())
                    throw new NoSuchElementException();
                InstanceType ret = this.next;
                this.next = null;
                if (numInstancesSeen != null)
                    numInstancesSeen.incrementAndGet();
                return ret;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
        progressInfoProv = percentPerInstance == null ? null : new ProgressInformationProvider() {
            @Override
            public double getPercentageDone() {
                return Double.longBitsToDouble(percentPerInstance.get()) * numInstancesSeen.get();
            }
        };
    } else {
        instanceIterator = backwardInsnItr;
        progressInfoProv = backwardInsnItr;
    }

    // the lastWriter is needed for WAR data dependences
    Map<Variable, InstanceType> lastWriter = new HashMap<Variable, InstanceType>();
    // lastReaders are needed for RAW data dependences
    Map<Variable, List<InstanceType>> lastReaders = new HashMap<Variable, List<InstanceType>>();

    /*
    HashSet<Long> createdObjects = new HashSet<Long>();
    HashSet<Long> seenObjects = new HashSet<Long>();
    */

    InstanceType instance = null;
    Instruction instruction = null;

    for (ProgressMonitor mon : this.progressMonitors)
        mon.start(progressInfoProv);

    try {

        long nextFrameNr = 0;
        int stackDepth = 0;

        List<ReadMethod> initialStackMethods = backwardInsnItr.getInitialStackMethods();

        int allocStack = initialStackMethods.size() + 1;
        allocStack = Integer.highestOneBit(allocStack) * 2;

        @SuppressWarnings("unchecked")
        InstanceType[] atCatchBlockStart = (InstanceType[]) (new InstructionInstance[allocStack]);
        boolean[] throwsException = new boolean[allocStack];
        boolean[] interruptedControlFlow = new boolean[allocStack];
        /**
         * <code>true</code> iff this frame was aborted abnormally (NOT by a RETURN
         * instruction)
         */
        boolean[] abnormalTermination = new boolean[allocStack];
        /**
         * is set to true if the methods entry label has been passed
         */
        boolean[] finished = new boolean[allocStack];
        int[] opStack = new int[allocStack];
        int[] minOpStack = new int[allocStack];
        long[] frames = new long[allocStack];
        Instruction[] lastInstruction = new Instruction[allocStack];
        @SuppressWarnings("unchecked")
        HashSet<InstanceType>[] interestingInstances = (HashSet<InstanceType>[]) new HashSet<?>[allocStack];
        StackEntry[][] cachedStackEntries = new StackEntry[allocStack][];
        LocalVariable[][] cachedLocalVariables = new LocalVariable[allocStack][];
        ReadMethod[] method = new ReadMethod[allocStack];

        for (ReadMethod method0 : initialStackMethods) {
            ++stackDepth;
            method[stackDepth] = method0;
            interruptedControlFlow[stackDepth] = true;
            frames[stackDepth] = nextFrameNr++;
            if (methodEntryLeaveVisitors0 != null)
                for (DependencesVisitor<? super InstanceType> vis : methodEntryLeaveVisitors0)
                    vis.visitMethodLeave(method0, stackDepth);
        }

        for (int i = 1; i < allocStack; ++i) {
            interestingInstances[i] = new HashSet<InstanceType>();
            cachedStackEntries[i] = new StackEntry[8];
            cachedLocalVariables[i] = new LocalVariable[8];
        }

        SimulationEnvironment simEnv = new SimulationEnvironment(frames, opStack, minOpStack,
                cachedStackEntries, cachedLocalVariables, throwsException, lastInstruction, method,
                interruptedControlFlow);

        while (instanceIterator.hasNext()) {

            instance = instanceIterator.next();
            instruction = instance.getInstruction();

            if ((instance.getInstanceNr() & ((1 << 16) - 1)) == 0 && Thread.interrupted())
                throw new InterruptedException();

            int newStackDepth = instance.getStackDepth();
            assert newStackDepth > 0;

            simEnv.removedMethod = null;
            boolean reenter = false;
            if (newStackDepth != stackDepth
                    || (reenter = finished[stackDepth] || method[stackDepth] != instruction.getMethod())) {
                if (newStackDepth >= stackDepth) {
                    // in all steps, the stackDepth can change by at most 1 (except for the very first instruction)
                    assert newStackDepth == stackDepth + 1 || stackDepth == 0 || reenter;
                    if (newStackDepth >= atCatchBlockStart.length) {
                        int oldLen = atCatchBlockStart.length;
                        int newLen = oldLen == 0 ? 8 : 2 * oldLen;
                        atCatchBlockStart = Arrays.copyOf(atCatchBlockStart, newLen);
                        throwsException = Arrays.copyOf(throwsException, newLen);
                        interruptedControlFlow = Arrays.copyOf(interruptedControlFlow, newLen);
                        abnormalTermination = Arrays.copyOf(abnormalTermination, newLen);
                        finished = Arrays.copyOf(finished, newLen);
                        opStack = Arrays.copyOf(opStack, newLen);
                        minOpStack = Arrays.copyOf(minOpStack, newLen);
                        frames = Arrays.copyOf(frames, newLen);
                        interestingInstances = Arrays.copyOf(interestingInstances, newLen);
                        lastInstruction = Arrays.copyOf(lastInstruction, newLen);
                        cachedStackEntries = Arrays.copyOf(cachedStackEntries, newLen);
                        cachedLocalVariables = Arrays.copyOf(cachedLocalVariables, newLen);
                        method = Arrays.copyOf(method, newLen);
                        for (int i = oldLen; i < newLen; ++i) {
                            interestingInstances[i] = new HashSet<InstanceType>();
                            cachedStackEntries[i] = new StackEntry[8];
                            cachedLocalVariables[i] = new LocalVariable[8];
                        }
                        simEnv = new SimulationEnvironment(frames, opStack, minOpStack, cachedStackEntries,
                                cachedLocalVariables, throwsException, lastInstruction, method,
                                interruptedControlFlow);
                    }
                    frames[newStackDepth] = nextFrameNr++;
                    ReadMethod oldMethod = method[newStackDepth];
                    method[newStackDepth] = instruction.getMethod();
                    if (methodEntryLeaveVisitors0 != null) {
                        for (DependencesVisitor<? super InstanceType> vis : methodEntryLeaveVisitors0) {
                            if (reenter)
                                vis.visitMethodEntry(oldMethod, newStackDepth);
                            vis.visitMethodLeave(method[newStackDepth], newStackDepth);
                        }
                    }

                    if (reenter) {
                        cleanUpExecutionFrame(simEnv, stackDepth, lastReaders, lastWriter,
                                pendingDataDependenceVisitorsWriteAfterRead0,
                                pendingDataDependenceVisitorsReadAfterWrite0,
                                dataDependenceVisitorsWriteAfterRead0, dataDependenceVisitorsReadAfterWrite0);
                    }

                    atCatchBlockStart[newStackDepth] = null;
                    if (instruction == method[newStackDepth].getAbnormalTerminationLabel()) {
                        throwsException[newStackDepth] = interruptedControlFlow[newStackDepth] = abnormalTermination[newStackDepth] = true;
                        interruptedControlFlow[stackDepth] = true;
                    } else {
                        throwsException[newStackDepth] = interruptedControlFlow[newStackDepth] = abnormalTermination[newStackDepth] = false;
                    }
                    finished[newStackDepth] = false;
                    opStack[newStackDepth] = 0;
                    minOpStack[newStackDepth] = 0;
                    interestingInstances[newStackDepth].clear();
                    if (cachedLocalVariables[newStackDepth].length > 128)
                        cachedLocalVariables[newStackDepth] = new LocalVariable[8];
                    else
                        Arrays.fill(cachedLocalVariables[newStackDepth], null);
                    if (cachedStackEntries[newStackDepth].length > 128)
                        cachedStackEntries[newStackDepth] = new StackEntry[8];
                    else
                        Arrays.fill(cachedStackEntries[newStackDepth], null);

                } else {
                    assert newStackDepth == stackDepth - 1;
                    if (methodEntryLeaveVisitors0 != null) {
                        for (DependencesVisitor<? super InstanceType> vis : methodEntryLeaveVisitors0) {
                            vis.visitMethodEntry(method[stackDepth], stackDepth);
                        }
                    }
                    simEnv.removedMethod = method[stackDepth];
                }
            }
            stackDepth = newStackDepth;

            if (simEnv.removedMethod == null && (this.untracedMethodsVisitors != null)
                    && (instruction.getType() == InstructionType.METHODINVOCATION)) {
                for (DependencesVisitor<? super InstanceType> vis : this.untracedMethodsVisitors)
                    vis.visitUntracedMethodCall(instance);
            }

            if (instruction == instruction.getMethod().getMethodEntryLabel())
                finished[stackDepth] = true;
            lastInstruction[stackDepth] = instruction;

            if (atCatchBlockStart[stackDepth] != null)
                throwsException[stackDepth] = true;

            DynamicInformation dynInfo = this.simulator.simulateInstruction(instance, simEnv);

            if (instructionVisitors0 != null)
                for (DependencesVisitor<? super InstanceType> vis : instructionVisitors0)
                    vis.visitInstructionExecution(instance);

            // the computation of control dependences only has to be performed
            // if there are any controlDependenceVisitors
            if (controlDependenceVisitors0 != null) {
                if (simEnv.removedMethod != null && !interestingInstances[stackDepth + 1].isEmpty()) {
                    // ok, we have a control dependence since the method was called by (or for) this instruction
                    // checking if this is the instr. that directly called the method is impossible
                    for (InstanceType depend : interestingInstances[stackDepth + 1]) {
                        for (DependencesVisitor<? super InstanceType> vis : controlDependenceVisitors0) {
                            vis.visitControlDependence(depend, instance);
                        }
                    }
                    interestingInstances[stackDepth].add(instance);
                }

                Set<Instruction> instrControlDependences = controlDependences.get(instruction.getIndex());
                if (instrControlDependences == null) {
                    computeControlDependences(instruction.getMethod(), controlDependences);
                    instrControlDependences = controlDependences.get(instruction.getIndex());
                    assert instrControlDependences != null;
                }
                boolean isExceptionsThrowingInstruction = throwsException[stackDepth]
                        && (instruction.getType() != InstructionType.LABEL
                                || !((LabelMarker) instruction).isAdditionalLabel())
                        && (instruction.getOpcode() != Opcodes.GOTO);
                // assert: every ATHROW must be an exception throwing instance
                assert (instruction.getOpcode() != Opcodes.ATHROW || isExceptionsThrowingInstruction);
                // get all interesting instructions, that are dependent on the current one
                Set<InstanceType> dependantInterestingInstances = getInstanceIntersection(
                        instrControlDependences, interestingInstances[stackDepth]);
                if (isExceptionsThrowingInstruction) {
                    throwsException[stackDepth] = false;
                    // in this case, we have an additional control dependence from the catching to
                    // the throwing instruction, and a data dependence on the thrown instruction
                    for (int i = stackDepth; i > 0; --i) {
                        if (atCatchBlockStart[i] != null) {
                            if (interestingInstances[i].contains(atCatchBlockStart[i])) {
                                if (dependantInterestingInstances.isEmpty())
                                    dependantInterestingInstances = Collections.singleton(atCatchBlockStart[i]);
                                else
                                    dependantInterestingInstances.add(atCatchBlockStart[i]);
                            }
                            atCatchBlockStart[i] = null;

                            // data dependence:
                            // (the stack height has already been decremented when entering the catch block)
                            Variable definedException = simEnv.getOpStackEntry(i, opStack[i]);
                            dynInfo = AdditionalDataDependence.annotate(dynInfo, definedException,
                                    dynInfo.getUsedVariables());

                            break;
                        }
                    }
                }
                if (!dependantInterestingInstances.isEmpty()) {
                    for (InstanceType depend : dependantInterestingInstances) {
                        for (DependencesVisitor<? super InstanceType> vis : controlDependenceVisitors0) {
                            vis.visitControlDependence(depend, instance);
                        }
                    }
                    interestingInstances[stackDepth].removeAll(dependantInterestingInstances);
                }
                interestingInstances[stackDepth].add(instance);
            }
            // TODO check this:
            if (pendingControlDependenceVisitors0 != null) {
                interestingInstances[stackDepth].add(instance);
                for (DependencesVisitor<? super InstanceType> vis : pendingControlDependenceVisitors0)
                    vis.visitPendingControlDependence(instance);
            }

            Collection<? extends Variable> definedVariables = dynInfo.getDefinedVariables();
            if (!definedVariables.isEmpty()) {
                /*
                for (Variable definedVariable: dynInfo.getDefinedVariables()) {
                if (definedVariable instanceof ObjectField) {
                    seenObjects.add(((ObjectField)definedVariable).getObjectId());
                    assert !createdObjects.contains(((ObjectField)definedVariable).getObjectId());
                }
                if (definedVariable instanceof ArrayElement) {
                    seenObjects.add(((ArrayElement)definedVariable).getArrayId());
                    assert !createdObjects.contains(((ArrayElement)definedVariable).getArrayId());
                }
                }
                */
                if (dataDependenceVisitorsReadAfterWrite0 != null
                        || dataDependenceVisitorsWriteAfterRead0 != null
                        || pendingDataDependenceVisitorsWriteAfterRead0 != null) {
                    for (Variable definedVariable : definedVariables) {
                        if (!(definedVariable instanceof StackEntry)) {
                            // we ignore WAR dependences over the stack!
                            if (pendingDataDependenceVisitorsWriteAfterRead0 != null) {
                                // for each defined variable, we have a pending WAR dependence
                                // if the lastWriter is not null, we first discard old pending dependences
                                InstanceType varLastWriter = lastWriter.put(definedVariable, instance);
                                for (DependencesVisitor<? super InstanceType> vis : pendingDataDependenceVisitorsWriteAfterRead0) {
                                    if (varLastWriter != null)
                                        vis.discardPendingDataDependence(varLastWriter, definedVariable,
                                                DataDependenceType.WRITE_AFTER_READ);
                                    vis.visitPendingDataDependence(instance, definedVariable,
                                            DataDependenceType.WRITE_AFTER_READ);
                                }
                                // otherwise, if there are WAR visitors, we only update the lastWriter
                            } else if (dataDependenceVisitorsWriteAfterRead0 != null) {
                                lastWriter.put(definedVariable, instance);
                            }
                        }
                        // if we have RAW visitors, we need to analyse the lastReaders
                        if (dataDependenceVisitorsReadAfterWrite0 != null
                                || pendingDataDependenceVisitorsReadAfterWrite0 != null) {
                            List<InstanceType> readers = lastReaders.remove(definedVariable);
                            if (readers != null) {
                                Collection<? extends Variable> usedVariables = dataDependenceVisitorsReadAfterWrite0 != null
                                        ? dynInfo.getUsedVariables(definedVariable)
                                        : null;
                                for (InstanceType reader : readers) {
                                    if (dataDependenceVisitorsReadAfterWrite0 != null) {
                                        for (DependencesVisitor<? super InstanceType> vis : dataDependenceVisitorsReadAfterWrite0)
                                            vis.visitDataDependence(reader, instance, usedVariables,
                                                    definedVariable, DataDependenceType.READ_AFTER_WRITE);
                                    }
                                    if (pendingDataDependenceVisitorsReadAfterWrite0 != null)
                                        for (DependencesVisitor<? super InstanceType> vis : pendingDataDependenceVisitorsReadAfterWrite0)
                                            vis.discardPendingDataDependence(reader, definedVariable,
                                                    DataDependenceType.READ_AFTER_WRITE);
                                }
                            }
                        }
                    }
                }
            }

            Collection<? extends Variable> usedVariables = dynInfo.getUsedVariables();
            if (!usedVariables.isEmpty()) {
                /*
                for (Variable usedVariable: dynInfo.getUsedVariables()) {
                if (usedVariable instanceof ObjectField) {
                    seenObjects.add(((ObjectField)usedVariable).getObjectId());
                    assert !createdObjects.contains(((ObjectField)usedVariable).getObjectId());
                }
                if (usedVariable instanceof ArrayElement) {
                    seenObjects.add(((ArrayElement)usedVariable).getArrayId());
                    assert !createdObjects.contains(((ArrayElement)usedVariable).getArrayId());
                }
                }
                */

                if (dataDependenceVisitorsWriteAfterRead0 != null
                        || dataDependenceVisitorsReadAfterWrite0 != null
                        || pendingDataDependenceVisitorsReadAfterWrite0 != null) {
                    for (Variable usedVariable : usedVariables) {
                        // if we have WAR visitors, we inform them about a new dependence
                        if (dataDependenceVisitorsWriteAfterRead0 != null
                                && !(usedVariable instanceof StackEntry)) {
                            InstanceType lastWriterInst = lastWriter.get(usedVariable);

                            // avoid self-loops in the DDG (e.g. for IINC, which reads and writes to the same variable)
                            if (lastWriterInst != null && lastWriterInst != instance) {
                                for (DependencesVisitor<? super InstanceType> vis : dataDependenceVisitorsWriteAfterRead0)
                                    vis.visitDataDependence(lastWriterInst, instance, null, usedVariable,
                                            DataDependenceType.WRITE_AFTER_READ);
                            }
                        }

                        // for RAW visitors, update the lastReaders
                        if (dataDependenceVisitorsReadAfterWrite0 != null
                                || pendingDataDependenceVisitorsReadAfterWrite0 != null) {
                            List<InstanceType> readers = lastReaders.get(usedVariable);
                            if (readers == null) {
                                readers = new ArrayList<InstanceType>(4);
                                lastReaders.put(usedVariable, readers);
                            }
                            readers.add(instance);
                            // for each used variable, we have a pending RAW dependence
                            if (pendingDataDependenceVisitorsReadAfterWrite0 != null) {
                                for (DependencesVisitor<? super InstanceType> vis : pendingDataDependenceVisitorsReadAfterWrite0)
                                    vis.visitPendingDataDependence(instance, usedVariable,
                                            DataDependenceType.READ_AFTER_WRITE);
                            }
                        }
                    }
                }
            }

            for (Entry<Long, Collection<? extends Variable>> e : dynInfo.getCreatedObjects().entrySet()) {
                /*
                boolean added = createdObjects.add(e.getKey());
                assert added;
                */

                for (Variable var : e.getValue()) {
                    assert var instanceof ObjectField || var instanceof ArrayElement;
                    // clean up lastWriter if we have any WAR visitors
                    if (pendingDataDependenceVisitorsWriteAfterRead0 != null) {
                        InstanceType inst;
                        if ((inst = lastWriter.remove(var)) != null)
                            for (DependencesVisitor<? super InstanceType> vis : pendingDataDependenceVisitorsWriteAfterRead0)
                                vis.discardPendingDataDependence(inst, var,
                                        DataDependenceType.WRITE_AFTER_READ);
                    } else if (dataDependenceVisitorsWriteAfterRead0 != null)
                        lastWriter.remove(var);
                    // clean up lastReaders if we have any RAW visitors
                    if (dataDependenceVisitorsReadAfterWrite0 != null
                            || pendingDataDependenceVisitorsReadAfterWrite0 != null) {
                        List<InstanceType> instList;
                        if ((instList = lastReaders.remove(var)) != null) {
                            if (dataDependenceVisitorsReadAfterWrite0 != null)
                                for (DependencesVisitor<? super InstanceType> vis : dataDependenceVisitorsReadAfterWrite0)
                                    for (InstanceType instrInst : instList)
                                        vis.visitDataDependence(instrInst, instance,
                                                Collections.<Variable>emptySet(), var,
                                                DataDependenceType.READ_AFTER_WRITE);
                            if (pendingDataDependenceVisitorsReadAfterWrite0 != null)
                                for (DependencesVisitor<? super InstanceType> vis : pendingDataDependenceVisitorsReadAfterWrite0)
                                    for (InstanceType instrInst : instList)
                                        vis.discardPendingDataDependence(instrInst, var,
                                                DataDependenceType.READ_AFTER_WRITE);
                        }
                    }
                }
                if (objectCreationVisitors0 != null)
                    for (DependencesVisitor<? super InstanceType> vis : objectCreationVisitors0)
                        vis.visitObjectCreation(e.getKey(), instance);
            }

            if (dynInfo.isCatchBlock()) {
                atCatchBlockStart[stackDepth] = instance;
                interruptedControlFlow[stackDepth] = true;
            } else if (atCatchBlockStart[stackDepth] != null) {
                atCatchBlockStart[stackDepth] = null;
            }

            if (simEnv.removedMethod != null) {
                cleanUpExecutionFrame(simEnv, stackDepth + 1, lastReaders, lastWriter,
                        pendingDataDependenceVisitorsWriteAfterRead0,
                        pendingDataDependenceVisitorsReadAfterWrite0, dataDependenceVisitorsWriteAfterRead0,
                        dataDependenceVisitorsReadAfterWrite0);
            }

            /*
            if (instance.getInstanceNr() % 1000000 == 0) {
            for (Variable var: lastReaders.keySet()) {
                if (var instanceof ObjectField) {
                    assert seenObjects.contains(((ObjectField)var).getObjectId());
                    assert !createdObjects.contains(((ObjectField)var).getObjectId());
                }
                if (var instanceof ArrayElement) {
                    assert seenObjects.contains(((ArrayElement)var).getArrayId());
                    assert !createdObjects.contains(((ArrayElement)var).getArrayId());
                }
                if (var instanceof StackEntry)
                    assert frames.contains(((StackEntry)var).getFrame());
                if (var instanceof LocalVariable) {
                    assert frames.contains(((LocalVariable)var).getFrame());
                }
            }
            for (Variable var: lastWriter.keySet()) {
                if (var instanceof ObjectField) {
                    assert seenObjects.contains(((ObjectField)var).getObjectId());
                    assert !createdObjects.contains(((ObjectField)var).getObjectId());
                }
                if (var instanceof ArrayElement) {
                    assert seenObjects.contains(((ArrayElement)var).getArrayId());
                    assert !createdObjects.contains(((ArrayElement)var).getArrayId());
                }
                // we do not store the last writer of a stack entry
                assert !(var instanceof StackEntry);
                if (var instanceof LocalVariable) {
                    assert frames.contains(((LocalVariable)var).getFrame());
                }
            }
            }
            */
        }
        Throwable t = iteratorException.get();
        if (t != null) {
            if (t instanceof RuntimeException)
                throw (RuntimeException) t;
            if (t instanceof Error)
                throw (Error) t;
            if (t instanceof InterruptedException)
                throw (InterruptedException) t;
            throw new TracerException("Iterator should not throw anything but RuntimeExceptions", t);
        }

        if (Thread.interrupted())
            throw new InterruptedException();

        cleanUpMaps(lastWriter, lastReaders, pendingDataDependenceVisitorsWriteAfterRead0,
                pendingDataDependenceVisitorsReadAfterWrite0);

        for (DependencesVisitor<? super InstanceType> vis : allVisitors)
            vis.visitEnd(instance == null ? 0 : instance.getInstanceNr());

        if (Thread.interrupted())
            throw new InterruptedException();
    } catch (InterruptedException e) {
        for (DependencesVisitor<? super InstanceType> vis : allVisitors)
            vis.interrupted();
        throw e;
    } finally {
        if (iteratorThread != null)
            iteratorThread.interrupt();
        for (ProgressMonitor mon : this.progressMonitors)
            mon.end();
    }
}

From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java

License:BSD License

@Override
public void visitInsn(final int opcode) {
    super.visitInsn(opcode);
    switch (opcode) {
    case Opcodes.IRETURN: // 1 before n/a after
    case Opcodes.FRETURN: // 1 before n/a after
    case Opcodes.ARETURN: // 1 before n/a after
    case Opcodes.ATHROW: // 1 before n/a after
        this.stackFrame.pop();
        break;//from w  w  w.  j a  va 2s .c  om
    case Opcodes.LRETURN: // 2 before n/a after
    case Opcodes.DRETURN: // 2 before n/a after
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.NOP:
    case Opcodes.LALOAD: // remove 2 add 2
    case Opcodes.DALOAD: // remove 2 add 2
    case Opcodes.LNEG:
    case Opcodes.DNEG:
    case Opcodes.FNEG:
    case Opcodes.INEG:
    case Opcodes.L2D:
    case Opcodes.D2L:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.I2F:
    case Opcodes.ARRAYLENGTH:
        break;
    case Opcodes.ACONST_NULL:
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.F2L: // 1 before 2 after
    case Opcodes.F2D:
    case Opcodes.I2L:
    case Opcodes.I2D:
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        this.stackFrame.push(OTHER);
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.IALOAD: // remove 2 add 1
    case Opcodes.FALOAD: // remove 2 add 1
    case Opcodes.AALOAD: // remove 2 add 1
    case Opcodes.BALOAD: // remove 2 add 1
    case Opcodes.CALOAD: // remove 2 add 1
    case Opcodes.SALOAD: // remove 2 add 1
    case Opcodes.POP:
    case Opcodes.IADD:
    case Opcodes.FADD:
    case Opcodes.ISUB:
    case Opcodes.LSHL: // 3 before 2 after
    case Opcodes.LSHR: // 3 before 2 after
    case Opcodes.LUSHR: // 3 before 2 after
    case Opcodes.L2I: // 2 before 1 after
    case Opcodes.L2F: // 2 before 1 after
    case Opcodes.D2I: // 2 before 1 after
    case Opcodes.D2F: // 2 before 1 after
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FCMPL: // 2 before 1 after
    case Opcodes.FCMPG: // 2 before 1 after
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
    case Opcodes.IAND:
    case Opcodes.IOR:
    case Opcodes.IXOR:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
        this.stackFrame.pop();
        break;
    case Opcodes.POP2:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.DADD:
    case Opcodes.DMUL:
    case Opcodes.DSUB:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.IASTORE:
    case Opcodes.FASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.LCMP: // 4 before 1 after
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.DUP:
        this.stackFrame.push(this.stackFrame.peek());
        break;
    case Opcodes.DUP_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.SWAP: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.remove(_s);
        break;
    }
    }
}

From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java

License:BSD License

@Override
public final void visitMaxs(final int maxStack, final int maxLocals) {
    endOutermostExceptionHandler();//from  w  w w  . j a  v a  2 s.  com
    for (final Map.Entry<Label, Label> _e : beginLabel2endLabel.entrySet()) {
        final Label _handlerLabel = new Label();
        super.visitLabel(_handlerLabel);
        super.visitTryCatchBlock(_e.getKey(), _e.getValue(), _handlerLabel, "java/lang/Throwable");
        LoggingHelper.emitLogException(this.mv);
        LoggingHelper.emitLogMethodExit(this.mv, this.methodId, LoggingHelper.ExitKind.EXCEPTIONAL);
        super.visitInsn(Opcodes.ATHROW);
    }
    super.visitMaxs(maxStack, maxLocals);
}

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();//from  w  ww. j a  v a 2s  .  com
    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.PriorityBlockingQueueShufflingAdder.java

License:Open Source License

public void addToString() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();//from www .j av a2  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();
}

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

License:Open Source License

public void addNext() {
    MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC, "next", "()Ljava/lang/Object;", "()TE;", null);
    mv.visitCode();/*from w w  w .j  a v  a  2s. c o m*/
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "expectedModCount", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "this$0", "Ljava/util/PriorityQueue;");
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue", "modCount", "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.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "iter", "Ljava/util/Iterator;");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, "java/util/PriorityQueue$Itr", "lastRet", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "java/util/PriorityQueue$Itr", "lastRetElt", "Ljava/lang/Object;");
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(2, 1);
    mv.visitEnd();
}