Java Code Examples for com.sun.jdi.ThreadReference#stop()

The following examples show how to use com.sun.jdi.ThreadReference#stop() . 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: 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 2
Source File: LaunchJDIAgent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Interrupts a running remote invoke by manipulating remote variables
 * and sending a stop via JDI.
 *
 * @throws EngineTerminationException the execution engine has terminated
 * @throws InternalException an internal problem occurred
 */
@Override
public void stop() throws ExecutionControl.EngineTerminationException, ExecutionControl.InternalException {
    synchronized (STOP_LOCK) {
        if (!userCodeRunning) {
            return;
        }

        vm().suspend();
        try {
            OUTER:
            for (ThreadReference thread : vm().allThreads()) {
                // could also tag the thread (e.g. using name), to find it easier
                for (StackFrame frame : thread.frames()) {
                    if (REMOTE_AGENT.equals(frame.location().declaringType().name()) &&
                            (    "invoke".equals(frame.location().method().name())
                            || "varValue".equals(frame.location().method().name()))) {
                        ObjectReference thiz = frame.thisObject();
                        com.sun.jdi.Field inClientCode = thiz.referenceType().fieldByName("inClientCode");
                        com.sun.jdi.Field expectingStop = thiz.referenceType().fieldByName("expectingStop");
                        com.sun.jdi.Field stopException = thiz.referenceType().fieldByName("stopException");
                        if (((BooleanValue) thiz.getValue(inClientCode)).value()) {
                            thiz.setValue(expectingStop, vm().mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(stopException);

                            vm().resume();
                            debug("Attempting to stop the client code...\n");
                            thread.stop(stopInstance);
                            thiz.setValue(expectingStop, vm().mirrorOf(false));
                        }

                        break OUTER;
                    }
                }
            }
        } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
            throw new ExecutionControl.InternalException("Exception on remote stop: " + ex);
        } finally {
            vm().resume();
        }
    }
}
 
Example 3
Source File: JdiDefaultExecutionControl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Interrupts a running remote invoke by manipulating remote variables
 * and sending a stop via JDI.
 *
 * @throws EngineTerminationException the execution engine has terminated
 * @throws InternalException an internal problem occurred
 */
@Override
public void stop() throws EngineTerminationException, InternalException {
    synchronized (STOP_LOCK) {
        if (!userCodeRunning) {
            return;
        }

        vm().suspend();
        try {
            OUTER:
            for (ThreadReference thread : vm().allThreads()) {
                // could also tag the thread (e.g. using name), to find it easier
                for (StackFrame frame : thread.frames()) {
                    if (remoteAgent.equals(frame.location().declaringType().name()) &&
                            (    "invoke".equals(frame.location().method().name())
                            || "varValue".equals(frame.location().method().name()))) {
                        ObjectReference thiz = frame.thisObject();
                        Field inClientCode = thiz.referenceType().fieldByName("inClientCode");
                        Field expectingStop = thiz.referenceType().fieldByName("expectingStop");
                        Field stopException = thiz.referenceType().fieldByName("stopException");
                        if (((BooleanValue) thiz.getValue(inClientCode)).value()) {
                            thiz.setValue(expectingStop, vm().mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(stopException);

                            vm().resume();
                            debug("Attempting to stop the client code...\n");
                            thread.stop(stopInstance);
                            thiz.setValue(expectingStop, vm().mirrorOf(false));
                        }

                        break OUTER;
                    }
                }
            }
        } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
            throw new InternalException("Exception on remote stop: " + ex);
        } finally {
            vm().resume();
        }
    }
}