Example usage for org.objectweb.asm Opcodes LRETURN

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

Introduction

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

Prototype

int LRETURN

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

Click Source Link

Usage

From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.Inlining.java

License:Open Source License

public static List<Insn> convertInsns(MethodInsn mi, List<Insn> insns, int[] args, int _index, Label end) {
    List<Insn> result = new ArrayList<Insn>();
    HashMap labels = new HashMap();
    int index = _index;
    for (Insn i : insns) {
        if (i.isExpanded()) {
            MethodInsn expanded = (MethodInsn) i;
            // This use of end should be OK because all returns should have been removed when inlined before.
            // What could go wrong?
            result.addAll(convertInsns(expanded, expanded.inlineExpansionInsns, args, _index, end));
        } else if (i instanceof SingleInsn) {
            SingleInsn si = (SingleInsn) i;
            switch (si.opcode) {
            case Opcodes.IRETURN:
            case Opcodes.LRETURN:
            case Opcodes.FRETURN:
            case Opcodes.DRETURN:
            case Opcodes.ARETURN:
            case Opcodes.RETURN:
                result.add(new JumpInsn("RETURN->GOTO", Opcodes.GOTO, end, newIndex(mi, index++)));
                break;
            default:
                result.add(i.copy(newIndex(mi, index++)));
            }// w  w w  .  j  a v a  2  s.com
        } else if (i instanceof VarInsn) {
            VarInsn vi = (VarInsn) i;
            switch (vi.opcode) {
            case Opcodes.ILOAD:
            case Opcodes.LLOAD:
            case Opcodes.FLOAD:
            case Opcodes.DLOAD:
            case Opcodes.ALOAD:
            case Opcodes.ISTORE:
            case Opcodes.LSTORE:
            case Opcodes.FSTORE:
            case Opcodes.DSTORE:
            case Opcodes.ASTORE:
                VarInsn newVarInsn = new VarInsn(vi.name, vi.opcode, args[vi.var], newIndex(mi, index++));
                result.add(newVarInsn);
                break;
            default:
                result.add(i.copy(newIndex(mi, index++)));
            }
        } else if (i instanceof VisitMaxs) {
        } else if (i instanceof VisitEnd) {
        } else if (i instanceof VisitCode) {
        } else if (i instanceof VisitFrame) {
        } else if (i instanceof LabelInsn) {
            LabelInsn li = (LabelInsn) i;
            if (labels.containsKey(li.label))
                result.add(new LabelInsn(li.name, (Label) labels.get(li.label), newIndex(mi, index++)));
            else {
                Label l = new Label();
                labels.put(li.label, l);
                result.add(new LabelInsn(li.name, l, newIndex(mi, index++)));
            }
        } else if (i instanceof JumpInsn) {
            JumpInsn ji = (JumpInsn) i;
            if (labels.containsKey(ji.label))
                result.add(
                        new JumpInsn(ji.name, ji.opcode, (Label) labels.get(ji.label), newIndex(mi, index++)));
            else {
                Label l = new Label();
                labels.put(ji.label, l);
                result.add(new JumpInsn(ji.name, ji.opcode, l, newIndex(mi, index++)));
            }
        } else if (i instanceof VisitLineNumberInsn) {
            VisitLineNumberInsn vlni = (VisitLineNumberInsn) i;
            if (labels.containsKey(vlni.start))
                result.add(new VisitLineNumberInsn(vlni.name, vlni.line, (Label) labels.get(vlni.start),
                        newIndex(mi, index++)));
            else {
                Label l = new Label();
                labels.put(vlni.start, l);
                result.add(new VisitLineNumberInsn(vlni.name, vlni.line, l, newIndex(mi, index++)));
            }
        } else if (i instanceof LocalVariableInsn) {
            LocalVariableInsn lvi = (LocalVariableInsn) i;
            if (labels.containsKey(lvi.start) && labels.containsKey(lvi.end)) {
                result.add(new LocalVariableInsn(lvi.name, lvi._name, lvi.desc, lvi.sig,
                        (Label) labels.get(lvi.start), (Label) labels.get(lvi.end), args[lvi._index],
                        newIndex(mi, index++)));
            } else
                throw new RuntimeException("NYI");
        } else if (i instanceof TryCatchBlock) {
            TryCatchBlock tcb = (TryCatchBlock) i;
            if (labels.containsKey(tcb.start) && labels.containsKey(tcb.end)
                    && labels.containsKey(tcb.handler)) {
                result.add(
                        new TryCatchBlock(tcb.name, (Label) labels.get(tcb.start), (Label) labels.get(tcb.end),
                                (Label) labels.get(tcb.handler), tcb.type, newIndex(mi, index++)));
            } else if (!labels.containsKey(tcb.start) && !labels.containsKey(tcb.end)
                    && !labels.containsKey(tcb.handler)) {
                Label s = new Label();
                Label e = new Label();
                Label h = new Label();
                labels.put(tcb.start, s);
                labels.put(tcb.end, e);
                labels.put(tcb.handler, h);
                result.add(new TryCatchBlock(tcb.name, s, e, h, tcb.type, newIndex(mi, index++)));
            } else
                throw new RuntimeException("NYI");
            // Need to add TableSwitch, LookupSwitch
        } else {
            result.add(i.copy(newIndex(mi, index++)));
        }
    }
    return result;
}

