author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 25859 | jdk/src/java.management/share/classes/sun/management/MonitorInfoCompositeData.java@3317bb8137f4 |
child 49077 | b1c42b3cd19b |
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) 2005, 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.MonitorInfo; |
|
29 |
import javax.management.openmbean.CompositeType; |
|
30 |
import javax.management.openmbean.CompositeData; |
|
31 |
import javax.management.openmbean.CompositeDataSupport; |
|
32 |
import javax.management.openmbean.OpenDataException; |
|
33 |
import java.util.Set; |
|
34 |
||
35 |
/** |
|
36 |
* A CompositeData for MonitorInfo for the local management support. |
|
37 |
* This class avoids the performance penalty paid to the |
|
38 |
* construction of a CompositeData use in the local case. |
|
39 |
*/ |
|
40 |
public class MonitorInfoCompositeData extends LazyCompositeData { |
|
41 |
private final MonitorInfo lock; |
|
42 |
||
43 |
private MonitorInfoCompositeData(MonitorInfo mi) { |
|
44 |
this.lock = mi; |
|
45 |
} |
|
46 |
||
47 |
public MonitorInfo getMonitorInfo() { |
|
48 |
return lock; |
|
49 |
} |
|
50 |
||
51 |
public static CompositeData toCompositeData(MonitorInfo mi) { |
|
52 |
MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi); |
|
53 |
return micd.getCompositeData(); |
|
54 |
} |
|
55 |
||
56 |
protected CompositeData getCompositeData() { |
|
57 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
58 |
// monitorInfoItemNames! |
|
59 |
||
60 |
int len = monitorInfoItemNames.length; |
|
61 |
Object[] values = new Object[len]; |
|
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
11530
diff
changeset
|
62 |
CompositeData li = LockInfoCompositeData.toCompositeData(lock); |
2 | 63 |
|
64 |
for (int i = 0; i < len; i++) { |
|
65 |
String item = monitorInfoItemNames[i]; |
|
66 |
if (item.equals(LOCKED_STACK_FRAME)) { |
|
67 |
StackTraceElement ste = lock.getLockedStackFrame(); |
|
68 |
values[i] = (ste != null ? StackTraceElementCompositeData. |
|
69 |
toCompositeData(ste) |
|
70 |
: null); |
|
71 |
} else if (item.equals(LOCKED_STACK_DEPTH)) { |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
14342
diff
changeset
|
72 |
values[i] = lock.getLockedStackDepth(); |
2 | 73 |
} else { |
74 |
values[i] = li.get(item); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
try { |
|
79 |
return new CompositeDataSupport(monitorInfoCompositeType, |
|
80 |
monitorInfoItemNames, |
|
81 |
values); |
|
82 |
} catch (OpenDataException e) { |
|
83 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
84 |
throw new AssertionError(e); |
2 | 85 |
} |
86 |
} |
|
87 |
||
88 |
private static final CompositeType monitorInfoCompositeType; |
|
89 |
private static final String[] monitorInfoItemNames; |
|
90 |
static { |
|
91 |
try { |
|
92 |
monitorInfoCompositeType = (CompositeType) |
|
93 |
MappedMXBeanType.toOpenType(MonitorInfo.class); |
|
94 |
Set<String> s = monitorInfoCompositeType.keySet(); |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
95 |
monitorInfoItemNames = s.toArray(new String[0]); |
2 | 96 |
} catch (OpenDataException e) { |
97 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
98 |
throw new AssertionError(e); |
2 | 99 |
} |
100 |
} |
|
101 |
||
102 |
static CompositeType getMonitorInfoCompositeType() { |
|
103 |
return monitorInfoCompositeType; |
|
104 |
} |
|
105 |
||
106 |
private static final String CLASS_NAME = "className"; |
|
107 |
private static final String IDENTITY_HASH_CODE = "identityHashCode"; |
|
108 |
private static final String LOCKED_STACK_FRAME = "lockedStackFrame"; |
|
109 |
private static final String LOCKED_STACK_DEPTH = "lockedStackDepth"; |
|
110 |
||
111 |
public static String getClassName(CompositeData cd) { |
|
112 |
return getString(cd, CLASS_NAME); |
|
113 |
} |
|
114 |
||
115 |
public static int getIdentityHashCode(CompositeData cd) { |
|
116 |
return getInt(cd, IDENTITY_HASH_CODE); |
|
117 |
} |
|
118 |
||
119 |
public static StackTraceElement getLockedStackFrame(CompositeData cd) { |
|
120 |
CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME); |
|
121 |
if (ste != null) { |
|
122 |
return StackTraceElementCompositeData.from(ste); |
|
123 |
} else { |
|
124 |
return null; |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
public static int getLockedStackDepth(CompositeData cd) { |
|
129 |
return getInt(cd, LOCKED_STACK_DEPTH); |
|
130 |
} |
|
131 |
||
132 |
/** Validate if the input CompositeData has the expected |
|
133 |
* CompositeType (i.e. contain all attributes with expected |
|
134 |
* names and types). |
|
135 |
*/ |
|
136 |
public static void validateCompositeData(CompositeData cd) { |
|
137 |
if (cd == null) { |
|
138 |
throw new NullPointerException("Null CompositeData"); |
|
139 |
} |
|
140 |
||
141 |
if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) { |
|
142 |
throw new IllegalArgumentException( |
|
143 |
"Unexpected composite type for MonitorInfo"); |
|
144 |
} |
|
145 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
146 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
147 |
private static final long serialVersionUID = -5825215591822908529L; |
2 | 148 |
} |