@Override
    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
        assert args.length <= 3;                // includes null

        // first check that we are still attached
        int door;
        synchronized (this) {
            if (fd == -1) {
                throw new IOException("Detached from target VM");
            }
            door = fd;
        }

        // enqueue the command via a door call
        int s = enqueue(door, cmd, args);
        assert s >= 0;                          // valid file descriptor

        // The door call returns a file descriptor (one end of a socket pair).
        // Create an input stream around it.
        SocketInputStream sis = new SocketInputStream(s);

        // Read the command completion status
        int completionStatus;
        try {
            completionStatus = readInt(sis);
        } catch (IOException ioe) {
            sis.close();
            throw ioe;
        }

        // If non-0 it means an error but we need to special-case the
        // "load" command to ensure that the right exception is thrown.
        if (completionStatus != 0) {
            sis.close();
            if (cmd.equals("load")) {
                throw new AgentLoadException("Failed to load agent library");
            } else {
                throw new IOException("Command failed in target VM");
            }
        }

        // Return the input stream so that the command output can be read
        return sis;
    }
@ Override InputStream execute ( String cmd , Object ... args ) throws AgentLoadException , IOException { assert args . length <= 3 ; int door ; synchronized ( this ) { if ( fd == - 1 ) { throw new IOException ( "Detached from target VM" ) ; } door = fd ; } int s = enqueue ( door , cmd , args ) ; assert s >= 0 ; SocketInputStream sis = new SocketInputStream ( s ) ; int completionStatus ; try { completionStatus = readInt ( sis ) ; } catch ( IOException ioe ) { sis . close ( ) ; throw ioe ; } if ( completionStatus != 0 ) { sis . close ( ) ; if ( cmd . equals ( "load" ) ) { throw new AgentLoadException ( "Failed to load agent library" ) ; } else { throw new IOException ( "Command failed in target VM" ) ; } } return sis ; }
Execute the given command in the target VM.