Top


定義場所(file name)

jdk/src/share/classes/com/sun/tools/attach/VirtualMachine.java

説明(description)

    /**
     * Attaches to a Java virtual machine.
     *
     * <p> This method obtains the list of attach providers by invoking the
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
     * AttachProvider.providers()} method. It then iterates overs the list
     * and invokes each provider's {@link
     * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
     * attachVirtualMachine} method in turn. If a provider successfully
     * attaches then the iteration terminates, and the VirtualMachine created
     * by the provider that successfully attached is returned by this method.
     * If the <code>attachVirtualMachine</code> method of all providers throws
     * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
     * then this method also throws <code>AttachNotSupportedException</code>.
     * This means that <code>AttachNotSupportedException</code> is thrown when
     * the identifier provided to this method is invalid, or the identifier
     * corresponds to a Java virtual machine that does not exist, or none
     * of the providers can attach to it. This exception is also thrown if
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
     * AttachProvider.providers()} returns an empty list. </p>
     *
     * @param   id
     *          The abstract identifier that identifies the Java virtual machine.
     *
     * @return  A VirtualMachine representing the target VM.
     *
     * @throws  SecurityException
     *          If a security manager has been installed and it denies
     *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
     *          <tt>("attachVirtualMachine")</tt>, or another permission
     *          required by the implementation.
     *
     * @throws  AttachNotSupportedException
     *          If the <code>attachVirtualmachine</code> method of all installed
     *          providers throws <code>AttachNotSupportedException</code>, or
     *          there aren't any providers installed.
     *
     * @throws  IOException
     *          If an I/O error occurs
     *
     * @throws  NullPointerException
     *          If <code>id</code> is <code>null</code>.
     */

名前(function name)

    public static VirtualMachine attach(String id)
        throws AttachNotSupportedException, IOException
    {

本体部(body)

  {- -------------------------------------------
  (1) 引数が null なら NullPointerException.
      ---------------------------------------- -}

            if (id == null) {
                throw new NullPointerException("id cannot be null");
            }

  {- -------------------------------------------
  (1) com.sun.tools.attach.spi.AttachProvider.providers() で
      ---------------------------------------- -}

            List<AttachProvider> providers = AttachProvider.providers();
            if (providers.size() == 0) {
                throw new AttachNotSupportedException("no providers installed");
            }

  {- -------------------------------------------
  (1) 取得した AttachProvider オブジェクトに対して
      順に attachVirtualMachine() を呼び出していき, HotSpot へのアタッチを試みる.
      初めに成功した時点で結果をリターンする.

      (逆に最後まで成功しなければ, 最後の attachVirtualMachine() 呼び出しが起こした例外を再スローする)
      ---------------------------------------- -}

            AttachNotSupportedException lastExc = null;
            for (AttachProvider provider: providers) {
                try {
                    return provider.attachVirtualMachine(id);
                } catch (AttachNotSupportedException x) {
                    lastExc = x;
                }
            }
            throw lastExc;
        }

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