Path: blob/master/jcl/src/java.management/share/classes/java/lang/management/LockInfo.java
12513 views
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/1/*2*******************************************************************************3* Copyright (c) 2008, 2022 IBM Corp. and others4*5* This program and the accompanying materials are made available under6* the terms of the Eclipse Public License 2.0 which accompanies this7* distribution and is available at https://www.eclipse.org/legal/epl-2.0/8* or the Apache License, Version 2.0 which accompanies this distribution and9* is available at https://www.apache.org/licenses/LICENSE-2.0.10*11* This Source Code may also be made available under the following12* Secondary Licenses when the conditions for such availability set13* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU14* General Public License, version 2 with the GNU Classpath15* Exception [1] and GNU General Public License, version 2 with the16* OpenJDK Assembly Exception [2].17*18* [1] https://www.gnu.org/software/classpath/license.html19* [2] http://openjdk.java.net/legal/assembly-exception.html20*21* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception22*******************************************************************************/23package java.lang.management;2425import javax.management.openmbean.CompositeData;2627import com.ibm.java.lang.management.internal.ManagementUtils;2829import openj9.management.internal.LockInfoBase;3031/**32* This class represents information about locked objects.33*34* @since 1.635*/36public class LockInfo {3738/**39* Container for the actual data from the native method40*/41private final LockInfoBase baseInfo;4243/**44* Creates a new <code>LockInfo</code> instance.45*46* @param className47* the name (including the package prefix) of the associated lock48* object's class49* @param identityHashCode50* the value of the associated lock object's identity hash code.51* This amounts to the result of calling52* {@link System#identityHashCode(Object)} with the lock object53* as the sole argument.54* @throws NullPointerException55* if <code>className</code> is <code>null</code>56*/57public LockInfo(String className, int identityHashCode) {58baseInfo = new LockInfoBase(className, identityHashCode);59}6061/**62* Constructor for use by subclasses63* @param base base data64*/65LockInfo(LockInfoBase base) {66baseInfo = base;67}6869/**70* Returns the name of the lock object's class in fully qualified form (i.e.71* including the package prefix).72*73* @return the associated lock object's class name74*/75public String getClassName() {76return baseInfo.getClassName();77}7879/**80* Returns the value of the associated lock object's identity hash code81*82* @return the identity hash code of the lock object83*/84public int getIdentityHashCode() {85return baseInfo.getIdentityHashCode();86}8788/**89* Returns a {@code LockInfo} object represented by the given90* {@code CompositeData}. The given {@code CompositeData} must contain the91* following attributes: <blockquote>92* <table>93* <caption>The attributes and the types the given CompositeData contains</caption>94* <tr>95* <th style="float:left">Attribute Name</th>96* <th style="float:left">Type</th>97* </tr>98* <tr>99* <td>className</td>100* <td><code>java.lang.String</code></td>101* </tr>102* <tr>103* <td>identityHashCode</td>104* <td><code>java.lang.Integer</code></td>105* </tr>106* </table>107* </blockquote>108*109* @param compositeData110* {@code CompositeData} representing a {@code LockInfo}111* @throws IllegalArgumentException112* if {@code compositeData} does not represent a {@code LockInfo} with the113* attributes described above.114* @return a {@code LockInfo} object represented by {@code compositeData} if {@code compositeData}115* is not {@code null}; {@code null} otherwise.116*117* @since 1.8118*/119public static LockInfo from(CompositeData compositeData) {120LockInfo element = null;121122if (compositeData != null) {123// Verify the element124ManagementUtils.verifyFieldNumber(compositeData, 2);125String[] attributeNames = { "className", "identityHashCode" }; //$NON-NLS-1$ //$NON-NLS-2$126ManagementUtils.verifyFieldNames(compositeData, attributeNames);127String[] attributeTypes = { "java.lang.String", "java.lang.Integer" }; //$NON-NLS-1$ //$NON-NLS-2$128ManagementUtils.verifyFieldTypes(compositeData, attributeNames, attributeTypes);129130// Get hold of the values from the data object to use in the131// creation of a new LockInfo.132Object[] attributeVals = compositeData.getAll(attributeNames);133String className = (String) attributeVals[0];134int idHashCode = ((Integer) attributeVals[1]).intValue();135136element = new LockInfo(className, idHashCode);137}138139return element;140}141142/**143* Provides callers with a string value that represents the associated lock.144* The string will hold both the name of the lock object's class and it's145* identity hash code expressed as an unsigned hexadecimal. i.e.<br>146* <p>147* {@link #getClassName()} + @ + Integer.toHexString({@link #getIdentityHashCode()})148* </p>149*150* @return a string containing the key details of the lock151*/152@Override153public String toString() {154return baseInfo.toString();155}156157LockInfoBase getBaseInfo() {158return baseInfo;159}160161}162163164