From source file:com.sun.tdk.jcov.instrument.StaticInvokeMethodAdapter.java

License:Open Source License

@Override
public void visitInsn(int opcode) {

    switch (opcode) {
    case Opcodes.IRETURN:
    case Opcodes.FRETURN:
    case Opcodes.ARETURN:
    case Opcodes.LRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if (params.isInnerInvacationsOff()
                && Utils.isAdvanceStaticInstrAllowed(className, methName/*"<init>"*/)) {
            if (!methName.equals("<clinit>")) {
                int id = 0;
                super.visitLdcInsn(id);
                super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected",
                        "(I)V");
            } else {
                super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "leaveClinit",
                        "()V");
            }/*from  w  w  w.ja  v a2s.  c  om*/
        }
        break;
    default:
        break;
    }

    super.visitInsn(opcode);
}

From source file:com.taobao.profile.instrument.ProfMethodAdapter.java

License:Open Source License

public void visitInsn(int inst) {
    switch (inst) {
    case Opcodes.ARETURN:
    case Opcodes.DRETURN:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.RETURN:
    case Opcodes.ATHROW:
        this.visitLdcInsn(mMethodId);
        this.visitMethodInsn(INVOKESTATIC, "com/taobao/profile/Profiler", "End", "(I)V");
        break;//w w w  . j a  v a 2s. co m
    default:
        break;
    }

    super.visitInsn(inst);
}

From source file:com.triage.bytecodemaster.GroovyShardTransformer.java

protected boolean isReturnOpCode(int opCode) {
    return opCode == Opcodes.ARETURN || opCode == Opcodes.LRETURN || opCode == Opcodes.IRETURN
            || opCode == Opcodes.DRETURN || opCode == Opcodes.FRETURN || opCode == Opcodes.RETURN;
}

From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java

License:Apache License

