com.sun.jdi.IncompatibleThreadStateException Java Examples

The following examples show how to use com.sun.jdi.IncompatibleThreadStateException. 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: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void popFrames (ThreadReference thread, StackFrame frame) {
    PropertyChangeEvent evt = null;
    accessLock.readLock().lock();
    try {
        JPDAThreadImpl threadImpl = getThread(thread);
        setState (STATE_RUNNING);
        try {
            threadImpl.popFrames(frame);
            evt = updateCurrentCallStackFrameNoFire(threadImpl);
        } catch (IncompatibleThreadStateException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            setState (STATE_STOPPED);
        }
    } finally {
        accessLock.readLock().unlock();
    }
    if (evt != null) {
        firePropertyChange(evt);
    }
}
 
Example #2
Source File: JPDAThreadImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void submitCheckForMonitorEntered(ObjectReference waitingMonitor) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, IllegalThreadStateExceptionWrapper {
    try {
        ThreadReferenceWrapper.suspend(threadReference);
        logger.fine("submitCheckForMonitorEntered(): suspending "+threadName);
        ObjectReference monitor = ThreadReferenceWrapper.currentContendedMonitor(threadReference);
        if (monitor == null) return ;
        Location loc = StackFrameWrapper.location(ThreadReferenceWrapper.frame(threadReference, 0));
        loc = MethodWrapper.locationOfCodeIndex(LocationWrapper.method(loc), LocationWrapper.codeIndex(loc) + 1);
        if (loc == null) return;
        BreakpointRequest br = EventRequestManagerWrapper.createBreakpointRequest(
                VirtualMachineWrapper.eventRequestManager(MirrorWrapper.virtualMachine(threadReference)), loc);
        BreakpointRequestWrapper.addThreadFilter(br, threadReference);
        submitMonitorEnteredRequest(br);
    } catch (IncompatibleThreadStateException itex) {
        Exceptions.printStackTrace(itex);
    } catch (InvalidStackFrameExceptionWrapper isex) {
        Exceptions.printStackTrace(isex);
    } finally {
        logger.fine("submitCheckForMonitorEntered(): resuming "+threadName);
        ThreadReferenceWrapper.resume(threadReference);
    }
}
 
Example #3
Source File: ThreadInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #4
Source File: ThreadInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #5
Source File: InvokableTypeImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #6
Source File: ThreadInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #7
Source File: ThreadInfo.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #8
Source File: InvokableTypeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #9
Source File: ThreadInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #10
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 #11
Source File: InvokableTypeImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #12
Source File: InvokableTypeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #13
Source File: InvokableTypeImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #14
Source File: ThreadInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #15
Source File: InvokableTypeImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #16
Source File: DynamothCollector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void getCurrentTest(ThreadReference threadRef) {
	try {
		List<StackFrame> frames = threadRef.frames();
		for (StackFrame stackFrame : frames) {
			for (String test : tests) {
				String[] splitted = test.split("#");
				test = splitted[0];
				ObjectReference thisObject = stackFrame.thisObject();
				if (thisObject == null) {
					continue;
				}
				String frameClass = thisObject.referenceType().name();
				if (frameClass.equals(test)) {
					String frameMethod = stackFrame.location().method().name();
					if (oracle.containsKey(test + "#" + frameMethod)) {
						if (frameClass.equals(currentTestClass) && frameMethod.equals(currentTestMethod)) {
							this.currentIteration++;
						} else {
							currentTestClass = test;
							currentTestMethod = frameMethod;
							this.currentIteration = 0;
						}
						// logger.info("[test] " + currentTestClass + "#" + currentTestMethod + "
						// iteration "
						// + this.currentIteration);
						return;
					}
				}
			}
		}
	} catch (IncompatibleThreadStateException e) {
		e.printStackTrace();
	}
	throw new RuntimeException("Unable to identify the current test");
}
 
Example #17
Source File: InvokableTypeImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #18
Source File: ExceptionInfoRequestHandler.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response,
        IDebugAdapterContext context) {
    ExceptionInfoArguments exceptionInfoArgs = (ExceptionInfoArguments) arguments;
    ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), exceptionInfoArgs.threadId);
    if (thread == null) {
        throw AdapterUtils.createCompletionException("Thread " + exceptionInfoArgs.threadId + " doesn't exist.", ErrorCode.EXCEPTION_INFO_FAILURE);
    }

    JdiExceptionReference jdiException = context.getExceptionManager().getException(exceptionInfoArgs.threadId);
    if (jdiException == null) {
        throw AdapterUtils.createCompletionException("No exception exists in thread " + exceptionInfoArgs.threadId, ErrorCode.EXCEPTION_INFO_FAILURE);
    }

    Method toStringMethod = null;
    for (Method method : jdiException.exception.referenceType().allMethods()) {
        if (Objects.equals("toString", method.name()) && Objects.equals("()Ljava/lang/String;", method.signature())) {
            toStringMethod = method;
            break;
        }
    }

    String typeName = jdiException.exception.type().name();
    String exceptionToString = typeName;
    if (toStringMethod != null) {
        try {
            Value returnValue = jdiException.exception.invokeMethod(thread, toStringMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
            exceptionToString = returnValue.toString();
        } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException
                | InvocationException e) {
            logger.log(Level.SEVERE, String.format("Failed to get the return value of the method Exception.toString(): %s", e.toString(), e));
        }
    }

    response.body = new Responses.ExceptionInfoResponse(typeName, exceptionToString,
            jdiException.isUncaught ? ExceptionBreakMode.USERUNHANDLED : ExceptionBreakMode.ALWAYS);
    return CompletableFuture.completedFuture(response);
}
 
