Java 类com.sun.jdi.IncompatibleThreadStateException 实例源码

项目:incubator-netbeans    文件:JPDADebuggerImpl.java   
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);
    }
}
项目:incubator-netbeans    文件:JPDAThreadImpl.java   
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);
    }
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
/**
 * Auto-boxes or un-boxes arguments of a method.
 */
static void autoboxArguments(List<Type> types, List<Value> argVals,
                             ThreadReference evaluationThread,
                             EvaluationContext evaluationContext) throws InvalidTypeException,
                                                                         ClassNotLoadedException,
                                                                         IncompatibleThreadStateException,
                                                                         InvocationException {
    if (types.size() != argVals.size()) {
        return ;
    }
    int n = types.size();
    for (int i = 0; i < n; i++) {
        Type t = types.get(i);
        Value v = argVals.get(i);
        if (v instanceof ObjectReference && t instanceof PrimitiveType) {
            argVals.set(i, unbox((ObjectReference) v, (PrimitiveType) t, evaluationThread, evaluationContext));
        }
        if (v instanceof PrimitiveValue && t instanceof ReferenceType) {
            argVals.set(i, box((PrimitiveValue) v, (ReferenceType) t, evaluationThread, evaluationContext));
        }
    }
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public boolean isAtBreakpoint() {
    /*
     * TO DO: This fails to take filters into account.
     */
    try {
        StackFrame frame = frame(0);
        Location location = frame.location();
        List<BreakpointRequest> requests = vm.eventRequestManager().breakpointRequests();
        Iterator<BreakpointRequest> iter = requests.iterator();
        while (iter.hasNext()) {
            BreakpointRequest request = iter.next();
            if (location.equals(request.location())) {
                return true;
            }
        }
        return false;
    } catch (IndexOutOfBoundsException iobe) {
        return false;  // no frames on stack => not at breakpoint
    } catch (IncompatibleThreadStateException itse) {
        // Per the javadoc, not suspended => return false
        return false;
    }
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public int frameCount() throws IncompatibleThreadStateException  {
    LocalCache snapshot = localCache;
    try {
        if (snapshot.frameCount == -1) {
            snapshot.frameCount = JDWP.ThreadReference.FrameCount
                                      .process(vm, this).frameCount;
        }
    } catch (JDWPException exc) {
        switch (exc.errorCode()) {
        case JDWP.Error.THREAD_NOT_SUSPENDED:
        case JDWP.Error.INVALID_THREAD:   /* zombie */
            throw new IncompatibleThreadStateException();
        default:
            throw exc.toJDIException();
        }
    }
    return snapshot.frameCount;
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public List<ObjectReference> ownedMonitors()  throws IncompatibleThreadStateException  {
    LocalCache snapshot = localCache;
    try {
        if (snapshot.ownedMonitors == null) {
            snapshot.ownedMonitors = Arrays.asList(
                             (ObjectReference[])JDWP.ThreadReference.OwnedMonitors.
                                     process(vm, this).owned);
            if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
                vm.printTrace(description() +
                              " temporarily caching owned monitors"+
                              " (count = " + snapshot.ownedMonitors.size() + ")");
            }
        }
    } catch (JDWPException exc) {
        switch (exc.errorCode()) {
        case JDWP.Error.THREAD_NOT_SUSPENDED:
        case JDWP.Error.INVALID_THREAD:   /* zombie */
            throw new IncompatibleThreadStateException();
        default:
            throw exc.toJDIException();
        }
    }
    return snapshot.ownedMonitors;
}
项目:java-debug    文件:StepRequestHandler.java   
/**
 * Check if the current top stack is same as the original top stack.
 *
 * @throws IncompatibleThreadStateException
 *                      if the thread is not suspended in the target VM.
 */
private boolean shouldDoExtraStepInto(int originalStackDepth, Location originalLocation, int currentStackDepth, Location currentLocation)
        throws IncompatibleThreadStateException {
    if (originalStackDepth != currentStackDepth) {
        return false;
    }
    if (originalLocation == null) {
        return false;
    }
    Method originalMethod = originalLocation.method();
    Method currentMethod = currentLocation.method();
    if (!originalMethod.equals(currentMethod)) {
        return false;
    }
    if (originalLocation.lineNumber() != currentLocation.lineNumber()) {
        return false;
    }
    return true;
}
项目:form-follows-function    文件:F3ThreadReference.java   
private List<StackFrame> getFilteredFrames() throws IncompatibleThreadStateException {
    List<StackFrame> frames = F3Wrapper.wrapFrames(virtualMachine(), underlying().frames());
    List<StackFrame> filteredFrames = new ArrayList<StackFrame>(frames.size());
    try {
        for (StackFrame fr : frames) {
            F3StackFrame f3fr = (F3StackFrame) fr;
            // don't add F3 synthetic frames
            if (f3fr.location().method().isF3InternalMethod()) {
                continue;
            } else {
                filteredFrames.add(f3fr);
            }
        }
    } catch (InvalidStackFrameException exp) {
        throw new IncompatibleThreadStateException(exp.getMessage());
    }
    return filteredFrames;
}
项目:form-follows-function    文件:Debugger.java   
/**
 * Evaluate "jdb"-style expressions. The expression syntax is same as what
 * you'd use with jdb's "print" or "set" command. The expression is evaluated
 * in current thread's current frame context. You can access locals from that 
 * frame and also evaluate object fields/static fields etc. from there. For 
 * example, if "seq" is a local variable of type F3 integer sequence, 
 * 
 *     Debugger dbg = ...
 *     dbg.evaluate("seq[0]");
 *
 * and that will return JDI IntegerValue type object in this case.
 */
public Value evaluate(String expr) {
    Value result = null;
    ExpressionParser.GetFrame frameGetter = null;
    try {
        final ThreadInfo threadInfo = env.getCurrentThreadInfo();
        if (threadInfo != null && threadInfo.getCurrentFrame() != null) {
            frameGetter = new ExpressionParser.GetFrame() {
                public StackFrame get() throws IncompatibleThreadStateException {
                    return threadInfo.getCurrentFrame();
                }
            };
        }
        result = ExpressionParser.evaluate(expr, env.vm(), frameGetter);
    } catch (RuntimeException rexp) {
        throw rexp;
    } catch (Exception exp) {
        throw new RuntimeException(exp);
    }
    return result;
}
项目:jive    文件:JDIEventHandlerDelegate.java   
/**
 * Returns whether the given thread contains any in-model frames (i.e., whether there is a frame
 * on the stack with a corresponding contour) between the top frame and the frame matching the
 * supplied location.
 */
private boolean containsInModelFrames(final ThreadReference thread, final Location catchLocation)
    throws IncompatibleThreadStateException
{
  final List<StackFrame> stack = thread.frames();
  for (final StackFrame frame : stack)
  {
    final ReferenceType type = frame.location().declaringType();
    if (eventFilter().acceptsType(type))
    {
      return true;
    }
    if (catchLocation != null && frame.location().method().equals(catchLocation.method()))
    {
      return false;
    }
  }
  return false;
}
项目:jive    文件:JDIEventHandlerDelegate.java   
/**
 * Filtered method calls/returns are captured lazily by determineStackFrame(event).
 */
void handleMethodEntry(final MethodEntryEvent event, final boolean generateLocals)
    throws IncompatibleThreadStateException, AbsentInformationException
{
  if (!eventFilter().acceptsMethod(event.method(), event.thread()))
  {
    return;
  }
  // adjust the stack frames if necessary
  final StackFrame frame = determineStackFrame(event);
  // handle a pending returned event if necessary
  handlePendingReturned(event.location(), frame, event.thread());
  // record newly observed types and objects if necessary
  handleNewObject(frame, event.thread());
  // resolve the method
  resolveMethod(frame, event.method());
  // record the method call
  dispatcher().dispatchInModelCallEvent(event, frame);
  // handle locals if necessary
  if (generateLocals)
  {
    handleLocals(null, frame, event.location());
  }
}
项目:jive    文件:ModelFilter.java   
/**
 * Step events are filtered according to accepted types and methods.
 */
@Override
public boolean acceptsStep(final StepEvent event)
{
  if (!acceptsLocation(event.location()))
  {
    return false;
  }
  ObjectReference oref;
  try
  {
    oref = event.thread().frame(0).thisObject();
  }
  catch (final IncompatibleThreadStateException e)
  {
    oref = null;
  }
  // step's context type
  if (oref != null && !acceptsType(oref.referenceType()))
  {
    return false;
  }
  return true;
}
项目:JavaTracer    文件:ExceptionManager.java   
private Data processThis(ExceptionEvent event, ReferenceType ref,
        ThreadReference thread) {

    StackFrame stack = null;

    try {
        stack = thread.frame(0);
    } catch (IncompatibleThreadStateException e) {
        e.printStackTrace();
    }

    Data valueThis = utils.getObj("this", stack.thisObject(),
            new ArrayList<Long>());

    return valueThis;
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static void pauseMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    final ClassType audioClipClass = getClass(vm, tr, "com.sun.media.jfxmedia.AudioClip");
    final ClassType mediaManagerClass = getClass(vm, tr, "com.sun.media.jfxmedia.MediaManager");
    final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer");
    final ClassType playerStateEnum = getClass(vm, tr, "com.sun.media.jfxmedia.events.PlayerStateEvent$PlayerState");

    if (audioClipClass != null) {
        Method stopAllClips = audioClipClass.concreteMethodByName("stopAllClips", "()V");
        audioClipClass.invokeMethod(tr, stopAllClips, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
    }

    if (mediaManagerClass != null && mediaPlayerClass != null && playerStateEnum != null) {
        Method getAllPlayers = mediaManagerClass.concreteMethodByName("getAllMediaPlayers", "()Ljava/util/List;");

        ObjectReference plList = (ObjectReference)mediaManagerClass.invokeMethod(tr, getAllPlayers, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);

        if (plList != null) {
            ClassType listType = (ClassType)plList.referenceType();
            Method iterator = listType.concreteMethodByName("iterator", "()Ljava/util/Iterator;");
            ObjectReference plIter = (ObjectReference)plList.invokeMethod(tr, iterator, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);

            ClassType iterType = (ClassType)plIter.referenceType();
            Method hasNext = iterType.concreteMethodByName("hasNext", "()Z");
            Method next = iterType.concreteMethodByName("next", "()Ljava/lang/Object;");


            Field playingState = playerStateEnum.fieldByName("PLAYING");

            Method getState = mediaPlayerClass.methodsByName("getState", "()Lcom/sun/media/jfxmedia/events/PlayerStateEvent$PlayerState;").get(0);
            Method pausePlayer = mediaPlayerClass.methodsByName("pause", "()V").get(0);
            boolean hasNextFlag = false;
            do {
                BooleanValue v = (BooleanValue)plIter.invokeMethod(tr, hasNext, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                hasNextFlag = v.booleanValue();
                if (hasNextFlag) {
                    ObjectReference player = (ObjectReference)plIter.invokeMethod(tr, next, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                    ObjectReference curState = (ObjectReference)player.invokeMethod(tr, getState, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                    if (playingState.equals(curState)) {
                        player.invokeMethod(tr, pausePlayer, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                        pausedPlayers.add(player);
                    }
                }
            } while (hasNextFlag);
        }
    }
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
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.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
        }
    }
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static ReferenceType getType(VirtualMachine vm, ThreadReference tr, String name) {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName0(vm, name);
    if (!classList.isEmpty()) {
        return classList.iterator().next();
    }
    List<ReferenceType> classClassList = VirtualMachineWrapper.classesByName0(vm, "java.lang.Class"); // NOI18N
    if (classClassList.isEmpty()) {
        throw new IllegalStateException("Cannot load class Class"); // NOI18N
    }

    ClassType cls = (ClassType) classClassList.iterator().next();
    try {
        Method m = ClassTypeWrapper.concreteMethodByName(cls, "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); // NOI18N
        StringReference mirrorOfName = VirtualMachineWrapper.mirrorOf(vm, name);
        ClassTypeWrapper.invokeMethod(cls, tr, m, Collections.singletonList(mirrorOfName), ObjectReference.INVOKE_SINGLE_THREADED);
        List<ReferenceType> classList2 = VirtualMachineWrapper.classesByName0(vm, name);
        if (!classList2.isEmpty()) {
            return classList2.iterator().next();
        }
    } catch (ClassNotLoadedException | ClassNotPreparedExceptionWrapper |
             IncompatibleThreadStateException | InvalidTypeException |
             InvocationException | InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper | UnsupportedOperationExceptionWrapper |
             VMDisconnectedExceptionWrapper ex) {
        logger.log(Level.FINE, "Cannot load class " + name, ex); // NOI18N
    }

    return null;
}
项目:incubator-netbeans    文件:DebugExecutionEnvironment.java   
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;
}
项目:incubator-netbeans    文件:VariableMirrorTranslator.java   
private static void setValueToFinalField(ObjectReference obj, String name, ClassType clazz, Value fv, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException, InvalidObjectException {
    ObjectReference fieldRef = getDeclaredOrInheritedField(clazz, name, vm, thread);
    if (fieldRef == null) {
        InvalidObjectException ioex = new InvalidObjectException("No field "+name+" of class "+clazz);
        throw ioex;
    }
    // field.setAccessible(true);
    ClassType fieldClassType = (ClassType) ValueWrapper.type(fieldRef);
    com.sun.jdi.Method setAccessibleMethod = ClassTypeWrapper.concreteMethodByName(
            fieldClassType, "setAccessible", "(Z)V");
    try {
        ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setAccessibleMethod,
                                            Collections.singletonList(vm.mirrorOf(true)),
                                            ClassType.INVOKE_SINGLE_THREADED);
        // field.set(newInstance, fv);
        com.sun.jdi.Method setMethod = ClassTypeWrapper.concreteMethodByName(
                fieldClassType, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V");
        if (fv instanceof PrimitiveValue) {
            PrimitiveType pt = (PrimitiveType) ValueWrapper.type(fv);
            ReferenceType fieldBoxingClass = EvaluatorVisitor.adjustBoxingType(clazz, pt, null);
            fv = EvaluatorVisitor.box((PrimitiveValue) fv, fieldBoxingClass, thread, null);
        }
        List<Value> args = Arrays.asList(new Value[] { obj, fv });
        ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setMethod,
                                            args,
                                            ClassType.INVOKE_SINGLE_THREADED);
    } catch (InvocationException iex) {
        throw new InvalidObjectException(
                "Problem setting value "+fv+" to field "+name+" of class "+clazz+
                " : "+iex.exception());
    }
}
项目:incubator-netbeans    文件:VariableMirrorTranslator.java   
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;
    }
}
项目:OpenJSharp    文件:ThreadInfo.java   
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
项目:OpenJSharp    文件:InvokableTypeImpl.java   
/**
 * 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();
    }
}
项目:jdk8u-jdk    文件:InvokableTypeImpl.java   
/**
 * 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();
    }
}
项目:openjdk-jdk10    文件:ThreadInfo.java   
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public List<StackFrame> frames(int start, int length)
                          throws IncompatibleThreadStateException  {
    if (length < 0) {
        throw new IndexOutOfBoundsException(
            "length must be greater than or equal to zero");
    }
    return privateFrames(start, length);
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public ObjectReference currentContendedMonitor()
                          throws IncompatibleThreadStateException  {
    LocalCache snapshot = localCache;
    try {
        if (snapshot.contendedMonitor == null &&
            !snapshot.triedCurrentContended) {
            snapshot.contendedMonitor = JDWP.ThreadReference.CurrentContendedMonitor.
                process(vm, this).monitor;
            snapshot.triedCurrentContended = true;
            if ((snapshot.contendedMonitor != null) &&
                ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0)) {
                vm.printTrace(description() +
                              " temporarily caching contended monitor"+
                              " (id = " + snapshot.contendedMonitor.uniqueID() + ")");
            }
        }
    } catch (JDWPException exc) {
        switch (exc.errorCode()) {
        case JDWP.Error.THREAD_NOT_SUSPENDED:
        case JDWP.Error.INVALID_THREAD:   /* zombie */
            throw new IncompatibleThreadStateException();
        default:
            throw exc.toJDIException();
        }
    }
    return snapshot.contendedMonitor;
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public List<MonitorInfo> ownedMonitorsAndFrames()  throws IncompatibleThreadStateException  {
    LocalCache snapshot = localCache;
    try {
        if (snapshot.ownedMonitorsInfo == null) {
            JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.monitor[] minfo;
            minfo = JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.process(vm, this).owned;

            snapshot.ownedMonitorsInfo = new ArrayList<>(minfo.length);

            for (int i=0; i < minfo.length; i++) {
                MonitorInfo mon = new MonitorInfoImpl(vm, minfo[i].monitor, this, minfo[i].stack_depth);
                snapshot.ownedMonitorsInfo.add(mon);
            }

            if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
                vm.printTrace(description() +
                              " temporarily caching owned monitors"+
                              " (count = " + snapshot.ownedMonitorsInfo.size() + ")");
                }
            }

    } catch (JDWPException exc) {
        switch (exc.errorCode()) {
        case JDWP.Error.THREAD_NOT_SUSPENDED:
        case JDWP.Error.INVALID_THREAD:   /* zombie */
            throw new IncompatibleThreadStateException();
        default:
            throw exc.toJDIException();
        }
    }
    return snapshot.ownedMonitorsInfo;
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
public void popFrames(StackFrame frame) throws IncompatibleThreadStateException {
    // Note that interface-wise this functionality belongs
    // here in ThreadReference, but implementation-wise it
    // belongs in StackFrame, so we just forward it.
    if (!frame.thread().equals(this)) {
        throw new IllegalArgumentException("frame does not belong to this thread");
    }
    if (!vm.canPopFrames()) {
        throw new UnsupportedOperationException(
            "target does not support popping frames");
    }
    ((StackFrameImpl)frame).pop();
}
项目:openjdk-jdk10    文件:InvokableTypeImpl.java   
/**
 * 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 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();
    }
}
项目:openjdk-jdk10    文件:StackFrameImpl.java   
void pop() throws IncompatibleThreadStateException {
    validateStackFrame();
    // flush caches and disable caching until command completion
    CommandSender sender =
        new CommandSender() {
            public PacketStream send() {
                return JDWP.StackFrame.PopFrames.enqueueCommand(vm,
                             thread, id);
            }
    };
    try {
        PacketStream stream = thread.sendResumingCommand(sender);
        JDWP.StackFrame.PopFrames.waitForReply(vm, stream);
    } catch (JDWPException exc) {
        switch (exc.errorCode()) {
        case JDWP.Error.THREAD_NOT_SUSPENDED:
            throw new IncompatibleThreadStateException(
                     "Thread not current or suspended");
        case JDWP.Error.INVALID_THREAD:   /* zombie */
            throw new IncompatibleThreadStateException("zombie");
        case JDWP.Error.NO_MORE_FRAMES:
            throw new InvalidStackFrameException(
                     "No more frames on the stack");
        default:
            throw exc.toJDIException();
        }
    }

    // enable caching - suspended again
    vm.state().freeze();
}
项目:java-debug    文件:StackFrameManager.java   
@Override
public StackFrame[] reloadStackFrames(ThreadReference thread) {
    return threadStackFrameMap.compute(thread.uniqueID(), (key, old) -> {
        try {
            return thread.frames().toArray(new StackFrame[0]);
        } catch (IncompatibleThreadStateException e) {
            return new StackFrame[0];
        }
    });
}
项目:java-debug    文件:StepRequestHandler.java   
/**
 * Return true if the StepEvent's location is a Method that the user has indicated to filter.
 *
 * @throws IncompatibleThreadStateException
 *                      if the thread is not suspended in the target VM.
 */
