@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();
            }
        }
    }
@ Override public void stop ( ) throws EngineTerminationException , InternalException { synchronized ( STOP_LOCK ) { if ( ! userCodeRunning ) { return ; } vm ( ) . suspend ( ) ; try { OUTER : for ( ThreadReference thread : vm ( ) . allThreads ( ) ) { 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 ( ) ; } } }
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