@Override
public void visitInsn(int opcode) {
    Expression e;/*from   w  ww.j  a v  a  2s .c  om*/
    Expression first;
    Expression second;
    switch (opcode) {
    case Opcodes.ARRAYLENGTH:
        e = Expression.arrayLength(_exprStack.pop());
        break;
    case Opcodes.ACONST_NULL:
        e = Expression.constant(null, Object.class);
        break;
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.AALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.arrayIndex(second, first);
        break;
    case Opcodes.DCONST_0:
        e = Expression.constant(0d, Double.TYPE);
        break;
    case Opcodes.DCONST_1:
        e = Expression.constant(1d, Double.TYPE);
        break;
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.LCMP:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.subtract(second, first);
        break;
    case Opcodes.FCONST_0:
        e = Expression.constant(0f, Float.TYPE);
        break;
    case Opcodes.FCONST_1:
        e = Expression.constant(1f, Float.TYPE);
        break;
    case Opcodes.FCONST_2:
        e = Expression.constant(2f, Float.TYPE);
        break;
    case Opcodes.ICONST_M1:
        e = Expression.constant(-1, Integer.TYPE);
        break;
    case Opcodes.ICONST_0:
        e = Expression.constant(0, Integer.TYPE);
        break;
    case Opcodes.ICONST_1:
        e = Expression.constant(1, Integer.TYPE);
        break;
    case Opcodes.ICONST_2:
        e = Expression.constant(2, Integer.TYPE);
        break;
    case Opcodes.ICONST_3:
        e = Expression.constant(3, Integer.TYPE);
        break;
    case Opcodes.ICONST_4:
        e = Expression.constant(4, Integer.TYPE);
        break;
    case Opcodes.ICONST_5:
        e = Expression.constant(5, Integer.TYPE);
        break;
    case Opcodes.LCONST_0:
        e = Expression.constant(0l, Long.TYPE);
        break;
    case Opcodes.LCONST_1:
        e = Expression.constant(1l, Long.TYPE);
        break;
    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.add(second, first);
        break;
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.subtract(second, first);
        break;
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.multiply(second, first);
        break;
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.divide(second, first);
        break;
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.modulo(second, first);
        break;
    case Opcodes.INEG:
    case Opcodes.LNEG:
    case Opcodes.FNEG:
    case Opcodes.DNEG:
        first = _exprStack.pop();
        e = Expression.negate(first);
        break;
    case Opcodes.ISHL:
    case Opcodes.LSHL:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.leftShift(second, first);
        break;
    case Opcodes.ISHR:
    case Opcodes.LSHR:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.rightShift(second, first);
        break;
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.rightShift(second, first);
        break;
    case Opcodes.IAND:
    case Opcodes.LAND:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.bitwiseAnd(second, first);
        break;
    case Opcodes.IOR:
    case Opcodes.LOR:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.bitwiseOr(second, first);
        break;
    case Opcodes.IXOR:
    case Opcodes.LXOR:
        first = _exprStack.pop();
        second = _exprStack.pop();
        e = Expression.exclusiveOr(second, first);
        break;
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
        first = _exprStack.pop();
        e = Expression.convert(first, NumericTypeLookup2[opcode - Opcodes.I2B]);
        break;
    case Opcodes.I2L:
    case Opcodes.I2F:
    case Opcodes.I2D:
        first = _exprStack.pop();
        e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.I2L + 1]);
        break;
    case Opcodes.L2I:
    case Opcodes.L2F:
    case Opcodes.L2D:
        int l2l = opcode > Opcodes.L2I ? 1 : 0;
        first = _exprStack.pop();
        e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.L2I + l2l]);
        break;
    case Opcodes.F2I:
    case Opcodes.F2L:
    case Opcodes.F2D:
        int f2f = opcode == Opcodes.F2D ? 1 : 0;
        first = _exprStack.pop();
        e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.F2I + f2f]);
        break;
    case Opcodes.D2I:
    case Opcodes.D2L:
    case Opcodes.D2F:
        first = _exprStack.pop();
        e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.D2I]);
        break;
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:

        go(null);

        return;
    case Opcodes.SWAP:
        first = _exprStack.pop();
        second = _exprStack.pop();
        _exprStack.push(first);
        _exprStack.push(second);
    case Opcodes.DUP:
    case Opcodes.DUP_X1:
    case Opcodes.DUP_X2:
    case Opcodes.DUP2:
    case Opcodes.DUP2_X1:
    case Opcodes.DUP2_X2:
        // our stack is not divided to words
        int base = (opcode - Opcodes.DUP) % 3;
        base++;
        dup(_exprStack, base, base - 1);
        return;
    case Opcodes.NOP:
        return;
    case Opcodes.RETURN:
    default:
        throw notLambda(opcode);
    }

    _exprStack.push(e);
}

From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java

License:Open Source License

