Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.management/share/classes/java/lang/management/LockInfo.java
12513 views
1
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 8]*/
2
/*
3
*******************************************************************************
4
* Copyright (c) 2008, 2022 IBM Corp. and others
5
*
6
* This program and the accompanying materials are made available under
7
* the terms of the Eclipse Public License 2.0 which accompanies this
8
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
9
* or the Apache License, Version 2.0 which accompanies this distribution and
10
* is available at https://www.apache.org/licenses/LICENSE-2.0.
11
*
12
* This Source Code may also be made available under the following
13
* Secondary Licenses when the conditions for such availability set
14
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
15
* General Public License, version 2 with the GNU Classpath
16
* Exception [1] and GNU General Public License, version 2 with the
17
* OpenJDK Assembly Exception [2].
18
*
19
* [1] https://www.gnu.org/software/classpath/license.html
20
* [2] http://openjdk.java.net/legal/assembly-exception.html
21
*
22
* 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-exception
23
*******************************************************************************/
24
package java.lang.management;
25
26
import javax.management.openmbean.CompositeData;
27
28
import com.ibm.java.lang.management.internal.ManagementUtils;
29
30
import openj9.management.internal.LockInfoBase;
31
32
/**
33
* This class represents information about locked objects.
34
*
35
* @since 1.6
36
*/
37
public class LockInfo {
38
39
/**
40
* Container for the actual data from the native method
41
*/
42
private final LockInfoBase baseInfo;
43
44
/**
45
* Creates a new <code>LockInfo</code> instance.
46
*
47
* @param className
48
* the name (including the package prefix) of the associated lock
49
* object's class
50
* @param identityHashCode
51
* the value of the associated lock object's identity hash code.
52
* This amounts to the result of calling
53
* {@link System#identityHashCode(Object)} with the lock object
54
* as the sole argument.
55
* @throws NullPointerException
56
* if <code>className</code> is <code>null</code>
57
*/
58
public LockInfo(String className, int identityHashCode) {
59
baseInfo = new LockInfoBase(className, identityHashCode);
60
}
61
62
/**
63
* Constructor for use by subclasses
64
* @param base base data
65
*/
66
LockInfo(LockInfoBase base) {
67
baseInfo = base;
68
}
69
70
/**
71
* Returns the name of the lock object's class in fully qualified form (i.e.
72
* including the package prefix).
73
*
74
* @return the associated lock object's class name
75
*/
76
public String getClassName() {
77
return baseInfo.getClassName();
78
}
79
80
/**
81
* Returns the value of the associated lock object's identity hash code
82
*
83
* @return the identity hash code of the lock object
84
*/
85
public int getIdentityHashCode() {
86
return baseInfo.getIdentityHashCode();
87
}
88
89
/**
90
* Returns a {@code LockInfo} object represented by the given
91
* {@code CompositeData}. The given {@code CompositeData} must contain the
92
* following attributes: <blockquote>
93
* <table>
94
* <caption>The attributes and the types the given CompositeData contains</caption>
95
* <tr>
96
* <th style="float:left">Attribute Name</th>
97
* <th style="float:left">Type</th>
98
* </tr>
99
* <tr>
100
* <td>className</td>
101
* <td><code>java.lang.String</code></td>
102
* </tr>
103
* <tr>
104
* <td>identityHashCode</td>
105
* <td><code>java.lang.Integer</code></td>
106
* </tr>
107
* </table>
108
* </blockquote>
109
*
110
* @param compositeData
111
* {@code CompositeData} representing a {@code LockInfo}
112
* @throws IllegalArgumentException
113
* if {@code compositeData} does not represent a {@code LockInfo} with the
114
* attributes described above.
115
* @return a {@code LockInfo} object represented by {@code compositeData} if {@code compositeData}
116
* is not {@code null}; {@code null} otherwise.
117
*
118
* @since 1.8
119
*/
120
public static LockInfo from(CompositeData compositeData) {
121
LockInfo element = null;
122
123
if (compositeData != null) {
124
// Verify the element
125
ManagementUtils.verifyFieldNumber(compositeData, 2);
126
String[] attributeNames = { "className", "identityHashCode" }; //$NON-NLS-1$ //$NON-NLS-2$
127
ManagementUtils.verifyFieldNames(compositeData, attributeNames);
128
String[] attributeTypes = { "java.lang.String", "java.lang.Integer" }; //$NON-NLS-1$ //$NON-NLS-2$
129
ManagementUtils.verifyFieldTypes(compositeData, attributeNames, attributeTypes);
130
131
// Get hold of the values from the data object to use in the
132
// creation of a new LockInfo.
133
Object[] attributeVals = compositeData.getAll(attributeNames);
134
String className = (String) attributeVals[0];
135
int idHashCode = ((Integer) attributeVals[1]).intValue();
136
137
element = new LockInfo(className, idHashCode);
138
}
139
140
return element;
141
}
142
143
/**
144
* Provides callers with a string value that represents the associated lock.
145
* The string will hold both the name of the lock object's class and it's
146
* identity hash code expressed as an unsigned hexadecimal. i.e.<br>
147
* <p>
148
* {@link #getClassName()} &nbsp;+&nbsp;&#64;&nbsp;+&nbsp;Integer.toHexString({@link #getIdentityHashCode()})
149
* </p>
150
*
151
* @return a string containing the key details of the lock
152
*/
153
@Override
154
public String toString() {
155
return baseInfo.toString();
156
}
157
158
LockInfoBase getBaseInfo() {
159
return baseInfo;
160
}
161
162
}
163
164