Example #19
Source File: ThreadInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #20
Source File: StackTraceRequestHandler.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
    StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments;
    List<Types.StackFrame> result = new ArrayList<>();
    if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) {
        response.body = new Responses.StackTraceResponseBody(result, 0);
        return CompletableFuture.completedFuture(response);
    }
    ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId);
    int totalFrames = 0;
    if (thread != null) {
        try {
            totalFrames = thread.frameCount();
            if (totalFrames <= stacktraceArgs.startFrame) {
                response.body = new Responses.StackTraceResponseBody(result, totalFrames);
                return CompletableFuture.completedFuture(response);
            }
            StackFrame[] frames = context.getStackFrameManager().reloadStackFrames(thread);

            int count = stacktraceArgs.levels == 0 ? totalFrames - stacktraceArgs.startFrame
                    : Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels);
            for (int i = stacktraceArgs.startFrame; i < frames.length && count-- > 0; i++) {
                StackFrameReference stackframe = new StackFrameReference(thread, i);
                int frameId = context.getRecyclableIdPool().addObject(thread.uniqueID(), stackframe);
                result.add(convertDebuggerStackFrameToClient(frames[i], frameId, context));
            }
        } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException
                | AbsentInformationException | ObjectCollectedException e) {
            // when error happens, the possible reason is:
            // 1. the vscode has wrong parameter/wrong uri
            // 2. the thread actually terminates
            // TODO: should record a error log here.
        }
    }
    response.body = new Responses.StackTraceResponseBody(result, totalFrames);
    return CompletableFuture.completedFuture(response);
}
 
