jdk/src/jdk.attach/share/classes/com/sun/tools/attach/VirtualMachine.java
author sla
Mon, 08 Sep 2014 14:46:51 +0200
changeset 26453 eb89fa61bc70
parent 25859 3317bb8137f4
child 32210 958d823579c3
permissions -rw-r--r--
8057776: Misc cleanups of the attach code Reviewed-by: alanb, dfuchs, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.attach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.attach.spi.AttachProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p> A <code>VirtualMachine</code> represents a Java virtual machine to which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Java virtual machine has attached. The Java virtual machine to which it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * attached is sometimes called the <i>target virtual machine</i>, or <i>target VM</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * An application (typically a tool such as a managemet console or profiler) uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * VirtualMachine to load an agent into the target VM. For example, a profiler tool
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * written in the Java Language might attach to a running application and load its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * profiler agent to profile the running application. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p> A VirtualMachine is obtained by invoking the {@link #attach(String) attach} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * with an identifier that identifies the target virtual machine. The identifier is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * implementation-dependent but is typically the process identifier (or pid) in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * environments where each Java virtual machine runs in its own operating system process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Alternatively, a <code>VirtualMachine</code> instance is obtained by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * {@link #attach(VirtualMachineDescriptor) attach} method with a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * com.sun.tools.attach.VirtualMachineDescriptor VirtualMachineDescriptor} obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * from the list of virtual machine descriptors returned by the {@link #list list} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Once a reference to a virtual machine is obtained, the {@link #loadAgent loadAgent},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * {@link #loadAgentLibrary loadAgentLibrary}, and {@link #loadAgentPath loadAgentPath}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * methods are used to load agents into target virtual machine. The {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * #loadAgent loadAgent} method is used to load agents that are written in the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Language and deployed in a {@link java.util.jar.JarFile JAR file}. (See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * {@link java.lang.instrument} for a detailed description on how these agents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * are loaded and started). The {@link #loadAgentLibrary loadAgentLibrary} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@link #loadAgentPath loadAgentPath} methods are used to load agents that
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
    62
 * are deployed either in a dynamic library or statically linked into the VM and make use of the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * href="../../../../../../../../technotes/guides/jvmti/index.html">JVM Tools
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Interface</a>. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p> In addition to loading agents a VirtualMachine provides read access to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * {@link java.lang.System#getProperties() system properties} in the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * This can be useful in some environments where properties such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <code>java.home</code>, <code>os.name</code>, or <code>os.arch</code> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * used to construct the path to agent that will be loaded into the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p> The following example demonstrates how VirtualMachine may be used:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *      // attach to target VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *      VirtualMachine vm = VirtualMachine.attach("2177");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    79
 *      // start management agent
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    80
 *      Properties props = new Properties();
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    81
 *      props.put("com.sun.management.jmxremote.port", "5000");
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    82
 *      vm.startManagementAgent(props);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *      // detach
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *      vm.detach();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p> In this example we attach to a Java virtual machine that is identified by
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    90
 * the process identifier <code>2177</code>. Then the JMX management agent is
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    91
 * started in the target process using the supplied arguments. Finally, the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
    92
 * client detaches from the target VM. </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p> A VirtualMachine is safe for use by multiple concurrent threads. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
20742
4ae78e8060d6 8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents: 19594
diff changeset
    99
@jdk.Exported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
public abstract class VirtualMachine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private AttachProvider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private volatile int hash;        // 0 => not computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Initializes a new instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param   provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *          The attach provider creating this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param   id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *          The abstract identifier that identifies the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *          If <code>provider</code> or <code>id</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected VirtualMachine(AttachProvider provider, String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new NullPointerException("provider cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (id == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new NullPointerException("id cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Return a list of Java virtual machines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p> This method returns a list of Java {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * com.sun.tools.attach.VirtualMachineDescriptor} elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The list is an aggregation of the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * descriptor lists obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * com.sun.tools.attach.spi.AttachProvider#listVirtualMachines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * listVirtualMachines} method of all installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * {@link com.sun.tools.attach.spi.AttachProvider attach providers}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * If there are no Java virtual machines known to any provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * then an empty list is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return  The list of virtual machine descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static List<VirtualMachineDescriptor> list() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        ArrayList<VirtualMachineDescriptor> l =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            new ArrayList<VirtualMachineDescriptor>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        List<AttachProvider> providers = AttachProvider.providers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        for (AttachProvider provider: providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            l.addAll(provider.listVirtualMachines());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Attaches to a Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <p> This method obtains the list of attach providers by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * AttachProvider.providers()} method. It then iterates overs the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * and invokes each provider's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * attachVirtualMachine} method in turn. If a provider successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * attaches then the iteration terminates, and the VirtualMachine created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * by the provider that successfully attached is returned by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * If the <code>attachVirtualMachine</code> method of all providers throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * then this method also throws <code>AttachNotSupportedException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * This means that <code>AttachNotSupportedException</code> is thrown when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * the identifier provided to this method is invalid, or the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * corresponds to a Java virtual machine that does not exist, or none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * of the providers can attach to it. This exception is also thrown if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * AttachProvider.providers()} returns an empty list. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param   id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          The abstract identifier that identifies the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return  A VirtualMachine representing the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          <tt>("attachVirtualMachine")</tt>, or another permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *          required by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @throws  AttachNotSupportedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *          If the <code>attachVirtualmachine</code> method of all installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *          providers throws <code>AttachNotSupportedException</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          there aren't any providers installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          If <code>id</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public static VirtualMachine attach(String id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        throws AttachNotSupportedException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (id == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new NullPointerException("id cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        List<AttachProvider> providers = AttachProvider.providers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (providers.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new AttachNotSupportedException("no providers installed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        AttachNotSupportedException lastExc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        for (AttachProvider provider: providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return provider.attachVirtualMachine(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                lastExc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        throw lastExc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Attaches to a Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p> This method first invokes the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * com.sun.tools.attach.VirtualMachineDescriptor#provider() provider()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * of the given virtual machine descriptor to obtain the attach provider. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * then invokes the attach provider's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(VirtualMachineDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * attachVirtualMachine} to attach to the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param   vmd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *          The virtual machine descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return  A VirtualMachine representing the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *          <tt>("attachVirtualMachine")</tt>, or another permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *          required by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @throws  AttachNotSupportedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *          If the attach provider's <code>attachVirtualmachine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *          throws <code>AttachNotSupportedException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *          If <code>vmd</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static VirtualMachine attach(VirtualMachineDescriptor vmd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        throws AttachNotSupportedException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return vmd.provider().attachVirtualMachine(vmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Detach from the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p> After detaching from the virtual machine, any further attempt to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * operations on that virtual machine will cause an {@link java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * IOException} to be thrown. If an operation (such as {@link #loadAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * loadAgent} for example) is in progress when this method is invoked then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * the behaviour is implementation dependent. In other words, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * implementation specific if the operation completes or throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p> If already detached from the virtual machine then invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * method has no effect. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public abstract void detach() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns the provider that created this virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return  The provider that created this virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public final AttachProvider provider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Returns the identifier for this Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return  The identifier for this Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public final String id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Loads an agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * TI</a> client is called an <i>agent</i>. It is developed in a native language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * A JVM TI agent is deployed in a platform specific manner but it is typically the
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   296
     * platform equivalent of a dynamic library. Alternatively, it may be statically linked into the VM.
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   297
     * This method causes the given agent library to be loaded into the target
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   298
     * VM (if not already loaded or if not statically linked into the VM).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   300
     * or, for a statically linked agent named 'L', the <code>Agent_OnAttach_L</code> function
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   303
     * Interface</a> specification. Note that the <code>Agent_OnAttach[_L]</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * function is invoked even if the agent library was loaded prior to invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <p> The agent library provided is the name of the agent library. It is interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * in the target virtual machine in an implementation-dependent manner. Typically an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * implementation will expand the library name into an operating system specific file
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   310
     * name. For example, on UNIX systems, the name <tt>L</tt> might be expanded to
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   311
     * <tt>libL.so</tt>, and located using the search path specified by the
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   312
     * <tt>LD_LIBRARY_PATH</tt> environment variable. If the agent named 'L' is
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   313
     * statically linked into the VM then the VM must export a function named
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   314
     * <code>Agent_OnAttach_L</code>.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   316
     * <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   318
     * thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * method on the exception. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param   agentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *          The name of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param   options
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   327
     *          The options to provide to the <code>Agent_OnAttach[_L]</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          function (can be <code>null</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   331
     *          If the agent library does not exist, the agent library is not
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   332
     *          statically linked with the VM, or the agent library cannot be
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   333
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @throws  AgentInitializationException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   336
     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *          If <code>agentLibrary</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see     com.sun.tools.attach.AgentInitializationException#returnValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public abstract void loadAgentLibrary(String agentLibrary, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Loads an agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <blockquote><tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * {@link #loadAgentLibrary(String, String) loadAgentLibrary}(agentLibrary,&nbsp;null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * </tt></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param   agentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *          The name of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   362
     *          If the agent library does not exist, the agent library is not
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   363
     *          statically linked with the VM, or the agent library cannot be
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   364
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @throws  AgentInitializationException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   367
     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          If <code>agentLibrary</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public void loadAgentLibrary(String agentLibrary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        loadAgentLibrary(agentLibrary, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Load a native agent library by full pathname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * TI</a> client is called an <i>agent</i>. It is developed in a native language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * A JVM TI agent is deployed in a platform specific manner but it is typically the
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   387
     * platform equivalent of a dynamic library. Alternatively, the native
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   388
     * library specified by the agentPath parameter may be statically
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   389
     * linked with the VM. The parsing of the agentPath parameter into
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   390
     * a statically linked library name is done in a platform
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   391
     * specific manner in the VM. For example, in UNIX, an agentPath parameter
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   392
     * of <code>/a/b/libL.so</code> would name a library 'L'.
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   393
     *
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   394
     * See the JVM TI Specification for more details.
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   395
     *
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   396
     * This method causes the given agent library to be loaded into the target
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   397
     * VM (if not already loaded or if not statically linked into the VM).
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   398
     * It then causes the target VM to invoke the <code>Agent_OnAttach</code>
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   399
     * function or, for a statically linked agent named 'L', the
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   400
     * <code>Agent_OnAttach_L</code> function as specified in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   402
     * Interface</a> specification.
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   403
     * Note that the <code>Agent_OnAttach[_L]</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * function is invoked even if the agent library was loaded prior to invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p> The agent library provided is the absolute path from which to load the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * is not expanded in the target virtual machine. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   411
     * <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   413
     * thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * method on the exception. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param   agentPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *          The full path of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param   options
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   422
     *          The options to provide to the <code>Agent_OnAttach[_L]</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *          function (can be <code>null</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   426
     *          If the agent library does not exist, the agent library is not
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   427
     *          statically linked with the VM, or the agent library cannot be
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   428
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @throws  AgentInitializationException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   431
     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *          If <code>agentPath</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @see     com.sun.tools.attach.AgentInitializationException#returnValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public abstract void loadAgentPath(String agentPath, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Load a native agent library by full pathname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * <blockquote><tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * {@link #loadAgentPath(String, String) loadAgentPath}(agentLibrary,&nbsp;null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * </tt></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param   agentPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *          The full path to the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   457
     *          If the agent library does not exist, the agent library is not
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   458
     *          statically linked with the VM, or the agent library cannot be
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   459
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @throws  AgentInitializationException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   462
     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *          If <code>agentPath</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public void loadAgentPath(String agentPath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
       throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        loadAgentPath(agentPath, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Loads an agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p> The agent provided to this method is a path name to a JAR file on the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * system of the target virtual machine. This path is passed to the target virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * machine where it is interpreted. The target virtual machine attempts to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * the agent as specified by the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * That is, the specified JAR file is added to the system class path (of the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * virtual machine), and the <code>agentmain</code> method of the agent class, specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * by the <code>Agent-Class</code> attribute in the JAR manifest, is invoked. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * method completes when the <code>agentmain</code> method completes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param   agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *          Path to the JAR file containing the agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param   options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *          The options to provide to the agent's <code>agentmain</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *          method (can be <code>null</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @throws  AgentLoadException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *          If the agent does not exist, or cannot be started in the manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *          specified in the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws  AgentInitializationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *          If the <code>agentmain</code> throws an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *          If <code>agent</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public abstract void loadAgent(String agent, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Loads an agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <blockquote><tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * {@link #loadAgent(String, String) loadAgent}(agent,&nbsp;null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * </tt></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param   agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *          Path to the JAR file containing the agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @throws  AgentLoadException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *          If the agent does not exist, or cannot be started in the manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *          specified in the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @throws  AgentInitializationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *          If the <code>agentmain</code> throws an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *          If <code>agent</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public void loadAgent(String agent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        loadAgent(agent, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Returns the current system properties in the target virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <p> This method returns the system properties in the target virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * machine. Properties whose key or value is not a <tt>String</tt> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * omitted. The method is approximately equivalent to the invocation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * method {@link java.lang.System#getProperties System.getProperties}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * in the target virtual machine except that properties with a key or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * value that is not a <tt>String</tt> are not included.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <p> This method is typically used to decide which agent to load into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * the target virtual machine with {@link #loadAgent loadAgent}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * {@link #loadAgentLibrary loadAgentLibrary}. For example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>java.home</code> or <code>user.dir</code> properties might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * use to create the path to the agent library or JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @return  The system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   561
     * @throws  AttachOperationFailedException
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   562
     *          If the target virtual machine is unable to complete the
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   563
     *          attach operation. A more specific error message will be
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   564
     *          given by {@link AttachOperationFailedException#getMessage()}.
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   565
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @throws  IOException
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   567
     *          If an I/O error occurs, a communication error for example,
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   568
     *          that cannot be identified as an error to indicate that the
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   569
     *          operation failed in the target VM.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see     java.lang.System#getProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see     #loadAgentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see     #loadAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public abstract Properties getSystemProperties() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Returns the current <i>agent properties</i> in the target virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <p> The target virtual machine can maintain a list of properties on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * behalf of agents. The manner in which this is done, the names of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * properties, and the types of values that are allowed, is implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * specific. Agent properties are typically used to store communication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * end-points and other agent configuration details. For example, a debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * agent might create an agent property for its transport address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <p> This method returns the agent properties whose key and value is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <tt>String</tt>. Properties whose key or value is not a <tt>String</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * are omitted. If there are no agent properties maintained in the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * virtual machine then an empty property list is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @return       The agent properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   595
     * @throws       AttachOperationFailedException
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   596
     *               If the target virtual machine is unable to complete the
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   597
     *               attach operation. A more specific error message will be
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   598
     *               given by {@link AttachOperationFailedException#getMessage()}.
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   599
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @throws       IOException
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   601
     *               If an I/O error occurs, a communication error for example,
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   602
     *               that cannot be identified as an error to indicate that the
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   603
     *               operation failed in the target VM.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public abstract Properties getAgentProperties() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   608
     * Starts the JMX management agent in the target virtual machine.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   609
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   610
     * <p> The configuration properties are the same as those specified on
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   611
     * the command line when starting the JMX management agent. In the same
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   612
     * way as on the command line, you need to specify at least the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   613
     * {@code com.sun.management.jmxremote.port} property.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   614
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   615
     * <p> See the online documentation for <a
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   616
     * href="../../../../../../../../technotes/guides/management/agent.html">
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   617
     * Monitoring and Management Using JMX Technology</a> for further details.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   618
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   619
     * @param   agentProperties
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   620
     *          A Properties object containing the configuration properties
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   621
     *          for the agent.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   622
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   623
     * @throws  AttachOperationFailedException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   624
     *          If the target virtual machine is unable to complete the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   625
     *          attach operation. A more specific error message will be
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   626
     *          given by {@link AttachOperationFailedException#getMessage()}.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   627
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   628
     * @throws  IOException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   629
     *          If an I/O error occurs, a communication error for example,
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   630
     *          that cannot be identified as an error to indicate that the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   631
     *          operation failed in the target VM.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   632
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   633
     * @throws  IllegalArgumentException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   634
     *          If keys or values in agentProperties are invalid.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   635
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   636
     * @throws  NullPointerException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   637
     *          If agentProperties is null.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   638
     *
26453
eb89fa61bc70 8057776: Misc cleanups of the attach code
sla
parents: 25859
diff changeset
   639
     * @since   1.8
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   640
     */
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   641
    public abstract void startManagementAgent(Properties agentProperties) throws IOException;
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   642
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   643
    /**
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   644
     * Starts the local JMX management agent in the target virtual machine.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   645
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   646
     * <p> See the online documentation for <a
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   647
     * href="../../../../../../../../technotes/guides/management/agent.html">
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   648
     * Monitoring and Management Using JMX Technology</a> for further details.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   649
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   650
     * @return  The String representation of the local connector's service address.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   651
     *          The value can be parsed by the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   652
     *          {@link javax.management.remote.JMXServiceURL#JMXServiceURL(String)}
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   653
     *          constructor.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   654
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   655
     * @throws  AttachOperationFailedException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   656
     *          If the target virtual machine is unable to complete the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   657
     *          attach operation. A more specific error message will be
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   658
     *          given by {@link AttachOperationFailedException#getMessage()}.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   659
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   660
     * @throws  IOException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   661
     *          If an I/O error occurs, a communication error for example,
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   662
     *          that cannot be identified as an error to indicate that the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   663
     *          operation failed in the target VM.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   664
     *
26453
eb89fa61bc70 8057776: Misc cleanups of the attach code
sla
parents: 25859
diff changeset
   665
     * @since   1.8
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   666
     */
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   667
    public abstract String startLocalManagementAgent() throws IOException;
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   668
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   669
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * Returns a hash-code value for this VirtualMachine. The hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * code is based upon the VirtualMachine's components, and satifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * the general contract of the {@link java.lang.Object#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Object.hashCode} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @return  A hash-code value for this virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (hash != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        hash = provider.hashCode() * 127 + id.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * Tests this VirtualMachine for equality with another object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <p> If the given object is not a VirtualMachine then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * method returns <tt>false</tt>. For two VirtualMachines to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * be considered equal requires that they both reference the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * provider, and their {@link VirtualMachineDescriptor#id() identifiers} are equal. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <p> This method satisfies the general contract of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * java.lang.Object#equals(Object) Object.equals} method. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @param   ob   The object to which this object is to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @return  <tt>true</tt> if, and only if, the given object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *                a VirtualMachine that is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *                VirtualMachine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (ob == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (!(ob instanceof VirtualMachine))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        VirtualMachine other = (VirtualMachine)ob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (other.provider() != this.provider()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (!other.id().equals(this.id())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Returns the string representation of the <code>VirtualMachine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        return provider.toString() + ": " + id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
}