Java 类org.apache.bcel.generic.JsrInstruction 实例源码

项目:VestaClient    文件:Subroutines.java   
/**
 * Adds a new JSR or JSR_W that has this subroutine as its target.
 */
public void addEnteringJsrInstruction(InstructionHandle jsrInst){
    if ( (jsrInst == null) || (! (jsrInst.getInstruction() instanceof JsrInstruction))){
        throw new AssertionViolatedException("Expecting JsrInstruction InstructionHandle.");
    }
    if (localVariable == UNSET){
        throw new AssertionViolatedException("Set the localVariable first!");
    }
    else{
        // Something is wrong when an ASTORE is targeted that does not operate on the same local variable than the rest of the
        // JsrInstruction-targets and the RET.
        // (We don't know out leader here so we cannot check if we're really targeted!)
        if (localVariable != ((ASTORE) (((JsrInstruction) jsrInst.getInstruction()).getTarget().getInstruction())).getIndex()){
            throw new AssertionViolatedException("Setting a wrong JsrInstruction.");
        }
    }
    theJSRs.add(jsrInst);
}
项目:VestaClient    文件:ControlFlowGraph.java   
/**
 * Returns the InstructionContextImpl with an JSR/JSR_W
 * that was last in the ExecutionChain, without
 * a corresponding RET, i.e.
 * we were called by this one.
 * Returns null if we were called from the top level.
 */
private InstructionContextImpl lastExecutionJSR(){

    int size = executionPredecessors.size();
    int retcount = 0;

    for (int i=size-1; i>=0; i--){
        InstructionContextImpl current = (InstructionContextImpl) (executionPredecessors.get(i));
        Instruction currentlast = current.getInstruction().getInstruction();
        if (currentlast instanceof RET) {
                  retcount++;
              }
        if (currentlast instanceof JsrInstruction){
            retcount--;
            if (retcount == -1) {
                      return current;
                  }
        }
    }
    return null;
}
项目:eclectic    文件:Subroutines.java   
/**
 * Adds a new JSR or JSR_W that has this subroutine as its target.
 */
public void addEnteringJsrInstruction(InstructionHandle jsrInst){
    if ( (jsrInst == null) || (! (jsrInst.getInstruction() instanceof JsrInstruction))){
        throw new AssertionViolatedException("Expecting JsrInstruction InstructionHandle.");
    }
    if (localVariable == UNSET){
        throw new AssertionViolatedException("Set the localVariable first!");
    }
    else{
        // Something is wrong when an ASTORE is targeted that does not operate on the same local variable than the rest of the
        // JsrInstruction-targets and the RET.
        // (We don't know out leader here so we cannot check if we're really targeted!)
        if (localVariable != ((ASTORE) (((JsrInstruction) jsrInst.getInstruction()).getTarget().getInstruction())).getIndex()){
            throw new AssertionViolatedException("Setting a wrong JsrInstruction.");
        }
    }
    theJSRs.add(jsrInst);
}
项目:eclectic    文件:ExecutionPath.java   
/**
 * Returns the InstructionContextImpl with an JSR/JSR_W
 * that was last in the ExecutionChain, without
 * a corresponding RET, i.e.
 * we were called by this one.
 * Returns null if we were called from the top level.
 */
public InstructionContext lastExecutionJSR(){
    int retcount = 0;

    for( ExecutionPath ptr = this; ptr!=EMPTY; ptr=ptr.prev) {
        Instruction i = ptr.last.getInstruction().getInstruction();
        if (i instanceof RET) retcount++;
        if (i instanceof JsrInstruction){
            retcount--;
            if (retcount == -1)
                return ptr.last;
        }
    }

    return null;
}
项目:eclectic    文件:Subroutines.java   
/**
 * Adds a new JSR or JSR_W that has this subroutine as its target.
 */
public void addEnteringJsrInstruction(InstructionHandle jsrInst){
    if ( (jsrInst == null) || (! (jsrInst.getInstruction() instanceof JsrInstruction))){
        throw new AssertionViolatedException("Expecting JsrInstruction InstructionHandle.");
    }
    if (localVariable == UNSET){
        throw new AssertionViolatedException("Set the localVariable first!");
    }
    else{
        // Something is wrong when an ASTORE is targeted that does not operate on the same local variable than the rest of the
        // JsrInstruction-targets and the RET.
        // (We don't know out leader here so we cannot check if we're really targeted!)
        if (localVariable != ((ASTORE) (((JsrInstruction) jsrInst.getInstruction()).getTarget().getInstruction())).getIndex()){
            throw new AssertionViolatedException("Setting a wrong JsrInstruction.");
        }
    }
    theJSRs.add(jsrInst);
}
项目:eclectic    文件:ExecutionPath.java   
/**
 * Returns the InstructionContextImpl with an JSR/JSR_W
 * that was last in the ExecutionChain, without
 * a corresponding RET, i.e.
 * we were called by this one.
 * Returns null if we were called from the top level.
 */