private boolean shouldFilterLocation(Location originalLocation, Location currentLocation, IDebugAdapterContext context)
        throws IncompatibleThreadStateException {
    if (originalLocation == null || currentLocation == null) {
        return false;
    }
    return !shouldFilterMethod(originalLocation.method(), context) && shouldFilterMethod(currentLocation.method(), context);
}
项目:java-debug    文件:StackTraceRequestHandler.java   
@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);
}
项目:java-debug    文件:StackFrameUtility.java   
/**
 * Pop a StackFrame from its thread.
 *
 * @param frame
 *            the StackFrame will be popped
 */
public static void pop(StackFrame frame) throws DebugException {
    try {
        frame.thread().popFrames(frame);
    } catch (IncompatibleThreadStateException | InvalidStackFrameException e) {
        throw new DebugException(e.getMessage(), e);
    }
}
项目:java-debug    文件:AbstractJdiTestCase.java   
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;
    }
}
项目:java-debug    文件:AbstractJdiTestCase.java   
protected StackFrame getSecondLevelStackFrame() {
    if (this.staticBreakpointEvent == null || !this.staticBreakpointEvent.thread().isAtBreakpoint()) {
        return null;
    }
    try {
        return this.staticBreakpointEvent.thread().frame(1);

    } catch (IncompatibleThreadStateException e) {
        e.printStackTrace();
        return null;
    }
}
项目:java-debug    文件:JavaHotCodeReplaceProvider.java   
private List<StackFrame> getStackFrames(ThreadReference thread, boolean refresh) {
    return threadFrameMap.compute(thread, (key, oldValue) -> {
        try {
            return oldValue == null || refresh ? key.frames() : oldValue;
        } catch (IncompatibleThreadStateException e) {
            logger.log(Level.SEVERE, "Failed to get stack frames: " + e.getMessage(), e);
            return oldValue;
        }
    });
}
项目:openjdk9    文件:ClassTypeImpl.java   
public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
                          List arguments, int options)
                               throws InvalidTypeException,
                                      ClassNotLoadedException,
                                      IncompatibleThreadStateException,
                                      InvocationException {
    vm.throwNotReadOnlyException("ClassType.invokeMethod(...)");
    return null;
}
项目:openjdk9    文件:ClassTypeImpl.java   
public ObjectReference newInstance(ThreadReference threadIntf,
                                   Method methodIntf,
                                   List arguments, int options)
                               throws InvalidTypeException,
                                      ClassNotLoadedException,
                                      IncompatibleThreadStateException,
                                      InvocationException {
    vm.throwNotReadOnlyException("ClassType.newInstance(...)");
    return null;
}
项目:openjdk9    文件:ThreadInfo.java   
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
项目:openjdk9    文件:InvokableTypeImpl.java   
/**
 * 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();
    }
}