Example usage for org.objectweb.asm Opcodes JSR

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

Introduction

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

Prototype

int JSR

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

Click Source Link

Usage

From source file:com.xruby.compiler.codegen.RubyCompilerImpl.java

License:BSD License

private void invokeFinallyIfExist() {
    MethodGenerator mg = cg_.getMethodGenerator();
    Label l = mg.getEnsureLabelManager().getCurrentFinally();
    if (null != l) {
        int tmp = cg_.getAnonymousLocalVariable();
        mg.storeLocal(tmp);//store then load to make stack size always equals 1
        mg.visitJumpInsn(Opcodes.JSR, l);
        mg.loadLocal(tmp);/*w w  w .j  a  v  a  2 s.  c  o  m*/
    }
}

From source file:de.scoopgmbh.copper.instrument.BuildStackInfoAdapter.java

License:Apache License

@Override
public void visitJumpInsn(int arg0, Label arg1) {
    savePreviousFrame();/*from   w w w. j a va 2s .c o m*/
    switch (arg0) {
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPNE:
        currentFrame.popStack();
    case Opcodes.IFEQ:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFNE:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
        currentFrame.popStack();
    case Opcodes.GOTO:
        forwardFrames.put(arg1, new StackInfo(currentFrame));
        break;
    case Opcodes.JSR:
        currentFrame.pushStack(retAddressType);
        forwardFrames.put(arg1, new StackInfo(currentFrame));
        break;
    default:
        logger.debug("Unhandled: ");
    }
    if (logger.isDebugEnabled())
        logger.debug("jumpInsn " + getOpCode(arg0) + " " + arg1);
    delegate.visitJumpInsn(arg0, arg1);
}

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

License:Open Source License

@Override
public String toString() {
    String condition;//w  w w .  ja v  a  2  s  .c om
    switch (getOpcode()) {
    case Opcodes.IFEQ:
        condition = "IFEQ";
        break;
    case Opcodes.IFNE:
        condition = "IFNE";
        break;
    case Opcodes.IFLT:
        condition = "IFLT";
        break;
    case Opcodes.IFGE:
        condition = "IFGE";
        break;
    case Opcodes.IFGT:
        condition = "IFGT";
        break;
    case Opcodes.IFLE:
        condition = "IFLE";
        break;
    case Opcodes.IF_ICMPEQ:
        condition = "IF_ICMPEQ";
        break;
    case Opcodes.IF_ICMPNE:
        condition = "IF_ICMPNE";
        break;
    case Opcodes.IF_ICMPLT:
        condition = "IF_ICMPLT";
        break;
    case Opcodes.IF_ICMPGE:
        condition = "IF_ICMPGE";
        break;
    case Opcodes.IF_ICMPGT:
        condition = "IF_ICMPGT";
        break;
    case Opcodes.IF_ICMPLE:
        condition = "IF_ICMPLE";
        break;
    case Opcodes.IF_ACMPEQ:
        condition = "IF_ACMPEQ";
        break;
    case Opcodes.IF_ACMPNE:
        condition = "IF_ACMPNE";
        break;
    case Opcodes.GOTO:
        condition = "GOTO";
        break;
    case Opcodes.JSR:
        condition = "JSR";
        break;
    case Opcodes.IFNULL:
        condition = "IFNULL";
        break;
    case Opcodes.IFNONNULL:
        condition = "IFNONNULL";
        break;
    default:
        assert false;
        condition = "--ERROR--";
        break;
    }

    return condition + " " + this.label;
}

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

License:Open Source License

@Override
public String toString() {
    String condition;/*  w  w w  . j  a  v  a 2s .  c  o  m*/
    switch (getOpcode()) {
    case Opcodes.IFEQ:
        condition = "IFEQ";
        break;
    case Opcodes.IFNE:
        condition = "IFNE";
        break;
    case Opcodes.IFLT:
        condition = "IFLT";
        break;
    case Opcodes.IFGE:
        condition = "IFGE";
        break;
    case Opcodes.IFGT:
        condition = "IFGT";
        break;
    case Opcodes.IFLE:
        condition = "IFLE";
        break;
    case Opcodes.IF_ICMPEQ:
        condition = "IF_ICMPEQ";
        break;
    case Opcodes.IF_ICMPNE:
        condition = "IF_ICMPNE";
        break;
    case Opcodes.IF_ICMPLT:
        condition = "IF_ICMPLT";
        break;
    case Opcodes.IF_ICMPGE:
        condition = "IF_ICMPGE";
        break;
    case Opcodes.IF_ICMPGT:
        condition = "IF_ICMPGT";
        break;
    case Opcodes.IF_ICMPLE:
        condition = "IF_ICMPLE";
        break;
    case Opcodes.IF_ACMPEQ:
        condition = "IF_ACMPEQ";
        break;
    case Opcodes.IF_ACMPNE:
        condition = "IF_ACMPNE";
        break;
    case Opcodes.GOTO:
        condition = "GOTO";
        break;
    case Opcodes.JSR:
        condition = "JSR";
        break;
    case Opcodes.IFNULL:
        condition = "IFNULL";
        break;
    case Opcodes.IFNONNULL:
        condition = "IFNONNULL";
        break;
    default:
        assert false;
        condition = "--ERROR--";
        break;
    }

    return condition + " " + this.target;
}

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  ww w .j av  a2s .  c om
        // 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.ControlFlowGraph.java

