author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 47028 | jdk/src/java.management/share/classes/java/lang/management/MonitorInfo.java@6df65183aa1f |
child 49077 | b1c42b3cd19b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
32034
diff
changeset
|
2 |
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.management; |
|
27 |
||
28 |
import javax.management.openmbean.CompositeData; |
|
29 |
import sun.management.MonitorInfoCompositeData; |
|
30 |
||
31 |
/** |
|
32 |
* Information about an object monitor lock. An object monitor is locked |
|
33 |
* when entering a synchronization block or method on that object. |
|
34 |
* |
|
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
5506
diff
changeset
|
35 |
* <h3>MXBean Mapping</h3> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
36 |
* {@code MonitorInfo} is mapped to a {@link CompositeData CompositeData} |
2 | 37 |
* with attributes as specified in |
38 |
* the {@link #from from} method. |
|
39 |
* |
|
40 |
* @author Mandy Chung |
|
41 |
* @since 1.6 |
|
42 |
*/ |
|
43 |
public class MonitorInfo extends LockInfo { |
|
44 |
||
45 |
private int stackDepth; |
|
46 |
private StackTraceElement stackFrame; |
|
47 |
||
48 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
49 |
* Construct a {@code MonitorInfo} object. |
2 | 50 |
* |
51 |
* @param className the fully qualified name of the class of the lock object. |
|
52 |
* @param identityHashCode the {@link System#identityHashCode |
|
53 |
* identity hash code} of the lock object. |
|
54 |
* @param stackDepth the depth in the stack trace where the object monitor |
|
55 |
* was locked. |
|
56 |
* @param stackFrame the stack frame that locked the object monitor. |
|
57 |
* @throws IllegalArgumentException if |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
58 |
* {@code stackDepth} ≥ 0 but {@code stackFrame} is {@code null}, |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
59 |
* or {@code stackDepth} < 0 but {@code stackFrame} is not |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
60 |
* {@code null}. |
2 | 61 |
*/ |
62 |
public MonitorInfo(String className, |
|
63 |
int identityHashCode, |
|
64 |
int stackDepth, |
|
65 |
StackTraceElement stackFrame) { |
|
66 |
super(className, identityHashCode); |
|
67 |
if (stackDepth >= 0 && stackFrame == null) { |
|
68 |
throw new IllegalArgumentException("Parameter stackDepth is " + |
|
69 |
stackDepth + " but stackFrame is null"); |
|
70 |
} |
|
71 |
if (stackDepth < 0 && stackFrame != null) { |
|
72 |
throw new IllegalArgumentException("Parameter stackDepth is " + |
|
73 |
stackDepth + " but stackFrame is not null"); |
|
74 |
} |
|
75 |
this.stackDepth = stackDepth; |
|
76 |
this.stackFrame = stackFrame; |
|
77 |
} |
|
78 |
||
79 |
/** |
|
80 |
* Returns the depth in the stack trace where the object monitor |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
81 |
* was locked. The depth is the index to the {@code StackTraceElement} |
2 | 82 |
* array returned in the {@link ThreadInfo#getStackTrace} method. |
83 |
* |
|
84 |
* @return the depth in the stack trace where the object monitor |
|
85 |
* was locked, or a negative number if not available. |
|
86 |
*/ |
|
87 |
public int getLockedStackDepth() { |
|
88 |
return stackDepth; |
|
89 |
} |
|
90 |
||
91 |
/** |
|
92 |
* Returns the stack frame that locked the object monitor. |
|
93 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
94 |
* @return {@code StackTraceElement} that locked the object monitor, |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
95 |
* or {@code null} if not available. |
2 | 96 |
*/ |
97 |
public StackTraceElement getLockedStackFrame() { |
|
98 |
return stackFrame; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
102 |
* Returns a {@code MonitorInfo} object represented by the |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
103 |
* given {@code CompositeData}. |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
104 |
* The given {@code CompositeData} must contain the following attributes |
2 | 105 |
* as well as the attributes specified in the |
106 |
* <a href="LockInfo.html#MappedType"> |
|
107 |
* mapped type</a> for the {@link LockInfo} class: |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
108 |
* <table class="striped" style="margin-left:2em"> |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
32034
diff
changeset
|
109 |
* <caption style="display:none">The attributes and their types the given CompositeData contains</caption> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
110 |
* <thead> |
2 | 111 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
112 |
* <th scope="col">Attribute Name</th> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
113 |
* <th scope="col">Type</th> |
2 | 114 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
115 |
* </thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
116 |
* <tbody style="text-align:left"> |
2 | 117 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
118 |
* <th scope="row">lockedStackFrame</th> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
119 |
* <td><code>CompositeData as specified in the |
2 | 120 |
* <a href="ThreadInfo.html#StackTrace">stackTrace</a> |
121 |
* attribute defined in the {@link ThreadInfo#from |
|
122 |
* ThreadInfo.from} method. |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
123 |
* </code></td> |
2 | 124 |
* </tr> |
125 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
126 |
* <th scope="row">lockedStackDepth</th> |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
127 |
* <td>{@code java.lang.Integer}</td> |
2 | 128 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
44858
diff
changeset
|
129 |
* </tbody> |
2 | 130 |
* </table> |
131 |
* |
|
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
132 |
* @param cd {@code CompositeData} representing a {@code MonitorInfo} |
2 | 133 |
* |
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
134 |
* @throws IllegalArgumentException if {@code cd} does not |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
135 |
* represent a {@code MonitorInfo} with the attributes described |
2 | 136 |
* above. |
137 |
||
32034
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
138 |
* @return a {@code MonitorInfo} object represented |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
139 |
* by {@code cd} if {@code cd} is not {@code null}; |
05676cfd40b5
8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents:
25859
diff
changeset
|
140 |
* {@code null} otherwise. |
2 | 141 |
*/ |
142 |
public static MonitorInfo from(CompositeData cd) { |
|
143 |
if (cd == null) { |
|
144 |
return null; |
|
145 |
} |
|
146 |
||
147 |
if (cd instanceof MonitorInfoCompositeData) { |
|
148 |
return ((MonitorInfoCompositeData) cd).getMonitorInfo(); |
|
149 |
} else { |
|
150 |
MonitorInfoCompositeData.validateCompositeData(cd); |
|
151 |
String className = MonitorInfoCompositeData.getClassName(cd); |
|
152 |
int identityHashCode = MonitorInfoCompositeData.getIdentityHashCode(cd); |
|
153 |
int stackDepth = MonitorInfoCompositeData.getLockedStackDepth(cd); |
|
154 |
StackTraceElement stackFrame = MonitorInfoCompositeData.getLockedStackFrame(cd); |
|
155 |
return new MonitorInfo(className, |
|
156 |
identityHashCode, |
|
157 |
stackDepth, |
|
158 |
stackFrame); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
} |