0N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.lang.management;
0N/A
0N/Aimport javax.management.openmbean.CompositeData;
0N/Aimport sun.management.MonitorInfoCompositeData;
0N/A
0N/A/**
0N/A * Information about an object monitor lock. An object monitor is locked
0N/A * when entering a synchronization block or method on that object.
0N/A *
0N/A * <h4>MXBean Mapping</h4>
0N/A * <tt>MonitorInfo</tt> is mapped to a {@link CompositeData CompositeData}
0N/A * with attributes as specified in
0N/A * the {@link #from from} method.
0N/A *
0N/A * @author Mandy Chung
0N/A * @since 1.6
0N/A */
0N/Apublic class MonitorInfo extends LockInfo {
0N/A
0N/A private int stackDepth;
0N/A private StackTraceElement stackFrame;
0N/A
0N/A /**
0N/A * Construct a <tt>MonitorInfo</tt> object.
0N/A *
0N/A * @param className the fully qualified name of the class of the lock object.
0N/A * @param identityHashCode the {@link System#identityHashCode
0N/A * identity hash code} of the lock object.
0N/A * @param stackDepth the depth in the stack trace where the object monitor
0N/A * was locked.
0N/A * @param stackFrame the stack frame that locked the object monitor.
0N/A * @throws IllegalArgumentException if
0N/A * <tt>stackDepth</tt> &ge; 0 but <tt>stackFrame</tt> is <tt>null</tt>,
0N/A * or <tt>stackDepth</tt> &lt; 0 but <tt>stackFrame</tt> is not
0N/A * <tt>null</tt>.
0N/A */
0N/A public MonitorInfo(String className,
0N/A int identityHashCode,
0N/A int stackDepth,
0N/A StackTraceElement stackFrame) {
0N/A super(className, identityHashCode);
0N/A if (stackDepth >= 0 && stackFrame == null) {
0N/A throw new IllegalArgumentException("Parameter stackDepth is " +
0N/A stackDepth + " but stackFrame is null");
0N/A }
0N/A if (stackDepth < 0 && stackFrame != null) {
0N/A throw new IllegalArgumentException("Parameter stackDepth is " +
0N/A stackDepth + " but stackFrame is not null");
0N/A }
0N/A this.stackDepth = stackDepth;
0N/A this.stackFrame = stackFrame;
0N/A }
0N/A
0N/A /**
0N/A * Returns the depth in the stack trace where the object monitor
0N/A * was locked. The depth is the index to the <tt>StackTraceElement</tt>
0N/A * array returned in the {@link ThreadInfo#getStackTrace} method.
0N/A *
0N/A * @return the depth in the stack trace where the object monitor
0N/A * was locked, or a negative number if not available.
0N/A */
0N/A public int getLockedStackDepth() {
0N/A return stackDepth;
0N/A }
0N/A
0N/A /**
0N/A * Returns the stack frame that locked the object monitor.
0N/A *
0N/A * @return <tt>StackTraceElement</tt> that locked the object monitor,
0N/A * or <tt>null</tt> if not available.
0N/A */
0N/A public StackTraceElement getLockedStackFrame() {
0N/A return stackFrame;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <tt>MonitorInfo</tt> object represented by the
0N/A * given <tt>CompositeData</tt>.
0N/A * The given <tt>CompositeData</tt> must contain the following attributes
0N/A * as well as the attributes specified in the
0N/A * <a href="LockInfo.html#MappedType">
0N/A * mapped type</a> for the {@link LockInfo} class:
0N/A * <blockquote>
0N/A * <table border>
0N/A * <tr>
0N/A * <th align=left>Attribute Name</th>
0N/A * <th align=left>Type</th>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>lockedStackFrame</td>
0N/A * <td><tt>CompositeData as specified in the
0N/A * <a href="ThreadInfo.html#StackTrace">stackTrace</a>
0N/A * attribute defined in the {@link ThreadInfo#from
0N/A * ThreadInfo.from} method.
0N/A * </tt></td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>lockedStackDepth</td>
0N/A * <td><tt>java.lang.Integer</tt></td>
0N/A * </tr>
0N/A * </table>
0N/A * </blockquote>
0N/A *
0N/A * @param cd <tt>CompositeData</tt> representing a <tt>MonitorInfo</tt>
0N/A *
0N/A * @throws IllegalArgumentException if <tt>cd</tt> does not
0N/A * represent a <tt>MonitorInfo</tt> with the attributes described
0N/A * above.
0N/A
0N/A * @return a <tt>MonitorInfo</tt> object represented
0N/A * by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
0N/A * <tt>null</tt> otherwise.
0N/A */
0N/A public static MonitorInfo from(CompositeData cd) {
0N/A if (cd == null) {
0N/A return null;
0N/A }
0N/A
0N/A if (cd instanceof MonitorInfoCompositeData) {
0N/A return ((MonitorInfoCompositeData) cd).getMonitorInfo();
0N/A } else {
0N/A MonitorInfoCompositeData.validateCompositeData(cd);
0N/A String className = MonitorInfoCompositeData.getClassName(cd);
0N/A int identityHashCode = MonitorInfoCompositeData.getIdentityHashCode(cd);
0N/A int stackDepth = MonitorInfoCompositeData.getLockedStackDepth(cd);
0N/A StackTraceElement stackFrame = MonitorInfoCompositeData.getLockedStackFrame(cd);
0N/A return new MonitorInfo(className,
0N/A identityHashCode,
0N/A stackDepth,
0N/A stackFrame);
0N/A }
0N/A }
0N/A
0N/A}