private Type getTypeIfSimpleType(final AbstractInsnNode node) {
    final int opcode = node.getOpcode();
    if ((opcode == Opcodes.ILOAD) || (opcode == Opcodes.ISTORE) || (opcode == Opcodes.IRETURN)) {
        return Type.INT_TYPE;
    }/*from   www  . j  a  v a  2 s .co  m*/
    if ((opcode == Opcodes.FLOAD) || (opcode == Opcodes.FSTORE) || (opcode == Opcodes.FRETURN)) {
        return Type.FLOAT_TYPE;
    }
    if ((opcode == Opcodes.LLOAD) || (opcode == Opcodes.LSTORE) || (opcode == Opcodes.LRETURN)) {
        return Type.LONG_TYPE;
    }
    if ((opcode == Opcodes.DLOAD) || (opcode == Opcodes.DSTORE) || (opcode == Opcodes.DRETURN)) {
        return Type.DOUBLE_TYPE;
    }
    return null;
}

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 ww  w  .ja v  a  2 s  .c  o  m*/
            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.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:// w  w  w  .  j ava2  s.c  om
        assert false;
        return "--ERROR--";
    }
}

From source file:de.unisb.cs.st.javaslicer.controlflowanalysis.ControlFlowGraph.java

License:Open Source License

private static Collection<Instruction> getSuccessors(Instruction instruction) {
    int opcode = instruction.getOpcode();
    Instruction nextInstruction = instruction.getNext();
    switch (instruction.getType()) {
    case JUMP:/*from  w  ww.j a  v  a  2s .c  o m*/
        // GOTO and JSR are not conditional
        if (opcode == Opcodes.GOTO || opcode == Opcodes.JSR) {
            return Collections.singleton((Instruction) ((JumpInstruction) instruction).getLabel());
        }
        assert nextInstruction != null;
        return Arrays.asList(((JumpInstruction) instruction).getLabel(), nextInstruction);
    case LOOKUPSWITCH: {
        LookupSwitchInstruction lsi = (LookupSwitchInstruction) instruction;
        Instruction[] successors = new AbstractInstruction[lsi.getHandlers().size() + 1];
        successors[0] = lsi.getDefaultHandler();
        int i = 1;
        for (LabelMarker lm : lsi.getHandlers().values())
            successors[i++] = lm;
        return Arrays.asList(successors);
    }
    case TABLESWITCH: {
        TableSwitchInstruction tsi = (TableSwitchInstruction) instruction;
        Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length + 1];
        successors[0] = tsi.getDefaultHandler();
        System.arraycopy(tsi.getHandlers(), 0, successors, 1, tsi.getHandlers().length);
        return Arrays.asList(successors);
    }
    case SIMPLE:
        switch (opcode) {
        case Opcodes.IRETURN:
        case Opcodes.LRETURN:
        case Opcodes.FRETURN:
        case Opcodes.DRETURN:
        case Opcodes.ARETURN:
        case Opcodes.RETURN:
            return Collections.emptySet();

        default:
            break;
        }
        break;
    case VAR:
        if (opcode == Opcodes.RET) {
            List<JumpInstruction> callingInstructions = getJsrInstructions((VarInstruction) instruction);
            Instruction[] successors = new AbstractInstruction[callingInstructions.size()];
            int i = 0;
            for (JumpInstruction instr : callingInstructions)
                successors[i++] = instr.getNext();
            return Arrays.asList(successors);
        }
        break;
    case LABEL:
        if (instruction == instruction.getMethod().getAbnormalTerminationLabel())
            return Collections.emptySet();
        break;
    default:
        break;
    }
    assert nextInstruction != null;
    return Collections.singleton(nextInstruction);
}

From source file:de.unisb.cs.st.javaslicer.controlflowanalysis.ControlFlowGraph2.java

License:Open Source License