Example #21
Source File: AbstractJdiTestCase.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
protected StackFrame getStackFrame() {
    if (this.staticBreakpointEvent == null || !this.staticBreakpointEvent.thread().isAtBreakpoint()) {
        return null;
    }
    try {
        return this.staticBreakpointEvent.thread().frame(0);

    } catch (IncompatibleThreadStateException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #22
Source File: VMTargetRemoteTest.java    From gravel with Apache License 2.0 5 votes vote down vote up
private void printStack(ThreadReference thread)
		throws IncompatibleThreadStateException {
	List<StackFrame> frames = thread.frames();
	for (StackFrame stackFrame : frames) {
		System.out.println("-Stack: "+ stackFrame+" location:  "+stackFrame.location().method());
		
	}
}
 
Example #23
Source File: InvokableTypeImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #24
Source File: CallStackTreeModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 *
 * @return threads contained in this group of threads
 */
public Object[] getChildren (Object parent, int from, int to) 
throws UnknownTypeException {
    if ( parent.equals (ROOT) ||
         (parent instanceof JPDAThread) 
    ) {
        // 1) get Thread
        JPDAThread thread;
        if (parent.equals (ROOT)) {
            thread = debugger.getCurrentThread ();
        } else {
            thread = (JPDAThread) parent;
        }
        if (thread == null) {
            return new String[] {"No current thread"}; // TODO make localizable!!!
        }
        
        // 2) get StackFrames for this Thread
        try {
            CallStackFrame[] sfs = thread.getCallStack(from, to);
            return sfs;
        } catch (AbsentInformationException aiex) {
            if (aiex.getCause() instanceof IncompatibleThreadStateException) {
                return new String[] {"Thread is running"}; // TODO make localizable!!!
            } else {
                return new String[] {"No call stack information available."}; // TODO make localizable!!!
            }
        }
    } else
    throw new UnknownTypeException (parent);
}
 
Example #25
Source File: VariableMirrorTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ObjectReference getDeclaredOrInheritedField(ClassType clazz, String name, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException {
    //try {
    //    java.lang.reflect.Field field = clazz.getDeclaredField(name);
    //    return field;
    //} catch (NoSuchFieldException ex) {}
    ClassType classType = (ClassType) getOrLoadClass(vm, "java.lang.Class");
    com.sun.jdi.Method getDeclaredFieldMethod = ClassTypeWrapper.concreteMethodByName(
            classType, "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
    try {
        ObjectReference fieldRef = (ObjectReference)
            ObjectReferenceWrapper.invokeMethod(ReferenceTypeWrapper.classObject(clazz),
                                                thread,
                                                getDeclaredFieldMethod,
                                                Collections.singletonList(vm.mirrorOf(name)),
                                                ClassType.INVOKE_SINGLE_THREADED);
        return fieldRef;
    } catch (InvocationException ex) {
        // Likely NoSuchFieldException, try the super class...
    }
    //Class superClass = clazz.getSuperclass();
    ClassType superClass = ClassTypeWrapper.superclass(clazz);
    if (superClass != null) {
        return getDeclaredOrInheritedField(superClass, name, vm, thread);
    } else {
        return null;
    }
}
 
Example #26
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void resumeMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    if (!pausedPlayers.isEmpty()) {
        final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer");
        List<Method> play = mediaPlayerClass.methodsByName("play", "()V");
        if (play.isEmpty()) {
            return;
        }
        Method p = play.iterator().next();
        for(ObjectReference pR : pausedPlayers) {
            pR.invokeMethod(tr, p, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        }
    }
}
 
Example #27
Source File: InvokableTypeImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method invocation support.
 * Shared by ClassType and InterfaceType
 * @param threadIntf the thread in which to invoke.
 * @param methodIntf method the {@link Method} to invoke.
 * @param origArguments the list of {@link Value} arguments bound to the
 * invoked method. Values from the list are assigned to arguments
 * in the order they appear in the method signature.
 * @param options the integer bit flag options.
 * @return a {@link Value} mirror of the invoked method's return value.
 * @throws java.lang.IllegalArgumentException if the method is not
 * a member of this type, if the size of the argument list
 * does not match the number of declared arguments for the method, or
 * if the method is not static or is a static initializer.
 * @throws {@link InvalidTypeException} if any argument in the
 * argument list is not assignable to the corresponding method argument
 * type.
 * @throws ClassNotLoadedException if any argument type has not yet been loaded
 * through the appropriate class loader.
 * @throws IncompatibleThreadStateException if the specified thread has not
 * been suspended by an event.
 * @throws InvocationException if the method invocation resulted in
 * an exception in the target VM.
 * @throws InvalidTypeException If the arguments do not meet this requirement --
 *         Object arguments must be assignment compatible with the argument
 *         type.  This implies that the argument type must be
 *         loaded through the enclosing class's class loader.
 *         Primitive arguments must be either assignment compatible with the
 *         argument type or must be convertible to the argument type without loss
 *         of information. See JLS section 5.2 for more information on assignment
 *         compatibility.
 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
 */
final public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                                List<? extends Value> origArguments, int options)
                                    throws InvalidTypeException,
                                           ClassNotLoadedException,
                                           IncompatibleThreadStateException,
                                           InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
     * There is an implict VM-wide suspend at the conclusion
     * of a normal (non-single-threaded) method invoke
     */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
 
Example #28
Source File: DebugExecutionEnvironment.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean sendStopUserCode() throws IllegalStateException {
    if (closed) {
        return false;
    }
    vm.suspend();
    try {
        ObjectReference myRef = getAgentObjectReference();

        OUTER:
        for (ThreadReference thread : vm.allThreads()) {
            // could also tag the thread (e.g. using name), to find it easier
            AGENT: for (StackFrame frame : thread.frames()) {
                if (REMOTE_AGENT_CLASS.equals(frame.location().declaringType().name())) {
                    String n = frame.location().method().name();
                    if (AGENT_INVOKE_METHOD.equals(n) || AGENT_VARVALUE_METHOD.equals(n)) {
                        ObjectReference thiz = frame.thisObject();
                        if (myRef != null && myRef != thiz) {
                            break AGENT;
                        }
                        if (((BooleanValue) thiz.getValue(thiz.referenceType().fieldByName("inClientCode"))).value()) {
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(thiz.referenceType().fieldByName("stopException"));
                            vm.resume();
                            thread.stop(stopInstance);
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(false));
                        }
                        return true;
                    }
                }
            }
        }
    } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
        throw new IllegalStateException(ex);
    } finally {
        vm.resume();
    }
    return false;
}
 
Example #29
Source File: JDIExampleDebugger.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Displays the visible variables
 * @param event
 * @throws IncompatibleThreadStateException
 * @throws AbsentInformationException
 */
public void displayVariables(LocatableEvent event) throws IncompatibleThreadStateException, AbsentInformationException {
    StackFrame stackFrame = event.thread().frame(0);
    if(stackFrame.location().toString().contains(debugClass.getName())) {
        Map<LocalVariable, Value> visibleVariables = stackFrame.getValues(stackFrame.visibleVariables());
        System.out.println("Variables at " +stackFrame.location().toString() +  " > ");
        for (Map.Entry<LocalVariable, Value> entry : visibleVariables.entrySet()) {
            System.out.println(entry.getKey().name() + " = " + entry.getValue());
        }
    }
}
 
Example #30
Source File: RemoteServices.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ObjectReference getTruffleClassLoader(ThreadReference tawt, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException, IOException, PropertyVetoException, InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, UnsupportedOperationExceptionWrapper, ClassNotPreparedExceptionWrapper {
    /* Use:
       com.oracle.truffle.api.impl.TruffleLocator.class.getClassLoader()
    */
    ClassType truffleLocatorClass = getClass(vm, "com.oracle.truffle.api.impl.TruffleLocator");
    return truffleLocatorClass.classLoader();
}