src/jdk.attach/share/classes/com/sun/tools/attach/VirtualMachineDescriptor.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20742
diff changeset
     2
 * Copyright (c) 2005, 2013, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Describes a Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    33
 * <p> A {@code VirtualMachineDescriptor} is a container class used to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * describe a Java virtual machine. It encapsulates an identifier that identifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * a target virtual machine, and a reference to the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * com.sun.tools.attach.spi.AttachProvider AttachProvider} that should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * when attempting to attach to the virtual machine. The identifier is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * implementation-dependent but is typically the process identifier (or pid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * environments where each Java virtual machine runs in its own operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * process. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    42
 * <p> A {@code VirtualMachineDescriptor} also has a {@link #displayName() displayName}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The display name is typically a human readable string that a tool might
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * display to a user. For example, a tool that shows a list of Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * virtual machines running on a system might use the display name rather
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    46
 * than the identifier. A {@code VirtualMachineDescriptor} may be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * created without a <i>display name</i>. In that case the identifier is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * used as the <i>display name</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    50
 * <p> {@code VirtualMachineDescriptor} instances are typically created by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * invoking the {@link com.sun.tools.attach.VirtualMachine#list VirtualMachine.list()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * method. This returns the complete list of descriptors to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Java virtual machines known to all installed {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * com.sun.tools.attach.spi.AttachProvider attach providers}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class VirtualMachineDescriptor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private AttachProvider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private String displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private volatile int hash;        // 0 => not computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Creates a virtual machine descriptor from the given components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param   provider      The AttachProvider to attach to the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param   id            The virtual machine identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param   displayName   The display name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    74
     *          If any of the arguments are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (provider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new NullPointerException("provider cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (id == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw new NullPointerException("identifier cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (displayName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new NullPointerException("display name cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this.displayName = displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Creates a virtual machine descriptor from the given components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <p> This convenience constructor works as if by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * three-argument constructor as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
    97
     * <blockquote><code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * new&nbsp;{@link #VirtualMachineDescriptor(AttachProvider, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * VirtualMachineDescriptor}(provider, &nbsp;id, &nbsp;id);
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   100
     * </code></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <p> That is, it creates a virtual machine descriptor such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * the <i>display name</i> is the same as the virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param   provider      The AttachProvider to attach to the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param   id            The virtual machine identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws  NullPointerException
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   110
     *          If {@code provider} or {@code id} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public VirtualMachineDescriptor(AttachProvider provider, String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this(provider, id, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   117
     * Return the {@code AttachProvider} that this descriptor references.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   119
     * @return The {@code AttachProvider} that this descriptor references.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public AttachProvider provider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Return the identifier component of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return  The identifier component of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public String id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Return the <i>display name</i> component of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return  The display name component of this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public String displayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns a hash-code value for this VirtualMachineDescriptor. The hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * code is based upon the descriptor's components, and satifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the general contract of the {@link java.lang.Object#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Object.hashCode} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return  A hash-code value for this descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (hash != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        hash = provider.hashCode() * 127 + id.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Tests this VirtualMachineDescriptor for equality with another object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <p> If the given object is not a VirtualMachineDescriptor then this
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   163
     * method returns {@code false}. For two VirtualMachineDescriptors to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * be considered equal requires that they both reference the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * provider, and their {@link #id() identifiers} are equal. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p> This method satisfies the general contract of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * java.lang.Object#equals(Object) Object.equals} method. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param   ob   The object to which this object is to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   172
     * @return  {@code true} if, and only if, the given object is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *                a VirtualMachineDescriptor that is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *                VirtualMachineDescriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (ob == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (!(ob instanceof VirtualMachineDescriptor))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        VirtualMachineDescriptor other = (VirtualMachineDescriptor)ob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (other.provider() != this.provider()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (!other.id().equals(this.id())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 25859
diff changeset
   192
     * Returns the string representation of the {@code VirtualMachineDescriptor}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        String s = provider.toString() + ": " + id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (displayName != id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            s += " " + displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}