src/jdk.attach/share/classes/com/sun/tools/attach/VirtualMachine.java
author roland
Sat, 02 Dec 2017 13:50:04 +0100
changeset 48298 40b9faefb496
parent 47216 71c04702a3d5
permissions -rw-r--r--
8191950: assertion failed: no insertions allowed Summary: Check for dead loops before incremental inlining. Reviewed-by: thartmann
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
 *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
    38
 * <p> A {@code VirtualMachine} represents a Java virtual machine to which this
2
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.
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
    50
 * Alternatively, a {@code VirtualMachine} instance is obtained by invoking the
2
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
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
    62
 * are deployed either in a dynamic library or statically linked into the VM and
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
    63
 * make use of the <a href="{@docRoot}/../specs/jvmti.html">JVM Tools Interface</a>.
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
    64
 * </p>
2
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
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
    69
 * {@code java.home}, {@code os.name}, or {@code os.arch} are
2
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
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
    90
 * the process identifier {@code 2177}. Then the JMX management agent is
24870
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
public abstract class VirtualMachine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private AttachProvider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private volatile int hash;        // 0 => not computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Initializes a new instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param   provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *          The attach provider creating this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param   id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *          The abstract identifier that identifies the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   113
     *          If {@code provider} or {@code id} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected VirtualMachine(AttachProvider provider, String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new NullPointerException("provider cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (id == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new NullPointerException("id cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Return a list of Java virtual machines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p> This method returns a list of Java {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * com.sun.tools.attach.VirtualMachineDescriptor} elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The list is an aggregation of the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * descriptor lists obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * com.sun.tools.attach.spi.AttachProvider#listVirtualMachines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * listVirtualMachines} method of all installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * {@link com.sun.tools.attach.spi.AttachProvider attach providers}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * If there are no Java virtual machines known to any provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * then an empty list is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return  The list of virtual machine descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static List<VirtualMachineDescriptor> list() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ArrayList<VirtualMachineDescriptor> l =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            new ArrayList<VirtualMachineDescriptor>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        List<AttachProvider> providers = AttachProvider.providers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        for (AttachProvider provider: providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            l.addAll(provider.listVirtualMachines());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Attaches to a Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <p> This method obtains the list of attach providers by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * AttachProvider.providers()} method. It then iterates overs the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * and invokes each provider's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * attachVirtualMachine} method in turn. If a provider successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * attaches then the iteration terminates, and the VirtualMachine created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * by the provider that successfully attached is returned by this method.
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   162
     * If the {@code attachVirtualMachine} method of all providers throws
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   164
     * then this method also throws {@code AttachNotSupportedException}.
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   165
     * This means that {@code AttachNotSupportedException} is thrown when
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * the identifier provided to this method is invalid, or the identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * corresponds to a Java virtual machine that does not exist, or none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * of the providers can attach to it. This exception is also thrown if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * {@link com.sun.tools.attach.spi.AttachProvider#providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * AttachProvider.providers()} returns an empty list. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param   id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *          The abstract identifier that identifies the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return  A VirtualMachine representing the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   180
     *          {@code ("attachVirtualMachine")}, or another permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          required by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @throws  AttachNotSupportedException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   184
     *          If the {@code attachVirtualmachine} method of all installed
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   185
     *          providers throws {@code AttachNotSupportedException}, or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *          there aren't any providers installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   192
     *          If {@code id} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static VirtualMachine attach(String id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        throws AttachNotSupportedException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (id == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throw new NullPointerException("id cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        List<AttachProvider> providers = AttachProvider.providers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (providers.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new AttachNotSupportedException("no providers installed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        AttachNotSupportedException lastExc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        for (AttachProvider provider: providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                return provider.attachVirtualMachine(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            } catch (AttachNotSupportedException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                lastExc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        throw lastExc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Attaches to a Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p> This method first invokes the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * com.sun.tools.attach.VirtualMachineDescriptor#provider() provider()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * of the given virtual machine descriptor to obtain the attach provider. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * then invokes the attach provider's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(VirtualMachineDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * attachVirtualMachine} to attach to the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param   vmd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *          The virtual machine descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return  A VirtualMachine representing the target VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   233
     *          {@code ("attachVirtualMachine")}, or another permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *          required by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @throws  AttachNotSupportedException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   237
     *          If the attach provider's {@code attachVirtualmachine}
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   238
     *          throws {@code AttachNotSupportedException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   244
     *          If {@code vmd} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static VirtualMachine attach(VirtualMachineDescriptor vmd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        throws AttachNotSupportedException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return vmd.provider().attachVirtualMachine(vmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Detach from the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <p> After detaching from the virtual machine, any further attempt to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * operations on that virtual machine will cause an {@link java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * IOException} to be thrown. If an operation (such as {@link #loadAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * loadAgent} for example) is in progress when this method is invoked then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * the behaviour is implementation dependent. In other words, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * implementation specific if the operation completes or throws
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   261
     * {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <p> If already detached from the virtual machine then invoking this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * method has no effect. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public abstract void detach() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns the provider that created this virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return  The provider that created this virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public final AttachProvider provider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Returns the identifier for this Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return  The identifier for this Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public final String id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Loads an agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   292
     * <p> A <a href="{@docRoot}/../specs/jvmti.html">JVM TI</a>
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   293
     * client is called an <i>agent</i>. It is developed in a native language.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * 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
   295
     * 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
   296
     * 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
   297
     * VM (if not already loaded or if not statically linked into the VM).
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   298
     * It then causes the target VM to invoke the {@code Agent_OnAttach} function
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   299
     * or, for a statically linked agent named 'L', the {@code Agent_OnAttach_L} function
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * as specified in the
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   301
     * <a href="{@docRoot}/../specs/jvmti.html">JVM Tools Interface</a> specification.
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   302
     * Note that the {@code Agent_OnAttach[_L]}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * function is invoked even if the agent library was loaded prior to invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <p> The agent library provided is the name of the agent library. It is interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * in the target virtual machine in an implementation-dependent manner. Typically an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * implementation will expand the library name into an operating system specific file
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   309
     * name. For example, on UNIX systems, the name {@code L} might be expanded to
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   310
     * {@code libL.so}, and located using the search path specified by the
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   311
     * {@code LD_LIBRARY_PATH} environment variable. If the agent named 'L' is
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   312
     * statically linked into the VM then the VM must export a function named
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   313
     * {@code Agent_OnAttach_L}.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   315
     * <p> If the {@code Agent_OnAttach[_L]} function in the agent library returns
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   317
     * thrown. The return value from the {@code Agent_OnAttach[_L]} can then be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * method on the exception. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param   agentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *          The name of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param   options
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   326
     *          The options to provide to the {@code Agent_OnAttach[_L]}
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   327
     *          function (can be {@code null}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   330
     *          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
   331
     *          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
   332
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   335
     *          If the {@code Agent_OnAttach[_L]} function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   341
     *          If {@code agentLibrary} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see     com.sun.tools.attach.AgentInitializationException#returnValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public abstract void loadAgentLibrary(String agentLibrary, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Loads an agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   353
     * <blockquote><code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * {@link #loadAgentLibrary(String, String) loadAgentLibrary}(agentLibrary,&nbsp;null);
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   355
     * </code></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param   agentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *          The name of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   361
     *          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
   362
     *          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
   363
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   366
     *          If the {@code Agent_OnAttach[_L]} function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   372
     *          If {@code agentLibrary} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void loadAgentLibrary(String agentLibrary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        loadAgentLibrary(agentLibrary, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Load a native agent library by full pathname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   383
     * <p> A <a href="{@docRoot}/../specs/jvmti.html">JVM TI</a>
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   384
     * client is called an <i>agent</i>. It is developed in a native language.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * 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
   386
     * 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
   387
     * 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
   388
     * 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
   389
     * 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
   390
     * specific manner in the VM. For example, in UNIX, an agentPath parameter
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   391
     * of {@code /a/b/libL.so} would name a library 'L'.
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   392
     *
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   393
     * 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
   394
     *
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   395
     * 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
   396
     * VM (if not already loaded or if not statically linked into the VM).
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   397
     * It then causes the target VM to invoke the {@code Agent_OnAttach}
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   398
     * function or, for a statically linked agent named 'L', the
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   399
     * {@code Agent_OnAttach_L} function as specified in the
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   400
     * <a href="{@docRoot}/../specs/jvmti.html">JVM Tools Interface</a> specification.
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   401
     * Note that the {@code Agent_OnAttach[_L]}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * function is invoked even if the agent library was loaded prior to invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * <p> The agent library provided is the absolute path from which to load the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * is not expanded in the target virtual machine. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   409
     * <p> If the {@code Agent_OnAttach[_L]} function in the agent library returns
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   411
     * thrown. The return value from the {@code Agent_OnAttach[_L]} can then be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * obtained by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * method on the exception. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param   agentPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *          The full path of the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param   options
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   420
     *          The options to provide to the {@code Agent_OnAttach[_L]}
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   421
     *          function (can be {@code null}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   424
     *          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
   425
     *          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
   426
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   429
     *          If the {@code Agent_OnAttach[_L]} function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   435
     *          If {@code agentPath} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see     com.sun.tools.attach.AgentInitializationException#returnValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public abstract void loadAgentPath(String agentPath, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Load a native agent library by full pathname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   447
     * <blockquote><code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * {@link #loadAgentPath(String, String) loadAgentPath}(agentLibrary,&nbsp;null);
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   449
     * </code></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @param   agentPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *          The full path to the agent library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @throws  AgentLoadException
19594
3c054071d45a 8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents: 5506
diff changeset
   455
     *          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
   456
     *          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
   457
     *          loaded for another reason.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   460
     *          If the {@code Agent_OnAttach[_L]} function returns an error.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   466
     *          If {@code agentPath} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public void loadAgentPath(String agentPath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
       throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        loadAgentPath(agentPath, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Loads an agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * <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
   479
     * system of the target virtual machine. This path is passed to the target virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * machine where it is interpreted. The target virtual machine attempts to start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * the agent as specified by the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * That is, the specified JAR file is added to the system class path (of the target
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   483
     * virtual machine), and the {@code agentmain} method of the agent class, specified
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   484
     * by the {@code Agent-Class} attribute in the JAR manifest, is invoked. This
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   485
     * method completes when the {@code agentmain} method completes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @param   agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *          Path to the JAR file containing the agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param   options
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   491
     *          The options to provide to the agent's {@code agentmain}
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   492
     *          method (can be {@code null}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws  AgentLoadException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *          If the agent does not exist, or cannot be started in the manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *          specified in the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   499
     *          If the {@code agentmain} throws an exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   505
     *          If {@code agent} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public abstract void loadAgent(String agent, String options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        throws AgentLoadException, AgentInitializationException, IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Loads an agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <p> This convenience method works as if by invoking:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   515
     * <blockquote><code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * {@link #loadAgent(String, String) loadAgent}(agent,&nbsp;null);
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   517
     * </code></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @param   agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          Path to the JAR file containing the agent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @throws  AgentLoadException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *          If the agent does not exist, or cannot be started in the manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *          specified in the {@link java.lang.instrument} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @throws  AgentInitializationException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   527
     *          If the {@code agentmain} throws an exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   533
     *          If {@code agent} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public void loadAgent(String agent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        throws AgentLoadException, AgentInitializationException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        loadAgent(agent, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Returns the current system properties in the target virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <p> This method returns the system properties in the target virtual
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   545
     * machine. Properties whose key or value is not a {@code String} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * omitted. The method is approximately equivalent to the invocation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * method {@link java.lang.System#getProperties System.getProperties}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * in the target virtual machine except that properties with a key or
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   549
     * value that is not a {@code String} are not included.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <p> This method is typically used to decide which agent to load into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * the target virtual machine with {@link #loadAgent loadAgent}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * {@link #loadAgentLibrary loadAgentLibrary}. For example, the
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   554
     * {@code java.home} or {@code user.dir} properties might be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * use to create the path to the agent library or JAR file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @return  The system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   559
     * @throws  AttachOperationFailedException
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   560
     *          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
   561
     *          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
   562
     *          given by {@link AttachOperationFailedException#getMessage()}.
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   563
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @throws  IOException
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   565
     *          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
   566
     *          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
   567
     *          operation failed in the target VM.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @see     java.lang.System#getProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see     #loadAgentLibrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see     #loadAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public abstract Properties getSystemProperties() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Returns the current <i>agent properties</i> in the target virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <p> The target virtual machine can maintain a list of properties on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * behalf of agents. The manner in which this is done, the names of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * properties, and the types of values that are allowed, is implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * specific. Agent properties are typically used to store communication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * end-points and other agent configuration details. For example, a debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * agent might create an agent property for its transport address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <p> This method returns the agent properties whose key and value is a
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   587
     * {@code String}. Properties whose key or value is not a {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * are omitted. If there are no agent properties maintained in the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * virtual machine then an empty property list is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @return       The agent properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   593
     * @throws       AttachOperationFailedException
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   594
     *               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
   595
     *               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
   596
     *               given by {@link AttachOperationFailedException#getMessage()}.
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   597
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @throws       IOException
24363
33b869a8806b 8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework
sla
parents: 20742
diff changeset
   599
     *               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
   600
     *               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
   601
     *               operation failed in the target VM.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public abstract Properties getAgentProperties() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   606
     * 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
   607
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   608
     * <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
   609
     * 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
   610
     * 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
   611
     * {@code com.sun.management.jmxremote.port} property.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   612
     *
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   613
     * <p> See the online documentation for
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   614
     * {@extLink monitoring_and_management_using_jmx_technology
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   615
     * Monitoring and Management Using JMX Technology} for further details.
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   616
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   617
     * @param   agentProperties
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   618
     *          A Properties object containing the configuration properties
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   619
     *          for the agent.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   620
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   621
     * @throws  AttachOperationFailedException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   622
     *          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
   623
     *          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
   624
     *          given by {@link AttachOperationFailedException#getMessage()}.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   625
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   626
     * @throws  IOException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   627
     *          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
   628
     *          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
   629
     *          operation failed in the target VM.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   630
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   631
     * @throws  IllegalArgumentException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   632
     *          If keys or values in agentProperties are invalid.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   633
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   634
     * @throws  NullPointerException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   635
     *          If agentProperties is null.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   636
     *
26453
eb89fa61bc70 8057776: Misc cleanups of the attach code
sla
parents: 25859
diff changeset
   637
     * @since   1.8
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   638
     */
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   639
    public abstract void startManagementAgent(Properties agentProperties) throws IOException;
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
    /**
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   642
     * 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
   643
     *
45662
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   644
     * <p> See the online documentation for
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   645
     * {@extLink monitoring_and_management_using_jmx_technology
c6adffba7268 8182596: Fix broken links in com.sun.tools.attach.VirtualMachine
mchung
parents: 34894
diff changeset
   646
     * Monitoring and Management Using JMX Technology} for further details.
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   647
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   648
     * @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
   649
     *          The value can be parsed by the
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   650
     *          {@link javax.management.remote.JMXServiceURL#JMXServiceURL(String)}
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   651
     *          constructor.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   652
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   653
     * @throws  AttachOperationFailedException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   654
     *          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
   655
     *          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
   656
     *          given by {@link AttachOperationFailedException#getMessage()}.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   657
     *
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   658
     * @throws  IOException
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   659
     *          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
   660
     *          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
   661
     *          operation failed in the target VM.
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   662
     *
26453
eb89fa61bc70 8057776: Misc cleanups of the attach code
sla
parents: 25859
diff changeset
   663
     * @since   1.8
24870
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   664
     */
5d567113d043 8044135: Add API to start JMX agent from attach framework
sla
parents: 24363
diff changeset
   665
    public abstract String startLocalManagementAgent() throws IOException;
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
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Returns a hash-code value for this VirtualMachine. The hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * code is based upon the VirtualMachine's components, and satifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * the general contract of the {@link java.lang.Object#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Object.hashCode} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @return  A hash-code value for this virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (hash != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        hash = provider.hashCode() * 127 + id.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Tests this VirtualMachine for equality with another object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <p> If the given object is not a VirtualMachine then this
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   687
     * method returns {@code false}. For two VirtualMachines to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * be considered equal requires that they both reference the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * provider, and their {@link VirtualMachineDescriptor#id() identifiers} are equal. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <p> This method satisfies the general contract of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * java.lang.Object#equals(Object) Object.equals} method. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @param   ob   The object to which this object is to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   696
     * @return  {@code true} if, and only if, the given object is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *                a VirtualMachine that is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *                VirtualMachine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        if (ob == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (!(ob instanceof VirtualMachine))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        VirtualMachine other = (VirtualMachine)ob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (other.provider() != this.provider()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        if (!other.id().equals(this.id())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 26453
diff changeset
   716
     * Returns the string representation of the {@code VirtualMachine}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return provider.toString() + ": " + id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
}