1 /* |
1 /* |
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import java.lang.management.MonitorInfo; |
28 import java.lang.management.MonitorInfo; |
29 import javax.management.openmbean.CompositeType; |
29 import javax.management.openmbean.CompositeType; |
30 import javax.management.openmbean.CompositeData; |
30 import javax.management.openmbean.CompositeData; |
31 import javax.management.openmbean.CompositeDataSupport; |
31 import javax.management.openmbean.CompositeDataSupport; |
32 import javax.management.openmbean.OpenDataException; |
32 import javax.management.openmbean.OpenDataException; |
33 import java.util.Set; |
33 import javax.management.openmbean.OpenType; |
34 |
34 |
35 /** |
35 /** |
36 * A CompositeData for MonitorInfo for the local management support. |
36 * A CompositeData for MonitorInfo for the local management support. |
37 * This class avoids the performance penalty paid to the |
37 * This class avoids the performance penalty paid to the |
38 * construction of a CompositeData use in the local case. |
38 * construction of a CompositeData use in the local case. |
53 return micd.getCompositeData(); |
53 return micd.getCompositeData(); |
54 } |
54 } |
55 |
55 |
56 protected CompositeData getCompositeData() { |
56 protected CompositeData getCompositeData() { |
57 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
57 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
58 // monitorInfoItemNames! |
58 // MONITOR_INFO_ATTRIBUTES! |
59 |
59 |
60 int len = monitorInfoItemNames.length; |
60 int len = MONITOR_INFO_ATTRIBUTES.length; |
61 Object[] values = new Object[len]; |
61 Object[] values = new Object[len]; |
62 CompositeData li = LockInfoCompositeData.toCompositeData(lock); |
62 CompositeData li = LockInfoCompositeData.toCompositeData(lock); |
63 |
63 |
64 for (int i = 0; i < len; i++) { |
64 for (int i = 0; i < len; i++) { |
65 String item = monitorInfoItemNames[i]; |
65 String item = MONITOR_INFO_ATTRIBUTES[i]; |
66 if (item.equals(LOCKED_STACK_FRAME)) { |
66 if (item.equals(LOCKED_STACK_FRAME)) { |
67 StackTraceElement ste = lock.getLockedStackFrame(); |
67 StackTraceElement ste = lock.getLockedStackFrame(); |
68 values[i] = (ste != null ? StackTraceElementCompositeData. |
68 values[i] = (ste != null ? StackTraceElementCompositeData. |
69 toCompositeData(ste) |
69 toCompositeData(ste) |
70 : null); |
70 : null); |
74 values[i] = li.get(item); |
74 values[i] = li.get(item); |
75 } |
75 } |
76 } |
76 } |
77 |
77 |
78 try { |
78 try { |
79 return new CompositeDataSupport(monitorInfoCompositeType, |
79 return new CompositeDataSupport(MONITOR_INFO_COMPOSITE_TYPE, |
80 monitorInfoItemNames, |
80 MONITOR_INFO_ATTRIBUTES, |
81 values); |
81 values); |
82 } catch (OpenDataException e) { |
82 } catch (OpenDataException e) { |
83 // Should never reach here |
83 // Should never reach here |
84 throw new AssertionError(e); |
84 throw new AssertionError(e); |
85 } |
85 } |
86 } |
86 } |
87 |
87 |
88 private static final CompositeType monitorInfoCompositeType; |
88 private static final String CLASS_NAME = "className"; |
89 private static final String[] monitorInfoItemNames; |
89 private static final String IDENTITY_HASH_CODE = "identityHashCode"; |
|
90 private static final String LOCKED_STACK_FRAME = "lockedStackFrame"; |
|
91 private static final String LOCKED_STACK_DEPTH = "lockedStackDepth"; |
|
92 |
|
93 private static final String[] MONITOR_INFO_ATTRIBUTES = { |
|
94 CLASS_NAME, |
|
95 IDENTITY_HASH_CODE, |
|
96 LOCKED_STACK_FRAME, |
|
97 LOCKED_STACK_DEPTH |
|
98 }; |
|
99 |
|
100 private static final CompositeType MONITOR_INFO_COMPOSITE_TYPE; |
|
101 private static final CompositeType V6_COMPOSITE_TYPE; |
90 static { |
102 static { |
91 try { |
103 try { |
92 monitorInfoCompositeType = (CompositeType) |
104 MONITOR_INFO_COMPOSITE_TYPE = (CompositeType) |
93 MappedMXBeanType.toOpenType(MonitorInfo.class); |
105 MappedMXBeanType.toOpenType(MonitorInfo.class); |
94 Set<String> s = monitorInfoCompositeType.keySet(); |
106 |
95 monitorInfoItemNames = s.toArray(new String[0]); |
107 OpenType<?>[] types = new OpenType<?>[MONITOR_INFO_ATTRIBUTES.length]; |
|
108 for (int i = 0; i < MONITOR_INFO_ATTRIBUTES.length; i++) { |
|
109 String name = MONITOR_INFO_ATTRIBUTES[i]; |
|
110 types[i] = name.equals(LOCKED_STACK_FRAME) |
|
111 ? StackTraceElementCompositeData.v5CompositeType() |
|
112 : MONITOR_INFO_COMPOSITE_TYPE.getType(name); |
|
113 } |
|
114 V6_COMPOSITE_TYPE = new CompositeType("MonitorInfo", |
|
115 "JDK 6 MonitorInfo", |
|
116 MONITOR_INFO_ATTRIBUTES, |
|
117 MONITOR_INFO_ATTRIBUTES, |
|
118 types); |
96 } catch (OpenDataException e) { |
119 } catch (OpenDataException e) { |
97 // Should never reach here |
120 // Should never reach here |
98 throw new AssertionError(e); |
121 throw new AssertionError(e); |
99 } |
122 } |
100 } |
123 } |
101 |
124 |
102 static CompositeType getMonitorInfoCompositeType() { |
125 static CompositeType v6CompositeType() { |
103 return monitorInfoCompositeType; |
126 return V6_COMPOSITE_TYPE; |
104 } |
127 } |
105 |
128 |
106 private static final String CLASS_NAME = "className"; |
129 static CompositeType compositeType() { |
107 private static final String IDENTITY_HASH_CODE = "identityHashCode"; |
130 return MONITOR_INFO_COMPOSITE_TYPE; |
108 private static final String LOCKED_STACK_FRAME = "lockedStackFrame"; |
131 } |
109 private static final String LOCKED_STACK_DEPTH = "lockedStackDepth"; |
|
110 |
132 |
111 public static String getClassName(CompositeData cd) { |
133 public static String getClassName(CompositeData cd) { |
112 return getString(cd, CLASS_NAME); |
134 return getString(cd, CLASS_NAME); |
113 } |
135 } |
114 |
136 |
136 public static void validateCompositeData(CompositeData cd) { |
158 public static void validateCompositeData(CompositeData cd) { |
137 if (cd == null) { |
159 if (cd == null) { |
138 throw new NullPointerException("Null CompositeData"); |
160 throw new NullPointerException("Null CompositeData"); |
139 } |
161 } |
140 |
162 |
141 if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) { |
163 if (!isTypeMatched(MONITOR_INFO_COMPOSITE_TYPE, cd.getCompositeType()) && |
|
164 !isTypeMatched(V6_COMPOSITE_TYPE, cd.getCompositeType())) { |
142 throw new IllegalArgumentException( |
165 throw new IllegalArgumentException( |
143 "Unexpected composite type for MonitorInfo"); |
166 "Unexpected composite type for MonitorInfo"); |
144 } |
167 } |
145 } |
168 } |
146 |
169 |