author | iklam |
Fri, 20 Jul 2018 12:19:28 -0700 | |
changeset 51180 | b7eb9cc56277 |
parent 49077 | b1c42b3cd19b |
child 52288 | 2b29df6dfa68 |
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; |
|
29 |
import javax.management.openmbean.CompositeType; |
|
30 |
import javax.management.openmbean.CompositeData; |
|
31 |
import javax.management.openmbean.CompositeDataSupport; |
|
32 |
import javax.management.openmbean.OpenDataException; |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
33 |
import javax.management.openmbean.OpenType; |
2 | 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 |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
58 |
// MONITOR_INFO_ATTRIBUTES! |
2 | 59 |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
60 |
int len = MONITOR_INFO_ATTRIBUTES.length; |
2 | 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++) { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
65 |
String item = MONITOR_INFO_ATTRIBUTES[i]; |
2 | 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 { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
79 |
return new CompositeDataSupport(MONITOR_INFO_COMPOSITE_TYPE, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
80 |
MONITOR_INFO_ATTRIBUTES, |
2 | 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 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
93 |
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
|
94 |
CLASS_NAME, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
95 |
IDENTITY_HASH_CODE, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
96 |
LOCKED_STACK_FRAME, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
97 |
LOCKED_STACK_DEPTH |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
98 |
}; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
99 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
100 |
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
|
101 |
private static final CompositeType V6_COMPOSITE_TYPE; |
2 | 102 |
static { |
103 |
try { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
104 |
MONITOR_INFO_COMPOSITE_TYPE = (CompositeType) |
2 | 105 |
MappedMXBeanType.toOpenType(MonitorInfo.class); |
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
106 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
String name = MONITOR_INFO_ATTRIBUTES[i]; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
110 |
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
|
111 |
? StackTraceElementCompositeData.v5CompositeType() |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
112 |
: MONITOR_INFO_COMPOSITE_TYPE.getType(name); |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
113 |
} |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
114 |
V6_COMPOSITE_TYPE = new CompositeType("MonitorInfo", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
115 |
"JDK 6 MonitorInfo", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
116 |
MONITOR_INFO_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
117 |
MONITOR_INFO_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
118 |
types); |
2 | 119 |
} catch (OpenDataException e) { |
120 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
121 |
throw new AssertionError(e); |
2 | 122 |
} |
123 |
} |
|
124 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
125 |
static CompositeType v6CompositeType() { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
126 |
return V6_COMPOSITE_TYPE; |
2 | 127 |
} |
128 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
129 |
static CompositeType compositeType() { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
130 |
return MONITOR_INFO_COMPOSITE_TYPE; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
131 |
} |
2 | 132 |
|
133 |
public static String getClassName(CompositeData cd) { |
|
134 |
return getString(cd, CLASS_NAME); |
|
135 |
} |
|
136 |
||
137 |
public static int getIdentityHashCode(CompositeData cd) { |
|
138 |
return getInt(cd, IDENTITY_HASH_CODE); |
|
139 |
} |
|
140 |
||
141 |
public static StackTraceElement getLockedStackFrame(CompositeData cd) { |
|
142 |
CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME); |
|
143 |
if (ste != null) { |
|
144 |
return StackTraceElementCompositeData.from(ste); |
|
145 |
} else { |
|
146 |
return null; |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
public static int getLockedStackDepth(CompositeData cd) { |
|
151 |
return getInt(cd, LOCKED_STACK_DEPTH); |
|
152 |
} |
|
153 |
||
154 |
/** Validate if the input CompositeData has the expected |
|
155 |
* CompositeType (i.e. contain all attributes with expected |
|
156 |
* names and types). |
|
157 |
*/ |
|
158 |
public static void validateCompositeData(CompositeData cd) { |
|
159 |
if (cd == null) { |
|
160 |
throw new NullPointerException("Null CompositeData"); |
|
161 |
} |
|
162 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
163 |
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
|
164 |
!isTypeMatched(V6_COMPOSITE_TYPE, cd.getCompositeType())) { |
2 | 165 |
throw new IllegalArgumentException( |
166 |
"Unexpected composite type for MonitorInfo"); |
|
167 |
} |
|
168 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
169 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
170 |
private static final long serialVersionUID = -5825215591822908529L; |
2 | 171 |
} |