author | mchung |
Thu, 25 Oct 2018 10:57:42 -0700 | |
changeset 52288 | 2b29df6dfa68 |
parent 49077 | b1c42b3cd19b |
child 58766 | 54ffb15c4839 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 2018, 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; |
|
52288
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
29 |
import java.util.HashMap; |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
30 |
import java.util.Map; |
2 | 31 |
import javax.management.openmbean.CompositeType; |
32 |
import javax.management.openmbean.CompositeData; |
|
33 |
import javax.management.openmbean.CompositeDataSupport; |
|
34 |
import javax.management.openmbean.OpenDataException; |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
35 |
import javax.management.openmbean.OpenType; |
2 | 36 |
|
37 |
/** |
|
38 |
* A CompositeData for MonitorInfo 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 MonitorInfoCompositeData extends LazyCompositeData { |
|
43 |
private final MonitorInfo lock; |
|
44 |
||
45 |
private MonitorInfoCompositeData(MonitorInfo mi) { |
|
46 |
this.lock = mi; |
|
47 |
} |
|
48 |
||
49 |
public MonitorInfo getMonitorInfo() { |
|
50 |
return lock; |
|
51 |
} |
|
52 |
||
53 |
public static CompositeData toCompositeData(MonitorInfo mi) { |
|
54 |
MonitorInfoCompositeData micd = new MonitorInfoCompositeData(mi); |
|
55 |
return micd.getCompositeData(); |
|
56 |
} |
|
57 |
||
58 |
protected CompositeData getCompositeData() { |
|
52288
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
59 |
StackTraceElement ste = lock.getLockedStackFrame(); |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
60 |
CompositeData steCData = ste != null ? StackTraceElementCompositeData.toCompositeData(ste) |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
61 |
: null; |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
62 |
// values may be null; can't use Map.of |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
63 |
Map<String,Object> items = new HashMap<>(); |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
64 |
items.put(CLASS_NAME, lock.getClassName()); |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
65 |
items.put(IDENTITY_HASH_CODE, lock.getIdentityHashCode()); |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
66 |
items.put(LOCKED_STACK_FRAME, steCData); |
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
67 |
items.put(LOCKED_STACK_DEPTH, lock.getLockedStackDepth()); |
2 | 68 |
|
69 |
try { |
|
52288
2b29df6dfa68
8212795: ThreadInfoCompositeData.toCompositeData fails to map ThreadInfo to CompositeData
mchung
parents:
49077
diff
changeset
|
70 |
return new CompositeDataSupport(MONITOR_INFO_COMPOSITE_TYPE, items); |
2 | 71 |
} catch (OpenDataException e) { |
72 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
73 |
throw new AssertionError(e); |
2 | 74 |
} |
75 |
} |
|
76 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
77 |
private static final String CLASS_NAME = "className"; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
78 |
private static final String IDENTITY_HASH_CODE = "identityHashCode"; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
79 |
private static final String LOCKED_STACK_FRAME = "lockedStackFrame"; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
80 |
private static final String LOCKED_STACK_DEPTH = "lockedStackDepth"; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
81 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
82 |
private static final String[] MONITOR_INFO_ATTRIBUTES = { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
83 |
CLASS_NAME, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
84 |
IDENTITY_HASH_CODE, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
85 |
LOCKED_STACK_FRAME, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
86 |
LOCKED_STACK_DEPTH |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
87 |
}; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
88 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
89 |
private static final CompositeType MONITOR_INFO_COMPOSITE_TYPE; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
90 |
private static final CompositeType V6_COMPOSITE_TYPE; |
2 | 91 |
static { |
92 |
try { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
93 |
MONITOR_INFO_COMPOSITE_TYPE = (CompositeType) |
2 | 94 |
MappedMXBeanType.toOpenType(MonitorInfo.class); |
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
95 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
96 |
OpenType<?>[] types = new OpenType<?>[MONITOR_INFO_ATTRIBUTES.length]; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
97 |
for (int i = 0; i < MONITOR_INFO_ATTRIBUTES.length; i++) { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
98 |
String name = MONITOR_INFO_ATTRIBUTES[i]; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
99 |
types[i] = name.equals(LOCKED_STACK_FRAME) |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
100 |
? StackTraceElementCompositeData.v5CompositeType() |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
101 |
: MONITOR_INFO_COMPOSITE_TYPE.getType(name); |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
102 |
} |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
103 |
V6_COMPOSITE_TYPE = new CompositeType("MonitorInfo", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
104 |
"JDK 6 MonitorInfo", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
105 |
MONITOR_INFO_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
106 |
MONITOR_INFO_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
107 |
types); |
2 | 108 |
} catch (OpenDataException e) { |
109 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
110 |
throw new AssertionError(e); |
2 | 111 |
} |
112 |
} |
|
113 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
114 |
static CompositeType v6CompositeType() { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
115 |
return V6_COMPOSITE_TYPE; |
2 | 116 |
} |
117 |
||
118 |
public static String getClassName(CompositeData cd) { |
|
119 |
return getString(cd, CLASS_NAME); |
|
120 |
} |
|
121 |
||
122 |
public static int getIdentityHashCode(CompositeData cd) { |
|
123 |
return getInt(cd, IDENTITY_HASH_CODE); |
|
124 |
} |
|
125 |
||
126 |
public static StackTraceElement getLockedStackFrame(CompositeData cd) { |
|
127 |
CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME); |
|
128 |
if (ste != null) { |
|
129 |
return StackTraceElementCompositeData.from(ste); |
|
130 |
} else { |
|
131 |
return null; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
public static int getLockedStackDepth(CompositeData cd) { |
|
136 |
return getInt(cd, LOCKED_STACK_DEPTH); |
|
137 |
} |
|
138 |
||
139 |
/** Validate if the input CompositeData has the expected |
|
140 |
* CompositeType (i.e. contain all attributes with expected |
|
141 |
* names and types). |
|
142 |
*/ |
|
143 |
public static void validateCompositeData(CompositeData cd) { |
|
144 |
if (cd == null) { |
|
145 |
throw new NullPointerException("Null CompositeData"); |
|
146 |
} |
|
147 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
148 |
if (!isTypeMatched(MONITOR_INFO_COMPOSITE_TYPE, cd.getCompositeType()) && |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
149 |
!isTypeMatched(V6_COMPOSITE_TYPE, cd.getCompositeType())) { |
2 | 150 |
throw new IllegalArgumentException( |
151 |
"Unexpected composite type for MonitorInfo"); |
|
152 |
} |
|
153 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
154 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
155 |
private static final long serialVersionUID = -5825215591822908529L; |
2 | 156 |
} |