Java Code Examples for com.sun.jdi.Method#signature()

The following examples show how to use com.sun.jdi.Method#signature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 6 votes vote down vote up
private void exec_IFX_lookAhead() throws GuidanceException {
    if (this.lookAheadDone) {
        return;
    }

    //checks
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    if (bc[currentCodeIndex] < OP_IFEQ || bc[currentCodeIndex] > OP_IF_ACMPNE) {
        final Method jdiMeth = this.currentStepEvent.location().method();
        final String jdiMethClassName = jdiMethodClassName(jdiMeth);
        final String jdiMethDescr = jdiMeth.signature();
        final String jdiMethName = jdiMeth.name();
        throw new GuidanceException("Wrong step alignment during IFX lookahead (JDI at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + currentCodeIndex + ", bytecode = " + opcodeName(bc[currentCodeIndex]) + ")");
    }

    //steps
    lookAhead();

    //takes the decision
    final int newOffset = getCurrentCodeIndex();
    final int jumpOffset = currentCodeIndex + byteCatShort(bc[currentCodeIndex + 1], bc[currentCodeIndex + 2]);
    this.lookAheadDecisionBoolean = (newOffset == jumpOffset); 
}
 
Example 2
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private void exec_INVOKEX_lookAhead() throws GuidanceException {
    if (this.lookAheadDone) {
        return;
    }

    //checks
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    if (bc[currentCodeIndex] < OP_INVOKEVIRTUAL || bc[currentCodeIndex] > OP_INVOKEDYNAMIC) {
        final Method jdiMeth = this.currentStepEvent.location().method();
        final String jdiMethClassName = jdiMethodClassName(jdiMeth);
        final String jdiMethDescr = jdiMeth.signature();
        final String jdiMethName = jdiMeth.name();
        throw new GuidanceException("Wrong step alignment during INVOKEX lookahead (JDI at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + currentCodeIndex + ", bytecode = " + opcodeName(bc[currentCodeIndex]) + ")");
    }

    //steps and decides
    try {
        final int intialFrames = this.currentStepEvent.thread().frameCount();
        doStep(true); //true -> StepInto  
        final int currFramesStepPre = this.currentStepEvent.thread().frameCount();
        if (currFramesStepPre <= intialFrames) {
            throw new GuidanceException("Error during INVOKEX lookahead: I expected to step into a new frame");
        }

        this.lookAheadUnintFuncNonPrimitiveRetValue = (ObjectReference) stepUpToMethodExit();

        doStep(false); //false -> StepOver  
        final int currFramesStepPost = this.currentStepEvent.thread().frameCount();
        if (currFramesStepPost != intialFrames) {
            throw new GuidanceException("Error during INVOKEX lookahead: I expected to step into a new frame");
        }

    } catch (IncompatibleThreadStateException e) {
        throw new GuidanceException(e);
    }
    this.lookAheadDone = true;
}
 
Example 3
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private void exec_XALOAD_lookAhead() throws GuidanceException {
    if (this.lookAheadDone) {
        return;
    }

    //checks
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    final int nextCodeIndex;
    if (bc[currentCodeIndex] >= OP_IALOAD && bc[currentCodeIndex] <= OP_SALOAD) {
        nextCodeIndex = currentCodeIndex + XALOADSTORE_OFFSET;
    } else if (bc[currentCodeIndex] == OP_INVOKEVIRTUAL) { //invokevirtual sun.misc.Unsafe.getIntVolatile or invokevirtual sun.misc.Unsafe.getObjectVolatile
        nextCodeIndex = currentCodeIndex + INVOKESPECIALSTATICVIRTUAL_OFFSET;
    } else {
        final Method jdiMeth = this.currentStepEvent.location().method();
        final String jdiMethClassName = jdiMethodClassName(jdiMeth);
        final String jdiMethDescr = jdiMeth.signature();
        final String jdiMethName = jdiMeth.name();
        throw new GuidanceException("Wrong step alignment during XALOAD (or INVOKEVIRTUAL sun/misc/Unsafe:getIntVolatile, or INVOKEVIRTUAL sun/misc/Unsafe:getObjectVolatile) lookahead (JDI at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + currentCodeIndex + ", bytecode = " + opcodeName(bc[currentCodeIndex]) + ")");
    }

    //steps
    lookAhead();

    //takes the decision
    calcLookaheadDecision(nextCodeIndex);
}
 
Example 4
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private void exec_XNEWARRAY_lookAhead() throws GuidanceException {
    if (this.lookAheadDone) {
        return;
    }

    //check
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    final int nextCodeIndex;
    if (bc[currentCodeIndex] == OP_NEWARRAY) {
        nextCodeIndex = currentCodeIndex + NEWARRAY_OFFSET;
    } else if (bc[currentCodeIndex] == OP_ANEWARRAY) {
        nextCodeIndex = currentCodeIndex + ANEWARRAY_OFFSET;
    } else if (bc[currentCodeIndex] == OP_MULTIANEWARRAY) {
        nextCodeIndex = currentCodeIndex + MULTIANEWARRAY_OFFSET;
    } else {
        final Method jdiMeth = this.currentStepEvent.location().method();
        final String jdiMethClassName = jdiMethodClassName(jdiMeth);
        final String jdiMethDescr = jdiMeth.signature();
        final String jdiMethName = jdiMeth.name();
        throw new GuidanceException("Wrong step alignment during XNEWARRAY lookahead (JDI at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + currentCodeIndex + ", bytecode = " + opcodeName(bc[currentCodeIndex]) + ")");
    }

    //steps
    lookAhead();

    //takes the decision
    calcLookaheadDecision(nextCodeIndex);
}
 