public InstructionContext lastExecutionJSR(){
    int retcount = 0;

    for( ExecutionPath ptr = this; ptr!=EMPTY; ptr=ptr.prev) {
        Instruction i = ptr.last.getInstruction().getInstruction();
        if (i instanceof RET) retcount++;
        if (i instanceof JsrInstruction){
            retcount--;
            if (retcount == -1)
                return ptr.last;
        }
    }

    return null;
}
项目:VestaClient    文件:Subroutines.java   
public Subroutine[] subSubs(){
    Set h = new HashSet();

    Iterator i = instructions.iterator();
    while (i.hasNext()){
        Instruction inst = ((InstructionHandle) i.next()).getInstruction();
        if (inst instanceof JsrInstruction){
            InstructionHandle targ = ((JsrInstruction) inst).getTarget();
            h.add(getSubroutine(targ));
        }
    }
    Subroutine[] ret = new Subroutine[h.size()];
    return (Subroutine[]) h.toArray(ret);
}
项目:eclectic    文件:Subroutines.java   
public Subroutine[] subSubs(){
    final Set<Subroutine> h = new HashSet<Subroutine>();
    for (final InstructionHandle ih : instructions){
        final Instruction inst = ih.getInstruction();
        if (inst instanceof JsrInstruction){
            InstructionHandle targ = ((JsrInstruction) inst).getTarget();
            h.add(getSubroutine(targ));
        }
    }
    final Subroutine[] ret = new Subroutine[h.size()];
    return h.toArray(ret);
}
项目:eclectic    文件:Subroutines.java   
public Subroutine[] subSubs(){
    final Set<Subroutine> h = new HashSet<Subroutine>();
    for (final InstructionHandle ih : instructions){
        final Instruction inst = ih.getInstruction();
        if (inst instanceof JsrInstruction){
            InstructionHandle targ = ((JsrInstruction) inst).getTarget();
            h.add(getSubroutine(targ));
        }
    }
    final Subroutine[] ret = new Subroutine[h.size()];
    return h.toArray(ret);
}
项目:VestaClient    文件:Pass3aVerifier.java   
/**
 * These are the checks for the satisfaction of constraints which are described in the
 * Java Virtual Machine Specification, Second Edition as Static Constraints on
 * the operands of instructions of Java Virtual Machine Code (chapter 4.8.1).
 * BCEL parses the code array to create an InstructionList and therefore has to check
 * some of these constraints. Additional checks are also implemented here.
 *
 * @throws StaticCodeConstraintException if the verification fails.
 */
private void pass3StaticInstructionOperandsChecks(){
    try {
    // When building up the InstructionList, BCEL has already done all those checks
    // mentioned in The Java Virtual Machine Specification, Second Edition, as
    // "static constraints on the operands of instructions in the code array".
    // TODO: see the do_verify() comments. Maybe we should really work on the
    //       byte array first to give more comprehensive messages.
    // TODO: Review Exception API, possibly build in some "offending instruction" thing
    //       when we're ready to insulate the offending instruction by doing the
    //       above thing.

    // TODO: Implement as much as possible here. BCEL does _not_ check everything.

    ConstantPoolGen cpg = new ConstantPoolGen(Repository.lookupClass(myOwner.getClassName()).getConstantPool());
    InstOperandConstraintVisitor v = new InstOperandConstraintVisitor(cpg);

    // Checks for the things BCEL does _not_ handle itself.
    InstructionHandle ih = instructionList.getStart();
    while (ih != null){
        Instruction i = ih.getInstruction();

        // An "own" constraint, due to JustIce's new definition of what "subroutine" means.
        if (i instanceof JsrInstruction){
            InstructionHandle target = ((JsrInstruction) i).getTarget();
            if (target == instructionList.getStart()){
                throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may have a top-level instruction (such as the very first instruction, which is targeted by instruction '"+ih+"' as its target.");
            }
            if (!(target.getInstruction() instanceof ASTORE)){
                throw new StaticCodeInstructionOperandConstraintException("Due to JustIce's clear definition of subroutines, no JSR or JSR_W may target anything else than an ASTORE instruction. Instruction '"+ih+"' targets '"+target+"'.");
            }
        }

        // vmspec2, page 134-137
        ih.accept(v);

        ih = ih.getNext();
    }

    } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
项目:VestaClient    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    final InstructionHandle[] empty = new InstructionHandle[0];
    final InstructionHandle[] single = new InstructionHandle[1];
    final InstructionHandle[] pair = new InstructionHandle[2];

    Instruction inst = instruction.getInstruction();

    if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

    // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.      
    single[0] = instruction.getNext();
    return single;
}
项目:eclectic    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    Instruction inst = instruction.getInstruction();

       if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

       final InstructionHandle[] single = new InstructionHandle[1];

       // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
               final InstructionHandle[] pair = new InstructionHandle[2];
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.
    single[0] = instruction.getNext();
    return single;
}
项目:eclectic    文件:ControlFlowGraph.java   
/**
         * A utility method that calculates the successors of a given InstructionHandle
         * That means, a RET does have successors as defined here.
         * A JsrInstruction has its target as its successor
         * (opposed to its physical successor) as defined here.
         */
