author | mchung |
Wed, 28 Feb 2018 17:11:57 -0800 (2018-03-01) | |
changeset 49077 | b1c42b3cd19b |
parent 47216 | 71c04702a3d5 |
child 52152 | bfdf2926cebc |
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 javax.management.openmbean.CompositeType; |
|
29 |
import javax.management.openmbean.CompositeData; |
|
30 |
import javax.management.openmbean.CompositeDataSupport; |
|
31 |
import javax.management.openmbean.OpenDataException; |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
32 |
import javax.management.openmbean.OpenType; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
33 |
import java.util.Arrays; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
34 |
import java.util.stream.Stream; |
2 | 35 |
|
36 |
/** |
|
37 |
* A CompositeData for StackTraceElement for the local management support. |
|
38 |
* This class avoids the performance penalty paid to the |
|
39 |
* construction of a CompositeData use in the local case. |
|
40 |
*/ |
|
41 |
public class StackTraceElementCompositeData extends LazyCompositeData { |
|
42 |
private final StackTraceElement ste; |
|
43 |
||
44 |
private StackTraceElementCompositeData(StackTraceElement ste) { |
|
45 |
this.ste = ste; |
|
46 |
} |
|
47 |
||
48 |
public StackTraceElement getStackTraceElement() { |
|
49 |
return ste; |
|
50 |
} |
|
51 |
||
52 |
public static StackTraceElement from(CompositeData cd) { |
|
53 |
validateCompositeData(cd); |
|
54 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
55 |
if (STACK_TRACE_ELEMENT_COMPOSITE_TYPE.equals(cd.getCompositeType())) { |
41911 | 56 |
return new StackTraceElement(getString(cd, CLASS_LOADER_NAME), |
57 |
getString(cd, MODULE_NAME), |
|
36511 | 58 |
getString(cd, MODULE_VERSION), |
59 |
getString(cd, CLASS_NAME), |
|
60 |
getString(cd, METHOD_NAME), |
|
61 |
getString(cd, FILE_NAME), |
|
62 |
getInt(cd, LINE_NUMBER)); |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
63 |
} else { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
64 |
return new StackTraceElement(getString(cd, CLASS_NAME), |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
65 |
getString(cd, METHOD_NAME), |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
66 |
getString(cd, FILE_NAME), |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
67 |
getInt(cd, LINE_NUMBER)); |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
68 |
|
36511 | 69 |
} |
2 | 70 |
} |
71 |
||
72 |
public static CompositeData toCompositeData(StackTraceElement ste) { |
|
73 |
StackTraceElementCompositeData cd = new StackTraceElementCompositeData(ste); |
|
74 |
return cd.getCompositeData(); |
|
75 |
} |
|
76 |
||
77 |
protected CompositeData getCompositeData() { |
|
78 |
// 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
|
79 |
// STACK_TRACE_ELEMENT_ATTRIBUTES! |
2 | 80 |
final Object[] stackTraceElementItemValues = { |
41911 | 81 |
ste.getClassLoaderName(), |
82 |
ste.getModuleName(), |
|
83 |
ste.getModuleVersion(), |
|
2 | 84 |
ste.getClassName(), |
85 |
ste.getMethodName(), |
|
86 |
ste.getFileName(), |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24685
diff
changeset
|
87 |
ste.getLineNumber(), |
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
5506
diff
changeset
|
88 |
ste.isNativeMethod(), |
2 | 89 |
}; |
90 |
try { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
91 |
return new CompositeDataSupport(STACK_TRACE_ELEMENT_COMPOSITE_TYPE, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
92 |
STACK_TRACE_ELEMENT_ATTRIBUTES, |
2 | 93 |
stackTraceElementItemValues); |
94 |
} catch (OpenDataException e) { |
|
95 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
96 |
throw new AssertionError(e); |
2 | 97 |
} |
98 |
} |
|
99 |
||
100 |
// Attribute names |
|
41911 | 101 |
private static final String CLASS_LOADER_NAME = "classLoaderName"; |
102 |
private static final String MODULE_NAME = "moduleName"; |
|
103 |
private static final String MODULE_VERSION = "moduleVersion"; |
|
104 |
private static final String CLASS_NAME = "className"; |
|
105 |
private static final String METHOD_NAME = "methodName"; |
|
106 |
private static final String FILE_NAME = "fileName"; |
|
107 |
private static final String LINE_NUMBER = "lineNumber"; |
|
108 |
private static final String NATIVE_METHOD = "nativeMethod"; |
|
109 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
110 |
private static final String[] V5_ATTRIBUTES = { |
2 | 111 |
CLASS_NAME, |
112 |
METHOD_NAME, |
|
113 |
FILE_NAME, |
|
114 |
LINE_NUMBER, |
|
115 |
NATIVE_METHOD, |
|
116 |
}; |
|
117 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
118 |
private static final String[] V9_ATTRIBUTES = { |
41911 | 119 |
CLASS_LOADER_NAME, |
36511 | 120 |
MODULE_NAME, |
121 |
MODULE_VERSION, |
|
122 |
}; |
|
123 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
124 |
private static final String[] STACK_TRACE_ELEMENT_ATTRIBUTES = |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
125 |
Stream.of(V5_ATTRIBUTES, V9_ATTRIBUTES).flatMap(Arrays::stream) |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
126 |
.toArray(String[]::new); |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
127 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
128 |
private static final CompositeType STACK_TRACE_ELEMENT_COMPOSITE_TYPE; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
129 |
private static final CompositeType V5_COMPOSITE_TYPE; |
36511 | 130 |
static { |
131 |
try { |
|
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
132 |
STACK_TRACE_ELEMENT_COMPOSITE_TYPE = (CompositeType) |
36511 | 133 |
MappedMXBeanType.toOpenType(StackTraceElement.class); |
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
134 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
135 |
OpenType<?>[] types = new OpenType<?>[V5_ATTRIBUTES.length]; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
136 |
for (int i=0; i < V5_ATTRIBUTES.length; i++) { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
137 |
String name = V5_ATTRIBUTES[i]; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
138 |
types[i] = STACK_TRACE_ELEMENT_COMPOSITE_TYPE.getType(name); |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
139 |
} |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
140 |
V5_COMPOSITE_TYPE = new CompositeType("StackTraceElement", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
141 |
"JDK 5 StackTraceElement", |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
142 |
V5_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
143 |
V5_ATTRIBUTES, |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
144 |
types); |
36511 | 145 |
} catch (OpenDataException e) { |
146 |
// Should never reach here |
|
147 |
throw new AssertionError(e); |
|
148 |
} |
|
149 |
} |
|
150 |
||
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
151 |
static CompositeType v5CompositeType() { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
152 |
return V5_COMPOSITE_TYPE; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
153 |
} |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
154 |
static CompositeType compositeType() { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
155 |
return STACK_TRACE_ELEMENT_COMPOSITE_TYPE; |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
156 |
} |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
157 |
|
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
158 |
/** |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
159 |
* Validate if the input CompositeData has the expected |
2 | 160 |
* CompositeType (i.e. contain all attributes with expected |
161 |
* names and types). |
|
162 |
*/ |
|
163 |
public static void validateCompositeData(CompositeData cd) { |
|
164 |
if (cd == null) { |
|
165 |
throw new NullPointerException("Null CompositeData"); |
|
166 |
} |
|
167 |
||
36511 | 168 |
CompositeType ct = cd.getCompositeType(); |
49077
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
169 |
if (!isTypeMatched(STACK_TRACE_ELEMENT_COMPOSITE_TYPE, ct) && |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
170 |
!isTypeMatched(V5_COMPOSITE_TYPE, ct)) { |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
171 |
throw new IllegalArgumentException( |
b1c42b3cd19b
8198253: ThreadInfo.from(CompositeData) incorrectly accepts CompositeData with missing JDK 6 attributes
mchung
parents:
47216
diff
changeset
|
172 |
"Unexpected composite type for StackTraceElement"); |
2 | 173 |
} |
174 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
175 |
private static final long serialVersionUID = -2704607706598396827L; |
2 | 176 |
} |