Example 5
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private void exec_XASTORE_lookAhead() throws GuidanceException {
    if (this.lookAheadDone) {
        return;
    }

    //check
    final int currentCodeIndex = getCurrentCodeIndex();
    final byte[] bc = getCurrentBytecode();
    final int nextCodeIndex;
    if (bc[currentCodeIndex] >= OP_IASTORE && bc[currentCodeIndex] <= OP_SASTORE) {
        nextCodeIndex = currentCodeIndex + XALOADSTORE_OFFSET;
    } else if (bc[currentCodeIndex] == OP_INVOKESTATIC || bc[currentCodeIndex] == OP_INVOKEVIRTUAL) { //invokestatic java.lang.System.arrayCopy or invokevirtual sun.misc.Unsafe.putObjectVolatile
        nextCodeIndex = currentCodeIndex + INVOKESPECIALSTATICVIRTUAL_OFFSET;
    } else {
        final Method jdiMeth = this.currentStepEvent.location().method();
        final String jdiMethClassName = jdiMethodClassName(jdiMeth);
        final String jdiMethDescr = jdiMeth.signature();
        final String jdiMethName = jdiMeth.name();
        throw new GuidanceException("Wrong step alignment during XASTORE (or INVOKESTATIC java/lang/System:arrayCopy, or INVOKEVIRTUAL sun/misc/Unsafe:putObjectVolatile) lookahead (JDI at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + currentCodeIndex + ", bytecode = " + opcodeName(bc[currentCodeIndex]) + ")");
    }

    //steps
    lookAhead();

    //takes the decision
    calcLookaheadDecision(nextCodeIndex);
}
 
Example 6
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Signature getCurrentMethodSignature() throws ThreadStackEmptyException {
    if (this.currentStepEvent == null && this.methodEntryEvent == null) {
        throw new ThreadStackEmptyException();
    }
    final Method jdiMeth = (this.currentStepEvent == null ? this.methodEntryEvent.location().method() : this.currentStepEvent.location().method());
    final String jdiMethClassName = jdiMethodClassName(jdiMeth);
    final String jdiMethDescr = jdiMeth.signature();
    final String jdiMethName = jdiMeth.name();
    return new Signature(jdiMethClassName, jdiMethDescr, jdiMethName);
}
 
Example 7
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 4 votes vote down vote up
private void checkAlignmentWithJbseOrThrowException(State jbseState) 
throws FrozenStateException, GuidanceException, ThreadStackEmptyException, IncompatibleThreadStateException {
    //HACK: if JDI is loading a set of classes just wait for it to end (JBSE does not invoke the classloader in the current configuration)  
    while (jdiMethodClassName(this.currentStepEvent.location().method()).equals("java/lang/ClassLoader")) {
        stepUpToMethodExit();
        doStep(true); //true -> StepInto
    }
    //TODO pedantically walk the whole stack and check all frames; by now we are less paranoid and just check the stack depth and the topmost frame

    //gets JDI stack data
    final int jdiStackSize = numFramesFromRootFrameConcrete();
    final Method jdiMeth = this.currentStepEvent.location().method();
    final String jdiMethClassName = jdiMethodClassName(jdiMeth);
    final String jdiMethDescr = jdiMeth.signature();
    final String jdiMethName = jdiMeth.name();
    final int jdiProgramCounter = getCurrentCodeIndex();

    //gets JBSE stack data
    final int jbseStackSize = jbseState.getStackSize();
    final Signature jbseMeth = jbseState.getCurrentMethodSignature();
    final String jbseMethClassname = jbseMeth.getClassName() == null ? null : jbseMeth.getClassName();
    final String jbseMethDescr = jbseMeth.getDescriptor() == null ? null : jbseMeth.getDescriptor();
    final String jbseMethName = jbseMeth.getName() == null ? null : jbseMeth.getName();
    final int jbseProgramCounter = jbseState.getCurrentProgramCounter();

    if (jdiStackSize == jbseStackSize && jdiMethName.equals(jbseMethName) && 
        jdiMethDescr.equals(jbseMethDescr) && jdiMethClassName.equals(jbseMethClassname) &&
        jdiProgramCounter == jbseProgramCounter) {
        return;
    //HACK: if JBSE is just one bytecode behind JDI, then step and realign: This compensates
    //the fact that, in some situations (e.g., after class initialization), JBSE repeats 
    //a previously abandoned execution of a bytecode, while JDI does not  
    } else if (jdiStackSize == jbseStackSize && jdiMethName.equals(jbseMethName) && 
               jdiMethDescr.equals(jbseMethDescr) && jdiMethClassName.equals(jbseMethClassname) &&
               jdiProgramCounter == jbseProgramCounter + offset(jbseState.getCurrentFrame().getCode(), jbseProgramCounter, -1)) {
        this.lookAheadDone = true;
        return;
    //HACK: if JBSE is in a <clinit> method and JDI is not, then wait for JBSE: This compensates
    //the fact that, in some situations, JBSE runs a class initializer that JDI did run before 
    //(note howewer that, if the stack size is the same, JDI is inside a method invocation)  
    } else if (jdiStackSize == jbseStackSize && "<clinit>".equals(jbseMethName)) {
        this.jbseIsDoingClinit = true;
        return;
    } else {
        throw new GuidanceException("JDI alignment with JBSE failed unexpectedly: JBSE is at " + jbseState.getCurrentMethodSignature() + ":" + jbseProgramCounter + ", while JDI is at " + jdiMethClassName + ":" + jdiMethDescr + ":" + jdiMethName + ":" + jdiProgramCounter);
    }	
}