author | jmanson |
Tue, 24 Feb 2015 09:46:29 +0100 | |
changeset 29101 | 55f7a91aaa32 |
parent 25859 | 3317bb8137f4 |
child 36511 | 9d0388c6b336 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13803
diff
changeset
|
2 |
* Copyright (c) 2004, 2012, 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 sun.management; |
|
27 |
||
28 |
import java.lang.management.ThreadInfo; |
|
29 |
import java.lang.management.MonitorInfo; |
|
30 |
import java.lang.management.LockInfo; |
|
31 |
import javax.management.openmbean.CompositeType; |
|
32 |
import javax.management.openmbean.CompositeData; |
|
33 |
import javax.management.openmbean.CompositeDataSupport; |
|
34 |
import javax.management.openmbean.OpenDataException; |
|
35 |
import javax.management.openmbean.OpenType; |
|
36 |
||
37 |
/** |
|
38 |
* A CompositeData for ThreadInfo for the local management support. |
|
39 |
* This class avoids the performance penalty paid to the |
|
40 |
* construction of a CompositeData use in the local case. |
|
41 |
*/ |
|
42 |
public class ThreadInfoCompositeData extends LazyCompositeData { |
|
43 |
private final ThreadInfo threadInfo; |
|
44 |
private final CompositeData cdata; |
|
45 |
private final boolean currentVersion; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
46 |
private final boolean hasV6; |
2 | 47 |
|
48 |
private ThreadInfoCompositeData(ThreadInfo ti) { |
|
49 |
this.threadInfo = ti; |
|
50 |
this.currentVersion = true; |
|
51 |
this.cdata = null; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
52 |
this.hasV6 = true; |
2 | 53 |
} |
54 |
||
55 |
private ThreadInfoCompositeData(CompositeData cd) { |
|
56 |
this.threadInfo = null; |
|
57 |
this.currentVersion = ThreadInfoCompositeData.isCurrentVersion(cd); |
|
58 |
this.cdata = cd; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
59 |
this.hasV6 = ThreadInfoCompositeData.hasV6(cd); |
2 | 60 |
} |
61 |
||
62 |
public ThreadInfo getThreadInfo() { |
|
63 |
return threadInfo; |
|
64 |
} |
|
65 |
||
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
66 |
public boolean hasV6() { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
67 |
return hasV6; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
68 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
69 |
|
2 | 70 |
public boolean isCurrentVersion() { |
71 |
return currentVersion; |
|
72 |
} |
|
73 |
||
74 |
public static ThreadInfoCompositeData getInstance(CompositeData cd) { |
|
75 |
validateCompositeData(cd); |
|
76 |
return new ThreadInfoCompositeData(cd); |
|
77 |
} |
|
78 |
||
79 |
public static CompositeData toCompositeData(ThreadInfo ti) { |
|
80 |
ThreadInfoCompositeData ticd = new ThreadInfoCompositeData(ti); |
|
81 |
return ticd.getCompositeData(); |
|
82 |
} |
|
83 |
||
84 |
protected CompositeData getCompositeData() { |
|
85 |
// Convert StackTraceElement[] to CompositeData[] |
|
86 |
StackTraceElement[] stackTrace = threadInfo.getStackTrace(); |
|
87 |
CompositeData[] stackTraceData = |
|
88 |
new CompositeData[stackTrace.length]; |
|
89 |
for (int i = 0; i < stackTrace.length; i++) { |
|
90 |
StackTraceElement ste = stackTrace[i]; |
|
91 |
stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste); |
|
92 |
} |
|
93 |
||
94 |
// Convert MonitorInfo[] and LockInfo[] to CompositeData[] |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
95 |
CompositeData lockInfoData = |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
96 |
LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo()); |
2 | 97 |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
98 |
// Convert LockInfo[] and MonitorInfo[] to CompositeData[] |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
99 |
LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers(); |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
100 |
CompositeData[] lockedSyncsData = |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
101 |
new CompositeData[lockedSyncs.length]; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
102 |
for (int i = 0; i < lockedSyncs.length; i++) { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
103 |
LockInfo li = lockedSyncs[i]; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
104 |
lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li); |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
105 |
} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
106 |
|
2 | 107 |
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); |
108 |
CompositeData[] lockedMonitorsData = |
|
109 |
new CompositeData[lockedMonitors.length]; |
|
110 |
for (int i = 0; i < lockedMonitors.length; i++) { |
|
111 |
MonitorInfo mi = lockedMonitors[i]; |
|
112 |
lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi); |
|
113 |
} |
|
114 |
||
115 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
116 |
// threadInfoItemNames! |
|
117 |
final Object[] threadInfoItemValues = { |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
118 |
threadInfo.getThreadId(), |
2 | 119 |
threadInfo.getThreadName(), |
120 |
threadInfo.getThreadState().name(), |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
121 |
threadInfo.getBlockedTime(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
122 |
threadInfo.getBlockedCount(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
123 |
threadInfo.getWaitedTime(), |
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
124 |
threadInfo.getWaitedCount(), |
2 | 125 |
lockInfoData, |
126 |
threadInfo.getLockName(), |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
24685
diff
changeset
|
127 |
threadInfo.getLockOwnerId(), |
2 | 128 |
threadInfo.getLockOwnerName(), |
129 |
stackTraceData, |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
14342
diff
changeset
|
130 |
threadInfo.isSuspended(), |
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
14342
diff
changeset
|
131 |
threadInfo.isInNative(), |
2 | 132 |
lockedMonitorsData, |
133 |
lockedSyncsData, |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
134 |
threadInfo.isDaemon(), |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
135 |
threadInfo.getPriority(), |
2 | 136 |
}; |
137 |
||
138 |
try { |
|
139 |
return new CompositeDataSupport(threadInfoCompositeType, |
|
140 |
threadInfoItemNames, |
|
141 |
threadInfoItemValues); |
|
142 |
} catch (OpenDataException e) { |
|
143 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
144 |
throw new AssertionError(e); |
2 | 145 |
} |
146 |
} |
|
147 |
||
148 |
// Attribute names |
|
149 |
private static final String THREAD_ID = "threadId"; |
|
150 |
private static final String THREAD_NAME = "threadName"; |
|
151 |
private static final String THREAD_STATE = "threadState"; |
|
152 |
private static final String BLOCKED_TIME = "blockedTime"; |
|
153 |
private static final String BLOCKED_COUNT = "blockedCount"; |
|
154 |
private static final String WAITED_TIME = "waitedTime"; |
|
155 |
private static final String WAITED_COUNT = "waitedCount"; |
|
156 |
private static final String LOCK_INFO = "lockInfo"; |
|
157 |
private static final String LOCK_NAME = "lockName"; |
|
158 |
private static final String LOCK_OWNER_ID = "lockOwnerId"; |
|
159 |
private static final String LOCK_OWNER_NAME = "lockOwnerName"; |
|
160 |
private static final String STACK_TRACE = "stackTrace"; |
|
161 |
private static final String SUSPENDED = "suspended"; |
|
162 |
private static final String IN_NATIVE = "inNative"; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
163 |
private static final String DAEMON = "daemon"; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
164 |
private static final String PRIORITY = "priority"; |
2 | 165 |
private static final String LOCKED_MONITORS = "lockedMonitors"; |
166 |
private static final String LOCKED_SYNCS = "lockedSynchronizers"; |
|
167 |
||
168 |
private static final String[] threadInfoItemNames = { |
|
169 |
THREAD_ID, |
|
170 |
THREAD_NAME, |
|
171 |
THREAD_STATE, |
|
172 |
BLOCKED_TIME, |
|
173 |
BLOCKED_COUNT, |
|
174 |
WAITED_TIME, |
|
175 |
WAITED_COUNT, |
|
176 |
LOCK_INFO, |
|
177 |
LOCK_NAME, |
|
178 |
LOCK_OWNER_ID, |
|
179 |
LOCK_OWNER_NAME, |
|
180 |
STACK_TRACE, |
|
181 |
SUSPENDED, |
|
182 |
IN_NATIVE, |
|
183 |
LOCKED_MONITORS, |
|
184 |
LOCKED_SYNCS, |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
185 |
DAEMON, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
186 |
PRIORITY, |
2 | 187 |
}; |
188 |
||
189 |
// New attributes added in 6.0 ThreadInfo |
|
190 |
private static final String[] threadInfoV6Attributes = { |
|
191 |
LOCK_INFO, |
|
192 |
LOCKED_MONITORS, |
|
193 |
LOCKED_SYNCS, |
|
194 |
}; |
|
195 |
||
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
196 |
private static final String[] threadInfoV9Attributes = { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
197 |
DAEMON, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
198 |
PRIORITY, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
199 |
}; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
200 |
|
2 | 201 |
// Current version of ThreadInfo |
202 |
private static final CompositeType threadInfoCompositeType; |
|
203 |
// Previous version of ThreadInfo |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
204 |
private static final CompositeType threadInfoV6CompositeType; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
205 |
// Previous-previous version of ThreadInfo |
2 | 206 |
private static final CompositeType threadInfoV5CompositeType; |
207 |
private static final CompositeType lockInfoCompositeType; |
|
208 |
static { |
|
209 |
try { |
|
210 |
threadInfoCompositeType = (CompositeType) |
|
211 |
MappedMXBeanType.toOpenType(ThreadInfo.class); |
|
212 |
// Form a CompositeType for JDK 5.0 ThreadInfo version |
|
213 |
String[] itemNames = |
|
214 |
threadInfoCompositeType.keySet().toArray(new String[0]); |
|
215 |
int numV5Attributes = threadInfoItemNames.length - |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
216 |
threadInfoV6Attributes.length - threadInfoV9Attributes.length; |
2 | 217 |
String[] v5ItemNames = new String[numV5Attributes]; |
218 |
String[] v5ItemDescs = new String[numV5Attributes]; |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
219 |
OpenType<?>[] v5ItemTypes = new OpenType<?>[numV5Attributes]; |
2 | 220 |
int i = 0; |
221 |
for (String n : itemNames) { |
|
222 |
if (isV5Attribute(n)) { |
|
223 |
v5ItemNames[i] = n; |
|
224 |
v5ItemDescs[i] = threadInfoCompositeType.getDescription(n); |
|
225 |
v5ItemTypes[i] = threadInfoCompositeType.getType(n); |
|
226 |
i++; |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
threadInfoV5CompositeType = |
|
231 |
new CompositeType("java.lang.management.ThreadInfo", |
|
232 |
"J2SE 5.0 java.lang.management.ThreadInfo", |
|
233 |
v5ItemNames, |
|
234 |
v5ItemDescs, |
|
235 |
v5ItemTypes); |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
236 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
237 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
238 |
// Form a CompositeType for JDK 6.0 ThreadInfo version |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
239 |
int numV6Attributes = threadInfoItemNames.length - |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
240 |
threadInfoV9Attributes.length; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
241 |
String[] v6ItemNames = new String[numV6Attributes]; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
242 |
String[] v6ItemDescs = new String[numV6Attributes]; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
243 |
OpenType<?>[] v6ItemTypes = new OpenType<?>[numV6Attributes]; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
244 |
i = 0; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
245 |
for (String n : itemNames) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
246 |
if (isV5Attribute(n) || isV6Attribute(n)) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
247 |
v6ItemNames[i] = n; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
248 |
v6ItemDescs[i] = threadInfoCompositeType.getDescription(n); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
249 |
v6ItemTypes[i] = threadInfoCompositeType.getType(n); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
250 |
i++; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
251 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
252 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
253 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
254 |
threadInfoV6CompositeType = |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
255 |
new CompositeType("java.lang.management.ThreadInfo", |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
256 |
"Java SE 6 java.lang.management.ThreadInfo", |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
257 |
v6ItemNames, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
258 |
v6ItemDescs, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
259 |
v6ItemTypes); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
260 |
|
2 | 261 |
} catch (OpenDataException e) { |
262 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
263 |
throw new AssertionError(e); |
2 | 264 |
} |
265 |
||
266 |
// Each CompositeData object has its CompositeType associated |
|
267 |
// with it. So we can get the CompositeType representing LockInfo |
|
268 |
// from a mapped CompositeData for any LockInfo object. |
|
269 |
// Thus we construct a random LockInfo object and pass it |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
270 |
// to LockInfoCompositeData to do the conversion. |
2 | 271 |
Object o = new Object(); |
272 |
LockInfo li = new LockInfo(o.getClass().getName(), |
|
273 |
System.identityHashCode(o)); |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
274 |
CompositeData cd = LockInfoCompositeData.toCompositeData(li); |
2 | 275 |
lockInfoCompositeType = cd.getCompositeType(); |
276 |
} |
|
277 |
||
278 |
private static boolean isV5Attribute(String itemName) { |
|
279 |
for (String n : threadInfoV6Attributes) { |
|
280 |
if (itemName.equals(n)) { |
|
281 |
return false; |
|
282 |
} |
|
283 |
} |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
284 |
for (String n : threadInfoV9Attributes) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
285 |
if (itemName.equals(n)) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
286 |
return false; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
287 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
288 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
289 |
return true; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
290 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
291 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
292 |
private static boolean isV6Attribute(String itemName) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
293 |
for (String n : threadInfoV9Attributes) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
294 |
if (itemName.equals(n)) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
295 |
return false; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
296 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
297 |
} |
2 | 298 |
return true; |
299 |
} |
|
300 |
||
301 |
public static boolean isCurrentVersion(CompositeData cd) { |
|
302 |
if (cd == null) { |
|
303 |
throw new NullPointerException("Null CompositeData"); |
|
304 |
} |
|
305 |
||
306 |
return isTypeMatched(threadInfoCompositeType, cd.getCompositeType()); |
|
307 |
} |
|
308 |
||
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
309 |
private static boolean hasV6(CompositeData cd) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
310 |
if (cd == null) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
311 |
throw new NullPointerException("Null CompositeData"); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
312 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
313 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
314 |
return isTypeMatched(threadInfoCompositeType, cd.getCompositeType()) || |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
315 |
isTypeMatched(threadInfoV6CompositeType, cd.getCompositeType()); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
316 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
317 |
|
2 | 318 |
public long threadId() { |
319 |
return getLong(cdata, THREAD_ID); |
|
320 |
} |
|
321 |
||
322 |
public String threadName() { |
|
323 |
// The ThreadName item cannot be null so we check that |
|
324 |
// it is present with a non-null value. |
|
325 |
String name = getString(cdata, THREAD_NAME); |
|
326 |
if (name == null) { |
|
327 |
throw new IllegalArgumentException("Invalid composite data: " + |
|
328 |
"Attribute " + THREAD_NAME + " has null value"); |
|
329 |
} |
|
330 |
return name; |
|
331 |
} |
|
332 |
||
333 |
public Thread.State threadState() { |
|
334 |
return Thread.State.valueOf(getString(cdata, THREAD_STATE)); |
|
335 |
} |
|
336 |
||
337 |
public long blockedTime() { |
|
338 |
return getLong(cdata, BLOCKED_TIME); |
|
339 |
} |
|
340 |
||
341 |
public long blockedCount() { |
|
342 |
return getLong(cdata, BLOCKED_COUNT); |
|
343 |
} |
|
344 |
||
345 |
public long waitedTime() { |
|
346 |
return getLong(cdata, WAITED_TIME); |
|
347 |
} |
|
348 |
||
349 |
public long waitedCount() { |
|
350 |
return getLong(cdata, WAITED_COUNT); |
|
351 |
} |
|
352 |
||
353 |
public String lockName() { |
|
354 |
// The LockName and LockOwnerName can legitimately be null, |
|
355 |
// we don't bother to check the value |
|
356 |
return getString(cdata, LOCK_NAME); |
|
357 |
} |
|
358 |
||
359 |
public long lockOwnerId() { |
|
360 |
return getLong(cdata, LOCK_OWNER_ID); |
|
361 |
} |
|
362 |
||
363 |
public String lockOwnerName() { |
|
364 |
return getString(cdata, LOCK_OWNER_NAME); |
|
365 |
} |
|
366 |
||
367 |
public boolean suspended() { |
|
368 |
return getBoolean(cdata, SUSPENDED); |
|
369 |
} |
|
370 |
||
371 |
public boolean inNative() { |
|
372 |
return getBoolean(cdata, IN_NATIVE); |
|
373 |
} |
|
374 |
||
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
375 |
public boolean isDaemon() { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
376 |
return getBoolean(cdata, DAEMON); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
377 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
378 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
379 |
public int getPriority(){ |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
380 |
return getInt(cdata, PRIORITY); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
381 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
382 |
|
2 | 383 |
public StackTraceElement[] stackTrace() { |
384 |
CompositeData[] stackTraceData = |
|
385 |
(CompositeData[]) cdata.get(STACK_TRACE); |
|
386 |
||
387 |
// The StackTrace item cannot be null, but if it is we will get |
|
388 |
// a NullPointerException when we ask for its length. |
|
389 |
StackTraceElement[] stackTrace = |
|
390 |
new StackTraceElement[stackTraceData.length]; |
|
391 |
for (int i = 0; i < stackTraceData.length; i++) { |
|
392 |
CompositeData cdi = stackTraceData[i]; |
|
393 |
stackTrace[i] = StackTraceElementCompositeData.from(cdi); |
|
394 |
} |
|
395 |
return stackTrace; |
|
396 |
} |
|
397 |
||
398 |
// 6.0 new attributes |
|
399 |
public LockInfo lockInfo() { |
|
400 |
CompositeData lockInfoData = (CompositeData) cdata.get(LOCK_INFO); |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
401 |
return LockInfo.from(lockInfoData); |
2 | 402 |
} |
403 |
||
404 |
public MonitorInfo[] lockedMonitors() { |
|
405 |
CompositeData[] lockedMonitorsData = |
|
406 |
(CompositeData[]) cdata.get(LOCKED_MONITORS); |
|
407 |
||
408 |
// The LockedMonitors item cannot be null, but if it is we will get |
|
409 |
// a NullPointerException when we ask for its length. |
|
410 |
MonitorInfo[] monitors = |
|
411 |
new MonitorInfo[lockedMonitorsData.length]; |
|
412 |
for (int i = 0; i < lockedMonitorsData.length; i++) { |
|
413 |
CompositeData cdi = lockedMonitorsData[i]; |
|
414 |
monitors[i] = MonitorInfo.from(cdi); |
|
415 |
} |
|
416 |
return monitors; |
|
417 |
} |
|
418 |
||
419 |
public LockInfo[] lockedSynchronizers() { |
|
420 |
CompositeData[] lockedSyncsData = |
|
421 |
(CompositeData[]) cdata.get(LOCKED_SYNCS); |
|
422 |
||
423 |
// The LockedSynchronizers item cannot be null, but if it is we will |
|
424 |
// get a NullPointerException when we ask for its length. |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
425 |
LockInfo[] locks = new LockInfo[lockedSyncsData.length]; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
426 |
for (int i = 0; i < lockedSyncsData.length; i++) { |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
427 |
CompositeData cdi = lockedSyncsData[i]; |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
428 |
locks[i] = LockInfo.from(cdi); |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
429 |
} |
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
430 |
return locks; |
2 | 431 |
} |
432 |
||
433 |
/** Validate if the input CompositeData has the expected |
|
434 |
* CompositeType (i.e. contain all attributes with expected |
|
435 |
* names and types). |
|
436 |
*/ |
|
437 |
public static void validateCompositeData(CompositeData cd) { |
|
438 |
if (cd == null) { |
|
439 |
throw new NullPointerException("Null CompositeData"); |
|
440 |
} |
|
441 |
||
442 |
CompositeType type = cd.getCompositeType(); |
|
443 |
boolean currentVersion = true; |
|
444 |
if (!isTypeMatched(threadInfoCompositeType, type)) { |
|
445 |
currentVersion = false; |
|
446 |
// check if cd is an older version |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
447 |
if (!isTypeMatched(threadInfoV5CompositeType, type) && |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
448 |
!isTypeMatched(threadInfoV6CompositeType, type)) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
449 |
throw new IllegalArgumentException( |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
450 |
"Unexpected composite type for ThreadInfo"); |
2 | 451 |
} |
452 |
} |
|
453 |
||
454 |
CompositeData[] stackTraceData = |
|
455 |
(CompositeData[]) cd.get(STACK_TRACE); |
|
456 |
if (stackTraceData == null) { |
|
457 |
throw new IllegalArgumentException( |
|
458 |
"StackTraceElement[] is missing"); |
|
459 |
} |
|
460 |
if (stackTraceData.length > 0) { |
|
461 |
StackTraceElementCompositeData.validateCompositeData(stackTraceData[0]); |
|
462 |
} |
|
463 |
||
464 |
// validate v6 attributes |
|
465 |
if (currentVersion) { |
|
466 |
CompositeData li = (CompositeData) cd.get(LOCK_INFO); |
|
467 |
if (li != null) { |
|
468 |
if (!isTypeMatched(lockInfoCompositeType, |
|
469 |
li.getCompositeType())) { |
|
470 |
throw new IllegalArgumentException( |
|
471 |
"Unexpected composite type for \"" + |
|
472 |
LOCK_INFO + "\" attribute."); |
|
473 |
} |
|
474 |
} |
|
475 |
||
476 |
CompositeData[] lms = (CompositeData[]) cd.get(LOCKED_MONITORS); |
|
477 |
if (lms == null) { |
|
478 |
throw new IllegalArgumentException("MonitorInfo[] is null"); |
|
479 |
} |
|
480 |
if (lms.length > 0) { |
|
481 |
MonitorInfoCompositeData.validateCompositeData(lms[0]); |
|
482 |
} |
|
483 |
||
484 |
CompositeData[] lsyncs = (CompositeData[]) cd.get(LOCKED_SYNCS); |
|
485 |
if (lsyncs == null) { |
|
486 |
throw new IllegalArgumentException("LockInfo[] is null"); |
|
487 |
} |
|
488 |
if (lsyncs.length > 0) { |
|
489 |
if (!isTypeMatched(lockInfoCompositeType, |
|
490 |
lsyncs[0].getCompositeType())) { |
|
491 |
throw new IllegalArgumentException( |
|
492 |
"Unexpected composite type for \"" + |
|
493 |
LOCKED_SYNCS + "\" attribute."); |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
} |
|
498 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
499 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
500 |
private static final long serialVersionUID = 2464378539119753175L; |
2 | 501 |
} |