License:Open Source License

/**
 * Returns all <code>jsr</code> instructions that may end up in the given <code>ret</code> instructions.
 *///from   ww  w. ja v a  2s  .  co m
private static List<JumpInstruction> getJsrInstructions(VarInstruction retInstruction) {
    assert retInstruction.getOpcode() == Opcodes.RET;
    List<JumpInstruction> list = new ArrayList<JumpInstruction>();
    for (AbstractInstruction instr : retInstruction.getMethod().getInstructions()) {
        if (instr.getOpcode() == Opcodes.JSR) {
            Queue<Instruction> queue = new UniqueQueue<Instruction>();
            queue.add(((JumpInstruction) instr).getLabel());
            while (!queue.isEmpty()) {
                Instruction instr2 = queue.poll();
                if (instr2.getOpcode() == Opcodes.RET) {
                    if (instr2 == retInstruction) {
                        list.add((JumpInstruction) instr);
                    }
                    break;
                }
                queue.addAll(getSuccessors(instr));
            }
        }
    }

    return list;
}

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 ww.j av  a 2s . c  o  m
        // 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);
}

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

License:Open Source License

/**
 * Returns all <code>jsr</code> instructions that may end up in the given <code>ret</code> instructions.
 *///  www.j  a va  2 s.  co m
private List<JumpInstruction2> getJsrInstructions(VarInstruction retInstruction) {
    assert retInstruction.getOpcode() == Opcodes.RET;
    List<JumpInstruction2> list = new ArrayList<JumpInstruction2>();
    for (AbstractInstruction instr : retInstruction.getMethod().getInstructions()) {
        if (instr.getOpcode() == Opcodes.JSR) {
            Queue<Instruction> queue = new UniqueQueue<Instruction>();
            queue.add(((JumpInstruction2) instr).getLabel());
            while (!queue.isEmpty()) {
                Instruction instr2 = queue.poll();
                if (instr2.getOpcode() == Opcodes.RET) {
                    if (instr2 == retInstruction) {
                        list.add((JumpInstruction2) instr);
                    }
                    break;
                }
                queue.addAll(getSuccessors(instr));
            }
        }
    }

    return list;
}

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

License:BSD License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    mv.visitJumpInsn(opcode, label);//from  w w  w. j  a  v  a 2s .  c o m
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        this.stackFrame.pop();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.JSR:
        this.stackFrame.push(OTHER);
        break;
    }
    addBranch(label);
}

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

License:Open Source License

private void interpret(JumpInsnNode insn, FrameState frame, BBInfo block) {
    //All JumpInsnNodes have a target.  Find it.
    BBInfo target = blockByInsn(insn.label);
    assert target != null;

    if (insn.getOpcode() == Opcodes.GOTO) {
        block.block.instructions().add(new JumpInst(target.block));
        return;/*from  ww w.  j  ava 2s .  c o m*/
    } else if (insn.getOpcode() == Opcodes.JSR)
        throw new UnsupportedOperationException("jsr not supported; upgrade to Java 6-era class files");

    //Remaining opcodes are branches.
    BBInfo fallthrough = blocks.get(blocks.indexOf(block) + 1);
    BranchInst.Sense sense = OPCODE_TO_SENSE.get(insn.getOpcode());
    //The second operand may come from the stack or may be a constant 0 or null.
    Value right;
    switch (insn.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        right = module.constants().getConstant(0);
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        right = module.constants().getNullConstant();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        right = frame.stack.pop();
        break;
    default:
        throw new AssertionError("Can't happen! Branch opcode missing? " + insn.getOpcode());
    }
    //First operand always comes from the stack.
    Value left = frame.stack.pop();
    block.block.instructions().add(new BranchInst(left, sense, right, target.block, fallthrough.block));
}