src/java.management/share/classes/java/lang/management/LockInfo.java
author mgronlun
Mon, 28 Oct 2019 18:43:04 +0100
branchJEP-349-branch
changeset 58823 6a21dba79b81
parent 55120 b0513c833960
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, 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 java.lang.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.concurrent.locks.*;
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
    30
import sun.management.LockInfoCompositeData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Information about a <em>lock</em>.  A lock can be a built-in object monitor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * an <em>ownable synchronizer</em>, or the {@link Condition Condition}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * object associated with synchronizers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
44858
7183899b064b 8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents: 44551
diff changeset
    37
 * <a id="OwnableSynchronizer">An ownable synchronizer</a> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a synchronizer that may be exclusively owned by a thread and uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * {@link AbstractOwnableSynchronizer AbstractOwnableSynchronizer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * (or its subclass) to implement its synchronization property.
44551
353956d2e327 8176204: [DOC] ThreadMXBean Fails to Detect ReentrantReadWriteLock Deadlock
asapre
parents: 32034
diff changeset
    41
 * {@link ReentrantLock ReentrantLock} and the write-lock (but not
353956d2e327 8176204: [DOC] ThreadMXBean Fails to Detect ReentrantReadWriteLock Deadlock
asapre
parents: 32034
diff changeset
    42
 * the read-lock) of {@link ReentrantReadWriteLock ReentrantReadWriteLock} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * two examples of ownable synchronizers provided by the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
55120
b0513c833960 8220251: fix headings in java.management
jjg
parents: 47216
diff changeset
    45
 * <h2><a id="MappedType">MXBean Mapping</a></h2>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    46
 * {@code LockInfo} is mapped to a {@link CompositeData CompositeData}
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
    47
 * as specified in the {@link #from from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see java.util.concurrent.locks.AbstractOwnableSynchronizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see java.util.concurrent.locks.Condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class LockInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private int    identityHashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    62
     * Constructs a {@code LockInfo} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param className the fully qualified name of the class of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param identityHashCode the {@link System#identityHashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *                         identity hash code} of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public LockInfo(String className, int identityHashCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new NullPointerException("Parameter className cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.identityHashCode = identityHashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * package-private constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    LockInfo(Object lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        this.identityHashCode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Returns the fully qualified name of the class of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @return the fully qualified name of the class of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Returns the identity hash code of the lock object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * returned from the {@link System#identityHashCode} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return the identity hash code of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public int getIdentityHashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return identityHashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   104
     * Returns a {@code LockInfo} object represented by the
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   105
     * given {@code CompositeData}.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   106
     * The given {@code CompositeData} must contain the following attributes:
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   107
     * <table class="striped" style="margin-left:2em;">
44858
7183899b064b 8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents: 44551
diff changeset
   108
     * <caption style="display:none">The attributes and the types the given CompositeData contains</caption>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   109
     * <thead style="text-align:left">
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   110
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   111
     *   <th scope="col">Attribute Name</th>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   112
     *   <th scope="col">Type</th>
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   113
     * </tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   114
     * </thead>
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   115
     * <tbody style="text-align:left">
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   116
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   117
     *   <th scope="row">className</th>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   118
     *   <td>{@code java.lang.String}</td>
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   119
     * </tr>
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   120
     * <tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   121
     *   <th scope="row">identityHashCode</th>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   122
     *   <td>{@code java.lang.Integer}</td>
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   123
     * </tr>
47028
6df65183aa1f 8186932: Fix accessibility issues in the java.management module
jjg
parents: 44858
diff changeset
   124
     * </tbody>
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   125
     * </table>
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   126
     *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   127
     * @param cd {@code CompositeData} representing a {@code LockInfo}
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   128
     *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   129
     * @throws IllegalArgumentException if {@code cd} does not
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   130
     *   represent a {@code LockInfo} with the attributes described
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   131
     *   above.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   132
     * @return a {@code LockInfo} object represented
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   133
     *         by {@code cd} if {@code cd} is not {@code null};
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   134
     *         {@code null} otherwise.
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   135
     *
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   136
     * @since 1.8
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   137
     */
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   138
    public static LockInfo from(CompositeData cd) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   139
        if (cd == null) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   140
            return null;
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   141
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   142
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   143
        if (cd instanceof LockInfoCompositeData) {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   144
            return ((LockInfoCompositeData) cd).getLockInfo();
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   145
        } else {
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   146
            return LockInfoCompositeData.toLockInfo(cd);
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   147
        }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   148
    }
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   149
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   150
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns a string representation of a lock.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * string representation consists of the name of the class of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * lock object, the at-sign character `@', and the unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * hexadecimal representation of the <em>identity</em> hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * of the object.  This method returns a string equals to the value of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * lock.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(lock))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * </pre></blockquote>
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   160
     * where {@code lock} is the lock object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the string representation of a lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return className + '@' + Integer.toHexString(identityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}