public Collection<Instruction> getSuccessors(Instruction instruction) {
    int opcode = instruction.getOpcode();
    // index??? getnextindex+1?
    Instruction nextInstruction = instruction.getNext();
    switch (instruction.getType()) {
    case JUMP://from  w w  w. j a  v  a2  s . c  om
        // GOTO and JSR are not conditional
        // ????
        if (opcode == Opcodes.GOTO || opcode == Opcodes.JSR) {
            List<AbstractInstruction> instrs = this.method.instructions;
            Iterator<AbstractInstruction> iter = instrs.iterator();
            Instruction temp = null;
            while (iter.hasNext()) {
                temp = iter.next();
                if (temp.getIndex() == ((JumpInstruction2) instruction).getTarget())
                    break;
            }
            return Collections.singleton(temp);
        }
        assert nextInstruction != null;
        // ?nextInstruction, ?label!
        List<AbstractInstruction> instrs = this.method.instructions;
        Iterator<AbstractInstruction> iter = instrs.iterator();
        Instruction temp = null;
        while (iter.hasNext()) {
            temp = iter.next();
            if (temp.getIndex() == ((JumpInstruction2) instruction).getTarget())
                break;
        }
        return Arrays.asList(temp, nextInstruction);
    // switch 
    case LOOKUPSWITCH: {
        LookupSwitchInstruction2 lsi = (LookupSwitchInstruction2) instruction;
        List<AbstractInstruction> instrs4 = this.method.instructions;
        List<AbstractInstruction> instrs5 = this.method.instructions;
        Iterator<AbstractInstruction> iter4 = instrs4.iterator();
        Instruction temp2 = null;
        Instruction[] successors = new AbstractInstruction[lsi.getHandlers().size() + 1];
        // find the default
        while (iter4.hasNext()) {
            temp2 = iter4.next();
            if (temp2.getIndex() == lsi.getDefaultHandler()) {
                successors[0] = temp2;
                break;
            }
        }
        // find the handlers
        int index = 0;
        for (Integer lm : lsi.getHandlers().values()) {
            Iterator<AbstractInstruction> iter5 = instrs5.iterator();
            while (iter5.hasNext()) {
                temp2 = iter5.next();
                if (temp2.getIndex() == lm) {
                    successors[index + 1] = temp2;
                    index++;
                    break;
                }
            }
        }
        return Arrays.asList(successors);
    }
    // switch ?
    case TABLESWITCH: {
        TableSwitchInstruction2 tsi = (TableSwitchInstruction2) instruction;
        List<AbstractInstruction> instrs2 = this.method.instructions;
        List<AbstractInstruction> instrs3 = this.method.instructions;
        Iterator<AbstractInstruction> iter2 = instrs2.iterator();
        //Iterator<AbstractInstruction> iter3=instrs3.iterator();
        Instruction temp2 = null;
        Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length + 1];
        // get the default target
        while (iter2.hasNext()) {
            temp2 = iter2.next();
            if (tsi.getDefaultHandler() == temp2.getIndex()) {
                successors[0] = temp2;
                break;
            }
        }
        // get the target from min to max! 
        for (int i = 0; i < tsi.getHandlers().length; i++) {
            Iterator<AbstractInstruction> iter3 = instrs3.iterator();
            while (iter3.hasNext()) {
                temp2 = iter3.next();
                if (temp2.getIndex() == (tsi.getHandlers()[i])) {
                    successors[i + 1] = temp2;
                    break;
                }
            }
        }
        return Arrays.asList(successors);
        /*
         TableSwitchInstruction tsi = (TableSwitchInstruction) instruction;
         Instruction[] successors = new AbstractInstruction[tsi.getHandlers().length+1];
         successors[0] = tsi.getDefaultHandler();
         System.arraycopy(tsi.getHandlers(), 0, successors, 1, tsi.getHandlers().length);
         return Arrays.asList(successors);*/
    }
    // ???return??nextInstruction!
    case SIMPLE:
        switch (opcode) {
        case Opcodes.IRETURN:
        case Opcodes.LRETURN:
        case Opcodes.FRETURN:
        case Opcodes.DRETURN:
        case Opcodes.ARETURN:
        case Opcodes.RETURN:
            return Collections.emptySet();

        default:
            break;
        }
        break;
    // ??ret 
    case VAR:
        if (opcode == Opcodes.RET) {
            List<JumpInstruction2> callingInstructions = getJsrInstructions((VarInstruction) instruction);
            Instruction[] successors = new AbstractInstruction[callingInstructions.size()];
            int i = 0;
            for (JumpInstruction2 instr : callingInstructions)
                successors[i++] = instr.getNext();
            return Arrays.asList(successors);
        }
        break;
    // label abnormalTermination?nextInstruction!
    case LABEL:
        if (instruction == instruction.getMethod().getAbnormalTerminationLabel())
            return Collections.emptySet();
        break;
    default:
        break;
    }
    // ?index+1??
    assert nextInstruction != null;
    return Collections.singleton(nextInstruction);
}