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

项目:incubator-netbeans    文件:AWTGrabHandler.java   
private boolean ungrabWindowAWT(ThreadReference tr, ObjectReference grabbedWindow) {
    // Call XBaseWindow.ungrabInput()
    try {
        VirtualMachine vm = MirrorWrapper.virtualMachine(grabbedWindow);
        List<ReferenceType> xbaseWindowClassesByName = VirtualMachineWrapper.classesByName(vm, "sun.awt.X11.XBaseWindow");
        if (xbaseWindowClassesByName.isEmpty()) {
            logger.info("Unable to release X grab, no XBaseWindow class in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        ClassType XBaseWindowClass = (ClassType) xbaseWindowClassesByName.get(0);
        Method ungrabInput = XBaseWindowClass.concreteMethodByName("ungrabInput", "()V");
        if (ungrabInput == null) {
            logger.info("Unable to release X grab, method ungrabInput not found in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        XBaseWindowClass.invokeMethod(tr, ungrabInput, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
    } catch (VMDisconnectedExceptionWrapper vmdex) {
        return true; // Disconnected, all is good.
    } catch (Exception ex) {
        logger.log(Level.INFO, "Unable to release X grab.", ex);
        return false;
    }
    return true;
}
项目:openjdk-jdk10    文件:ThreadInfo.java   
static void removeThread(ThreadReference thread) {
    if (thread.equals(ThreadInfo.current)) {
        // Current thread has died.

        // Be careful getting the thread name. If its death happens
        // as part of VM termination, it may be too late to get the
        // information, and an exception will be thrown.
        String currentThreadName;
        try {
           currentThreadName = "\"" + thread.name() + "\"";
        } catch (Exception e) {
           currentThreadName = "";
        }

        setCurrentThread(null);

        MessageOutput.println();
        MessageOutput.println("Current thread died. Execution continuing...",
                              currentThreadName);
    }
    threads.remove(getThreadInfo(thread));
}
项目:java-debug    文件:ThreadsRequestHandler.java   
private CompletableFuture<Response> resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) {
    boolean allThreadsContinued = true;
    ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
    /**
     * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(),
     * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must
     * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended.
     */
    if (thread != null) {
        allThreadsContinued = false;
        DebugUtility.resumeThread(thread);
        checkThreadRunningAndRecycleIds(thread, context);
    } else {
        context.getDebugSession().resume();
        context.getRecyclableIdPool().removeAllObjects();
    }
    response.body = new Responses.ContinueResponseBody(allThreadsContinued);
    return CompletableFuture.completedFuture(response);
}
项目:incubator-netbeans    文件:JPDADebuggerImpl.java   
public void notifyToBeResumedAllNoFire(Set<ThreadReference> ignoredThreads) {
    Collection threads = threadsTranslation.getTranslated();
    for (Iterator it = threads.iterator(); it.hasNext(); ) {
        Object threadOrGroup = it.next();
        if (threadOrGroup instanceof JPDAThreadImpl &&
                (ignoredThreads == null || !ignoredThreads.contains(threadOrGroup))) {
            int status = ((JPDAThreadImpl) threadOrGroup).getState();
            boolean invalid = (status == JPDAThread.STATE_NOT_STARTED ||
                               status == JPDAThread.STATE_UNKNOWN ||
                               status == JPDAThread.STATE_ZOMBIE);
            if (!invalid) {
                ((JPDAThreadImpl) threadOrGroup).notifyToBeResumedNoFire();
            } else if (status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE) {
                threadsTranslation.remove(((JPDAThreadImpl) threadOrGroup).getThreadReference());
            }
        }
    }
}
项目:incubator-netbeans    文件:JPDADebuggerImpl.java   
public ThreadsCache getThreadsCache() {
    synchronized (threadsCollectorLock) {
        if (threadsCache == null) {
            threadsCache = new ThreadsCache(this);
            threadsCache.addPropertyChangeListener(new PropertyChangeListener() {
                //  Re-fire the changes
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if (ThreadsCache.PROP_THREAD_STARTED.equals(propertyName)) {
                        firePropertyChange(PROP_THREAD_STARTED, null, getThread((ThreadReference) evt.getNewValue()));
                    }
                    if (ThreadsCache.PROP_THREAD_DIED.equals(propertyName)) {
                        firePropertyChange(PROP_THREAD_DIED, getThread((ThreadReference) evt.getOldValue()), null);
                    }
                    if (ThreadsCache.PROP_GROUP_ADDED.equals(propertyName)) {
                        firePropertyChange(PROP_THREAD_GROUP_ADDED, null, getThreadGroup((ThreadGroupReference) evt.getNewValue()));
                    }
                }
            });
        }
        return threadsCache;
    }
}
项目:incubator-netbeans    文件:JPDADebuggerImpl.java   
@Override
public void run() {
    List<ThreadReference> allThreads = vm.allThreads();
    System.err.println("All Threads:");
    for (ThreadReference tr : allThreads) {
        String name = tr.name();
        boolean suspended = tr.isSuspended();
        int suspendCount = tr.suspendCount();
        int status = tr.status();
        System.err.println(name+"\t SUSP = "+suspended+", COUNT = "+suspendCount+", STATUS = "+status);
    }
    System.err.println("");
    if (!finish) {
        rp.post(this, INTERVAL);
    }
}
项目:incubator-netbeans    文件:ObjectTranslation.java   
/**
 * Creates a new translated node for given original one.
 *
 * @param o a node to be translated
 * @return a new translated node
 */
private Object createTranslation (Object o) {
    switch (translationID) {
        case THREAD_ID:
            if (o instanceof ThreadReference) {
                return new JPDAThreadImpl ((ThreadReference) o, debugger);
            } else if (o instanceof ThreadGroupReference) {
                return new JPDAThreadGroupImpl ((ThreadGroupReference) o, debugger);
            } else {
                return null;
            }
        case LOCALS_ID:
            if (o instanceof ArrayType) {
                return new JPDAArrayTypeImpl(debugger, (ArrayType) o);
            }
            if (o instanceof ReferenceType) {
                return new JPDAClassTypeImpl(debugger, (ReferenceType) o);
            }
        default:
            throw new IllegalStateException(""+o);
    }
}
项目:incubator-netbeans    文件:ThreadsCache.java   
private void initGroups(ThreadGroupReference group) {
    try {
        List<ThreadGroupReference> groups = new ArrayList(ThreadGroupReferenceWrapper.threadGroups0(group));
        List<ThreadReference> threads = new ArrayList(ThreadGroupReferenceWrapper.threads0(group));
        filterThreads(threads);
        groupMap.put(group, groups);
        threadMap.put(group, threads);
        for (ThreadGroupReference g : groups) {
            initGroups(g);
        }
    } catch (ObjectCollectedException e) {
    }
}
项目:openjdk-jdk10    文件:ThreadReferenceImpl.java   
private JDWP.ThreadReference.Status jdwpStatus() {
    LocalCache snapshot = localCache;
    JDWP.ThreadReference.Status myStatus = snapshot.status;
    try {
         if (myStatus == null) {
             myStatus = JDWP.ThreadReference.Status.process(vm, this);
            if ((myStatus.suspendStatus & SUSPEND_STATUS_SUSPENDED) != 0) {
                // thread is suspended, we can cache the status.
                snapshot.status = myStatus;
            }
        }
     } catch (JDWPException exc) {
        throw exc.toJDIException();
    }
    return myStatus;
}
项目:java-debug    文件:JavaHotCodeReplaceProvider.java   
private boolean containsObsoleteMethods() throws DebugException {
    List<ThreadReference> threads = currentDebugSession.getAllThreads();
    for (ThreadReference thread : threads) {
        if (!thread.isSuspended()) {
            continue;
        }
        List<StackFrame> frames = getStackFrames(thread, false);
        if (frames == null || frames.isEmpty()) {
            continue;
        }
        for (StackFrame frame : frames) {
            if (StackFrameUtility.isObsolete(frame)) {
                return true;
            }
        }
    }
    return false;
}
项目:incubator-netbeans    文件:Operator.java   
public void notifyMethodInvoking(ThreadReference tr) {
    if (logger.isLoggable(Level.FINE)) {
        try {
            logger.fine("  notifyMethodInvoking("+tr+") suspendCount = "+tr.suspendCount());
        } catch (Exception ex) {
            logger.fine("  notifyMethodInvoking("+tr+")");
        }
    }
    if (Thread.currentThread() == thread) {
        // start another event handler thread...
        startEventHandlerThreadFor(tr);
    }
    synchronized (methodInvokingThreads) {
        methodInvokingThreads.add(tr);
    }
    loopControl.setInMethodInvoke(true);
}
项目:incubator-netbeans    文件:Operator.java   
public void notifyMethodInvokeDone(ThreadReference tr) {
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("  notifyMethodInvokeDone("+tr+")");
    }
    if (Thread.currentThread() == thread) {
        HandlerTask task = eventHandlers.remove(tr);
        if (task != null) {
            task.cancel();
        }
    }
    boolean done;
    synchronized (methodInvokingThreads) {
        methodInvokingThreads.remove(tr);
        done = methodInvokingThreads.isEmpty();
    }
    if (done) {
        loopControl.setInMethodInvoke(false);
    }
}
项目:incubator-netbeans    文件:JPDAStepImpl.java   
private void stepDone(EventRequest er) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper {
    JPDAThreadImpl t;
    if (er instanceof StepRequest) {
        StepRequest sr = (StepRequest) er;
        t = ((JPDADebuggerImpl) debugger).getThread(StepRequestWrapper.thread(sr));
    } else {
        ThreadReference tr = (ThreadReference) EventRequestWrapper.getProperty(er, "thread"); // NOI18N
        if (tr != null) {
            t = ((JPDADebuggerImpl) debugger).getThread(tr);
        } else {
            t = null;
        }
    }
    if (t != null) {
        t.setInStep(false, null);
    }
}
项目:openjdk-jdk10    文件:EventSetImpl.java   
public void resume() {
    switch (suspendPolicy()) {
        case EventRequest.SUSPEND_ALL:
            vm.resume();
            break;
        case EventRequest.SUSPEND_EVENT_THREAD:
            ThreadReference thread = eventThread();
            if (thread == null) {
                throw new InternalException("Inconsistent suspend policy");
            }
            thread.resume();
            break;
        case EventRequest.SUSPEND_NONE:
            // Do nothing
            break;
        default:
            throw new InternalException("Invalid suspend policy");
    }
}
项目: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;
}
项目:incubator-netbeans    文件:ThreadsTreeModel.java   
private Object[] computeChildren(Object node) {
    if (node.equals (ROOT)) {

        if (verbose) {
            com.sun.jdi.VirtualMachine vm = debugger.getVirtualMachine();
            if (vm == null) {
                System.err.println("\nThreadsTreeModel.computeChildren():\nVM is null!\n");
            } else {
                try {
                    List<ThreadReference> threads = VirtualMachineWrapper.allThreads(vm);
                    System.err.println("\nThreadsTreeModel.computeChildren() ALL Threads:");
                    for (ThreadReference t : threads) {
                        System.err.println("  "+ThreadReferenceWrapper.name(t)+" is suspended: "+ThreadReferenceWrapper.isSuspended(t)+", suspend count = "+ThreadReferenceWrapper.suspendCount(t));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.err.println("");
            }
        }

        return debugger.getTopLevelThreadGroups();
    } else if (node instanceof JPDAThreadGroup) {
        JPDAThreadGroup tg = (JPDAThreadGroup) node;
        JPDAThreadGroup[] tgs = tg.getThreadGroups();
        JPDAThread[] ts = tg.getThreads();
        int n = tgs.length + ts.length;
        Object[] ch = new Object[n];
        System.arraycopy(tgs, 0, ch, 0, tgs.length);
        System.arraycopy(ts, 0, ch, tgs.length, ts.length);
        return ch;
    } else {
        return new Object[0];
    }
}
项目:openjdk-jdk10    文件:VMState.java   
/**
 * Tell listeners to invalidate suspend-sensitive caches.
 * If resumingThread != null, then only that thread is being
 * resumed.
 */
synchronized void thaw(ThreadReference resumingThread) {
    if (cache != null) {
        if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
            vm.printTrace("Clearing VM suspended cache");
        }
        disableCache();
    }
    processVMAction(new VMAction(vm, resumingThread, VMAction.VM_NOT_SUSPENDED));
}
项目:incubator-netbeans    文件:AWTGrabHandler.java   
private boolean ungrabWindowFX(ThreadReference tr) {
    // javafx.stage.Window.impl_getWindows() - Iterator<Window>
    // while (iterator.hasNext()) {
    //     Window w = iterator.next();
    //     ungrabWindowFX(w);
    // }
    try {
        VirtualMachine vm = MirrorWrapper.virtualMachine(tr);
        List<ReferenceType> windowClassesByName = VirtualMachineWrapper.classesByName(vm, "javafx.stage.Window");
        if (windowClassesByName.isEmpty()) {
            logger.info("Unable to release FX X grab, no javafx.stage.Window class in target VM "+VirtualMachineWrapper.description(vm));
            return true; // We do not know whether there was any grab
        }
        ClassType WindowClass = (ClassType) windowClassesByName.get(0);
        Method getWindowsMethod = WindowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;");
        if (getWindowsMethod == null) {
            logger.info("Unable to release FX X grab, no impl_getWindows() method in "+WindowClass);
            return true; // We do not know whether there was any grab
        }
        ObjectReference windowsIterator = (ObjectReference) WindowClass.invokeMethod(tr, getWindowsMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
        if (windowsIterator == null) {
            return true; // We do not know whether there was any grab
        }
        InterfaceType IteratorClass = (InterfaceType) VirtualMachineWrapper.classesByName(vm, Iterator.class.getName()).get(0);
        Method hasNext = IteratorClass.methodsByName("hasNext", "()Z").get(0);
        Method next = IteratorClass.methodsByName("next", "()Ljava/lang/Object;").get(0);
        while (hasNext(hasNext, tr, windowsIterator)) {
            ObjectReference w = next(next, tr, windowsIterator);
            ungrabWindowFX(WindowClass, w, tr);
        }
    } catch (VMDisconnectedExceptionWrapper vmdex) {
        return true; // Disconnected, all is good.
    } catch (Exception ex) {
        logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex);
        return true; // We do not know whether there was any grab
    }
    return true;
}
项目:incubator-netbeans    文件:AWTGrabHandler.java   
private boolean ungrabWindowFX_OLD(ThreadReference tr) {
    // com.sun.javafx.tk.quantum.WindowStage has:
    // field static Map<Window, WindowStage> platformWindows = new HashMap<>();
    // com.sun.glass.ui.Window.ungrabFocus()
    try {
        VirtualMachine vm = MirrorWrapper.virtualMachine(tr);
        List<ReferenceType> windowStageClassesByName = VirtualMachineWrapper.classesByName(vm, "com.sun.javafx.tk.quantum.WindowStage");
        if (windowStageClassesByName.isEmpty()) {
            logger.info("Unable to release FX X grab, no quantum WindowStage class in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        ClassType WindowStageClass = (ClassType) windowStageClassesByName.get(0);
        Field platformWindowsField = WindowStageClass.fieldByName("platformWindows");
        if (platformWindowsField == null) {
            logger.info("Unable to release FX X grab, no platformWindows field found in WindowStage in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
        ObjectReference platformWindows = (ObjectReference) WindowStageClass.getValue(platformWindowsField);
        if (platformWindows == null) {
            logger.info("Unable to release FX X grab, no platformWindows field has null value in WindowStage in target VM "+VirtualMachineWrapper.description(vm));
            return false;
        }
    } catch (VMDisconnectedExceptionWrapper vmdex) {
        return true; // Disconnected, all is good.
    } catch (Exception ex) {
        logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex);
        return true; // We do not know whether there was any grab
    }
    return true;
}
项目:java-debug    文件:DebugUtility.java   
/**
 * Get the ThreadReference instance by the thread id.
 * @param debugSession
 *                  the debug session
 * @param threadId
 *                  the thread id
 * @return the ThreadReference instance
 */
public static ThreadReference getThread(IDebugSession debugSession, long threadId) {
    for (ThreadReference thread : getAllThreadsSafely(debugSession)) {
        if (thread.uniqueID() == threadId && !thread.isCollected()) {
            return thread;
        }
    }
    return null;
}
项目:openjdk-jdk10    文件:EventRequestManagerImpl.java   
public synchronized void addThreadFilter(ThreadReference thread) {
    validateMirror(thread);
    if (isEnabled() || deleted) {
        throw invalidState();
    }
    filters.add(JDWP.EventRequest.Set.Modifier.ThreadOnly
                              .create((ThreadReferenceImpl)thread));
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static void retrieveScreenshots(JPDAThreadImpl t, final ThreadReference tr, VirtualMachine vm, DebuggerEngine engine, JPDADebuggerImpl d, final List<RemoteScreenshot> screenshots) throws RetrievalException {
    try {
        final ClassType windowClass = getClass(vm, tr, "javafx.stage.Window");

        Method getWindows = windowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;");
        Method windowName = windowClass.concreteMethodByName("impl_getMXWindowType", "()Ljava/lang/String;");

        ObjectReference iterator = (ObjectReference)windowClass.invokeMethod(tr, getWindows, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
        ClassType iteratorClass = (ClassType)iterator.referenceType();
        Method hasNext = iteratorClass.concreteMethodByName("hasNext", "()Z");
        Method next = iteratorClass.concreteMethodByName("next", "()Ljava/lang/Object;");

        boolean nextFlag = false;
        do {
            BooleanValue bv = (BooleanValue)iterator.invokeMethod(tr, hasNext, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
            nextFlag = bv.booleanValue();
            if (nextFlag) {
                ObjectReference window = (ObjectReference)iterator.invokeMethod(tr, next, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                StringReference name = (StringReference)window.invokeMethod(tr, windowName, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
                SGComponentInfo windowInfo = new SGComponentInfo(t, window);

                screenshots.add(createRemoteFXScreenshot(engine, vm, tr, name.value(), window, windowInfo));
            }
        } while (nextFlag);
    } catch (Exception e) {
        throw new RetrievalException(e.getMessage(), e);
    }
}
项目: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 ClassType getClass(VirtualMachine vm, ThreadReference tr, String name) {
    ReferenceType t = getType(vm, tr, name);
    if (t instanceof ClassType) {
        return (ClassType)t;
    }
    logger.log(Level.WARNING, "{0} is not a class but {1}", new Object[]{name, t}); // NOI18N
    return null;
}
项目:incubator-netbeans    文件:RemoteFXScreenshot.java   
private static InterfaceType getInterface(VirtualMachine vm, ThreadReference tr, String name) {
    ReferenceType t = getType(vm, tr, name);
    if (t instanceof InterfaceType) {
        return (InterfaceType)t;
    }
    logger.log(Level.WARNING, "{0} is not an interface but {1}", new Object[]{name, t}); // NOI18N
    return null;
}
项目:incubator-netbeans    文件:VisualDebuggerListener.java   
private static ClassType getClass(VirtualMachine vm, ThreadReference tr, String name) {
    ReferenceType t = getType(vm, tr, name);
    if (t instanceof ClassType) {
        return (ClassType)t;
    }
    logger.log(Level.WARNING, "{0} is not a class but {1}", new Object[]{name, t}); // 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    文件:JPDADebuggerImpl.java   
public List<PropertyChangeEvent> notifySuspendAll(boolean doFire, boolean explicitelyPaused,
                                                  Set<ThreadReference> ignoredThreads) {
    Collection threads = threadsTranslation.getTranslated();
    List<PropertyChangeEvent> events = new ArrayList<PropertyChangeEvent>(threads.size());
    for (Iterator it = threads.iterator(); it.hasNext(); ) {
        Object threadOrGroup = it.next();
        if (threadOrGroup instanceof JPDAThreadImpl &&
                (ignoredThreads == null || !ignoredThreads.contains(((JPDAThreadImpl) threadOrGroup).getThreadReference()))) {
            int status = ((JPDAThreadImpl) threadOrGroup).getState();
            boolean invalid = (status == JPDAThread.STATE_NOT_STARTED ||
                               status == JPDAThread.STATE_UNKNOWN ||
                               status == JPDAThread.STATE_ZOMBIE);
            if (!invalid) {
                try {
                    PropertyChangeEvent event = ((JPDAThreadImpl) threadOrGroup).notifySuspended(doFire, explicitelyPaused);
                    if (event != null) {
                        events.add(event);
                    }
                } catch (ObjectCollectedException ocex) {
                    invalid = true;
                }
            } else if (status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE) {
                threadsTranslation.remove(((JPDAThreadImpl) threadOrGroup).getThreadReference());
            }
        }
    }
    return events;
}
项目:java-debug    文件:JavaHotCodeReplaceProvider.java   
private void stepIntoThread(ThreadReference thread) {
    StepRequest request = DebugUtility.createStepIntoRequest(thread,
            this.context.getStepFilters().classNameFilters);
    currentDebugSession.getEventHub().stepEvents().filter(debugEvent -> request.equals(debugEvent.event.request()))
            .take(1).subscribe(debugEvent -> {
                debugEvent.shouldResume = false;
                // Have to send to events to keep the UI sync with the step in operations:
                context.getProtocolServer().sendEvent(new Events.StoppedEvent("step", thread.uniqueID()));
                context.getProtocolServer().sendEvent(new Events.ContinuedEvent(thread.uniqueID()));
            });
    request.enable();
    thread.resume();
}
项目:java-debug    文件:JavaHotCodeReplaceProvider.java   
/**
 * Returns the stack frame that should be dropped to in the given thread after a
 * hot code replace. This is calculated by determining if the threads contain
 * stack frames that reside in one of the given replaced class names. If
 * possible, only stack frames whose methods were directly affected (and not
 * simply all frames in affected types) will be returned.
 */
private StackFrame getAffectedFrame(ThreadReference thread, List<String> replacedClassNames)
        throws DebugException {
    List<StackFrame> frames = getStackFrames(thread, false);
    StackFrame affectedFrame = null;
    for (int i = 0; i < frames.size(); i++) {
        StackFrame frame = frames.get(i);
        if (containsChangedType(frame, replacedClassNames)) {
            if (supportsDropToFrame(thread, frame)) {
                affectedFrame = frame;
                break;
            }
            // The frame we wanted to drop to cannot be popped.
            // Set the affected frame to the next lowest pop-able
            // frame on the stack.
            int j = i;
            while (j > 0) {
                j--;
                frame = frames.get(j);
                if (supportsDropToFrame(thread, frame)) {
                    affectedFrame = frame;
                    break;
                }
            }
            break;
        }
    }
    return affectedFrame;
}
项目: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;
    }
}
项目:incubator-netbeans    文件:JPDAThreadGroupImpl.java   
public JPDAThreadImpl[] getThreads () {
    ThreadsCache tc = debugger.getThreadsCache();
    if (tc == null) {
        return new JPDAThreadImpl[0];
    }
    List<ThreadReference> l = tc.getThreads(tgr);
    int i, k = l.size ();
    JPDAThreadImpl[] ts = new JPDAThreadImpl[k];
    for (i = 0; i < k; i++) {
        ts [i] = debugger.getThread(l.get (i));
    }
    return ts;
}
项目:incubator-netbeans    文件:JPDAThreadGroupImpl.java   
void notifyToBeResumed(ThreadsCache tc) {
    List<ThreadReference> threads = tc.getThreads(tgr);
    for (ThreadReference threadRef : threads) {
        JPDAThreadImpl thread = debugger.getThread(threadRef);
        thread.notifyToBeResumed();
    }
    List<ThreadGroupReference> groups = tc.getGroups(tgr);
    for (ThreadGroupReference groupRef : groups) {
        JPDAThreadGroupImpl group = (JPDAThreadGroupImpl) debugger.getThreadGroup(groupRef);
        group.notifyToBeResumed(tc);
    }
}
项目:incubator-netbeans    文件:JPDAThreadGroupImpl.java   
void notifySuspended(ThreadsCache tc) {
    List<ThreadReference> threads = tc.getThreads(tgr);
    for (ThreadReference threadRef : threads) {
        JPDAThreadImpl thread = debugger.getThread(threadRef);
        thread.notifySuspended();
    }
    List<ThreadGroupReference> groups = tc.getGroups(tgr);
    for (ThreadGroupReference groupRef : groups) {
        JPDAThreadGroupImpl group = (JPDAThreadGroupImpl) debugger.getThreadGroup(groupRef);
        group.notifySuspended(tc);
    }
}
项目:java-debug    文件:JdtEvaluationProvider.java   
private JDIThread getMockJDIThread(ThreadReference thread) {
    synchronized (threadMap) {
        return threadMap.computeIfAbsent(thread, threadKey -> new JDIThread(debugTarget, thread) {
            @Override
            protected synchronized void invokeComplete(int restoreTimeout) {
                super.invokeComplete(restoreTimeout);
                context.getStackFrameManager().reloadStackFrames(thread);
            }
        });
    }

}
项目:java-debug    文件:ThreadsRequestHandler.java   
private CompletableFuture<Response> pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) {
    ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
    if (thread != null) {
        thread.suspend();
        context.getProtocolServer().sendEvent(new Events.StoppedEvent("pause", arguments.threadId));
    } else {
        context.getDebugSession().suspend();
        context.getProtocolServer().sendEvent(new Events.StoppedEvent("pause", arguments.threadId, true));
    }
    return CompletableFuture.completedFuture(response);
}
项目:incubator-netbeans    文件:StepIntoNextMethod.java   
private void removeStepRequests (ThreadReference tr) {
    synchronized (this) {
        stepIntoRequest = null;
    }
    JPDADebuggerActionProvider.removeStepRequests (getDebuggerImpl(), tr);
    smartLogger.finer("removing all patterns, all step requests.");
}
项目:incubator-netbeans    文件:BreakpointImpl.java   
boolean processCondition(
        Event event,
        String condition,
        ThreadReference threadReference,
        Value returnValue) {

    return processCondition(event, condition, threadReference, returnValue, null);
}
项目:incubator-netbeans    文件:Operator.java   
/**
 * Removes binding between the specified event request and a registered object.
 *
 * @param  req  request
 * @see  #register
 */
public synchronized void unregister (EventRequest req) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper {
    Executor e = (Executor) EventRequestWrapper.getProperty(req, "executor");
    EventRequestWrapper.putProperty (req, "executor", null); // NOI18N
    if (e != null) {
        e.removed(req);
    }
    if (req instanceof StepRequest) {
        ThreadReference tr = StepRequestWrapper.thread((StepRequest) req);
        debugger.getThread(tr).setInStep(false, null);
    }
}
项目:incubator-netbeans    文件:Operator.java   
public synchronized void add(ThreadReference t) {
    MutableInteger i = threads.get(t);
    if (i == null) {
        i = new MutableInteger(1);
        threads.put(t, i);
    }
    i.i++;
}