// TODO: implement caching!
        private InstructionHandle[] _getSuccessors(){
            final InstructionHandle[] empty = new InstructionHandle[0];
            final InstructionHandle[] single = new InstructionHandle[1];
            final InstructionHandle[] pair = new InstructionHandle[2];

            Instruction inst = getInstruction().getInstruction();

            if (inst instanceof RET){
                Subroutine s = subroutines.subroutineOf(getInstruction());
                if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project...
                    throw new AssertionViolatedException("Asking for successors of a RET in dead code?!");
                }
//TODO: remove
throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?");
/*
                InstructionHandle[] jsrs = s.getEnteringJsrInstructions();
                InstructionHandle[] ret = new InstructionHandle[jsrs.length];
                for (int i=0; i<jsrs.length; i++){
                    ret[i] = jsrs[i].getNext();
                }
                return ret;
*/
            }

            // Terminates method normally.
            if (inst instanceof ReturnInstruction){
                return empty;
            }

            // Terminates method abnormally, because JustIce mandates
            // subroutines not to be protected by exception handlers.
            if (inst instanceof ATHROW){
                return empty;
            }

            // See method comment.
            if (inst instanceof JsrInstruction){
                single[0] = ((JsrInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof GotoInstruction){
                single[0] = ((GotoInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof BranchInstruction){
                if (inst instanceof Select){
                    // BCEL's getTargets() returns only the non-default targets,
                    // thanks to Eli Tilevich for reporting.
                    InstructionHandle[] matchTargets = ((Select) inst).getTargets();
                    InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
                    ret[0] = ((Select) inst).getTarget();
                    System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
                    return ret;
                }
                else{
                    pair[0] = getInstruction().getNext();
                    pair[1] = ((BranchInstruction) inst).getTarget();
                    return pair;
                }
            }

            // default case: Fall through.      
            single[0] = getInstruction().getNext();
            return single;
        }
项目:eclectic    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    Instruction inst = instruction.getInstruction();

       if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

       final InstructionHandle[] single = new InstructionHandle[1];

       // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
               final InstructionHandle[] pair = new InstructionHandle[2];
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.
    single[0] = instruction.getNext();
    return single;
}
项目:eclectic    文件:ControlFlowGraph.java   
/**
         * A utility method that calculates the successors of a given InstructionHandle
         * That means, a RET does have successors as defined here.
         * A JsrInstruction has its target as its successor
         * (opposed to its physical successor) as defined here.
         */
// TODO: implement caching!
        private InstructionHandle[] _getSuccessors(){
            final InstructionHandle[] empty = new InstructionHandle[0];
            final InstructionHandle[] single = new InstructionHandle[1];
            final InstructionHandle[] pair = new InstructionHandle[2];

            Instruction inst = getInstruction().getInstruction();

            if (inst instanceof RET){
                Subroutine s = subroutines.subroutineOf(getInstruction());
                if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project...
                    throw new AssertionViolatedException("Asking for successors of a RET in dead code?!");
                }
//TODO: remove
throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?");
/*
                InstructionHandle[] jsrs = s.getEnteringJsrInstructions();
                InstructionHandle[] ret = new InstructionHandle[jsrs.length];
                for (int i=0; i<jsrs.length; i++){
                    ret[i] = jsrs[i].getNext();
                }
                return ret;
*/
            }

            // Terminates method normally.
            if (inst instanceof ReturnInstruction){
                return empty;
            }

            // Terminates method abnormally, because JustIce mandates
            // subroutines not to be protected by exception handlers.
            if (inst instanceof ATHROW){
                return empty;
            }

            // See method comment.
            if (inst instanceof JsrInstruction){
                single[0] = ((JsrInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof GotoInstruction){
                single[0] = ((GotoInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof BranchInstruction){
                if (inst instanceof Select){
                    // BCEL's getTargets() returns only the non-default targets,
                    // thanks to Eli Tilevich for reporting.
                    InstructionHandle[] matchTargets = ((Select) inst).getTargets();
                    InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
                    ret[0] = ((Select) inst).getTarget();
                    System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
                    return ret;
                }
                else{
                    pair[0] = getInstruction().getNext();
                    pair[1] = ((BranchInstruction) inst).getTarget();
                    return pair;
                }
            }

            // default case: Fall through.      
            single[0] = getInstruction().getNext();
            return single;
        }