jdk/src/share/classes/java/lang/management/MonitorInfo.java
author jfranck
Mon, 30 Sep 2013 11:18:18 +0200
changeset 20481 2735b307d256
parent 18799 31062cb3cc8e
permissions -rw-r--r--
8007072: Update Core Reflection for Type Annotations to match latest spec 8022324: j.l.Class.getAnnotatedInterfaces() for array type returns wrong value 8024915: j.l.r.Executable.getAnnotatedReceiverType() should return null for static methods Summary: Update javadoc and implementation of reflection for type annotations to match latest spec Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 5506
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 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 sun.management.MonitorInfoCompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Information about an object monitor lock.  An object monitor is locked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * when entering a synchronization block or method on that object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 5506
diff changeset
    35
 * <h3>MXBean Mapping</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <tt>MonitorInfo</tt> is mapped to a {@link CompositeData CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * with attributes as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the {@link #from from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class MonitorInfo extends LockInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private int    stackDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private StackTraceElement stackFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Construct a <tt>MonitorInfo</tt> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @param className the fully qualified name of the class of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @param identityHashCode the {@link System#identityHashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *                         identity hash code} of the lock object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @param stackDepth the depth in the stack trace where the object monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *                   was locked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param stackFrame the stack frame that locked the object monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *    <tt>stackDepth</tt> &ge; 0 but <tt>stackFrame</tt> is <tt>null</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *    or <tt>stackDepth</tt> &lt; 0 but <tt>stackFrame</tt> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *       <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public MonitorInfo(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                       int identityHashCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                       int stackDepth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                       StackTraceElement stackFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        super(className, identityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (stackDepth >= 0 && stackFrame == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new IllegalArgumentException("Parameter stackDepth is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                stackDepth + " but stackFrame is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (stackDepth < 0 && stackFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            throw new IllegalArgumentException("Parameter stackDepth is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                stackDepth + " but stackFrame is not null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.stackDepth = stackDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.stackFrame = stackFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the depth in the stack trace where the object monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * was locked.  The depth is the index to the <tt>StackTraceElement</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * array returned in the {@link ThreadInfo#getStackTrace} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @return the depth in the stack trace where the object monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *         was locked, or a negative number if not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public int getLockedStackDepth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return stackDepth;
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
     * Returns the stack frame that locked the object monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return <tt>StackTraceElement</tt> that locked the object monitor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *         or <tt>null</tt> if not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public StackTraceElement getLockedStackFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return stackFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns a <tt>MonitorInfo</tt> object represented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * given <tt>CompositeData</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The given <tt>CompositeData</tt> must contain the following attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * as well as the attributes specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <a href="LockInfo.html#MappedType">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * mapped type</a> for the {@link LockInfo} class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <blockquote>
18799
31062cb3cc8e 8020308: Fix doclint issues in java.lang.management
sspitsyn
parents: 5506
diff changeset
   109
     * <table border summary="The attributes and their types the given CompositeData contains">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *   <th align=left>Attribute Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *   <th align=left>Type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *   <td>lockedStackFrame</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *   <td><tt>CompositeData as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *       <a href="ThreadInfo.html#StackTrace">stackTrace</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *       attribute defined in the {@link ThreadInfo#from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *       ThreadInfo.from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *       </tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *   <td>lockedStackDepth</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *   <td><tt>java.lang.Integer</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param cd <tt>CompositeData</tt> representing a <tt>MonitorInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @throws IllegalArgumentException if <tt>cd</tt> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *   represent a <tt>MonitorInfo</tt> with the attributes described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *   above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @return a <tt>MonitorInfo</tt> object represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *         by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         <tt>null</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static MonitorInfo from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (cd instanceof MonitorInfoCompositeData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return ((MonitorInfoCompositeData) cd).getMonitorInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            MonitorInfoCompositeData.validateCompositeData(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            String className = MonitorInfoCompositeData.getClassName(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            int identityHashCode = MonitorInfoCompositeData.getIdentityHashCode(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            int stackDepth = MonitorInfoCompositeData.getLockedStackDepth(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            StackTraceElement stackFrame = MonitorInfoCompositeData.getLockedStackFrame(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return new MonitorInfo(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                   identityHashCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                   stackDepth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                   stackFrame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}