Top


定義場所(file name)

jdk/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java

説明(description)

    /**
     * Execute the given command in the target VM.
     */

名前(function name)

    InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {

本体部(body)

  {- -------------------------------------------
  (1) (assert)
      ---------------------------------------- -}

            assert args.length <= 3;                // includes null

  {- -------------------------------------------
  (1) 既に detach 済みであれば IOException.
      (See: sun.tools.attach.LinuxVirtualMachine.detach())
      ---------------------------------------- -}

            // did we detach?
            String p;
            synchronized (this) {
                if (this.path == null) {
                    throw new IOException("Detached from target VM");
                }
                p = this.path;
            }

  {- -------------------------------------------
  (1) 通信用の UNIX domain socket にコネクトする.

      (失敗して IOException が出たら, socket を閉じ, そのまま再スローして終了)
      ---------------------------------------- -}

            // create UNIX socket
            int s = socket();

            // connect to target VM
            try {
                connect(s, p);
            } catch (IOException x) {
                close(s);
                throw x;
            }

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

            IOException ioe = null;

  {- -------------------------------------------
  (1) 指定されたコマンド (及びその引数) を UNIX domain socket に書き込む.
      ---------------------------------------- -}

            // connected - write request
            // <ver> <cmd> <args...>
            try {
                writeString(s, PROTOCOL_VERSION);
                writeString(s, cmd);

                for (int i=0; i<3; i++) {
                    if (i < args.length && args[i] != null) {
                        writeString(s, (String)args[i]);
                    } else {
                        writeString(s, "");
                    }
                }
            } catch (IOException x) {
                ioe = x;
            }


  {- -------------------------------------------
  (1) 処理の終了ステータスを UNIX domain socket から読み取る
      ---------------------------------------- -}

            // Create an input stream to read reply
            SocketInputStream sis = new SocketInputStream(s);

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

  {- -------------------------------------------
  (1) もし処理がエラーを起こしていたら, 適切な例外をスロー.
      ---------------------------------------- -}

            if (completionStatus != 0) {
                sis.close();

                // In the event of a protocol mismatch then the target VM
                // returns a known error so that we can throw a reasonable
                // error.
                if (completionStatus == ATTACH_ERROR_BADVERSION) {
                    throw new IOException("Protocol mismatch with target VM");
                }

                // Special-case the "load" command so that the right exception is
                // thrown.
                if (cmd.equals("load")) {
                    throw new AgentLoadException("Failed to load agent library");
                } else {
                    throw new IOException("Command failed in target VM");
                }
            }

  {- -------------------------------------------
  (1) 処理結果を読むための SocketInputStream オブジェクトをリターン.
      ---------------------------------------- -}

            // Return the input stream so that the command output can be read
            return sis;
        }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.