author | weijun |
Thu, 11 Dec 2014 15:23:02 +0800 | |
changeset 27957 | 24b4e6082f19 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
1 |
/* |
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
4 |
* |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
10 |
* |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
15 |
* accompanied this code). |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
16 |
* |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
20 |
* |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
23 |
* questions. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
24 |
*/ |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
25 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
26 |
package sun.management; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
27 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
28 |
import com.sun.management.GarbageCollectionNotificationInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
29 |
import com.sun.management.GcInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
30 |
import java.lang.reflect.Method; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
31 |
import javax.management.openmbean.CompositeData; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
32 |
import javax.management.openmbean.CompositeType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
33 |
import javax.management.openmbean.CompositeDataSupport; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
34 |
import javax.management.openmbean.OpenDataException; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
35 |
import javax.management.openmbean.OpenType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
36 |
import javax.management.openmbean.SimpleType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
37 |
import java.security.AccessController; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
38 |
import java.security.PrivilegedAction; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
39 |
import java.lang.reflect.Field; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
40 |
import java.util.HashMap; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
41 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
42 |
/** |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
43 |
* A CompositeData for GarbageCollectionNotificationInfo for the local management support. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
44 |
* This class avoids the performance penalty paid to the |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
45 |
* construction of a CompositeData use in the local case. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
46 |
*/ |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
47 |
public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
48 |
private final GarbageCollectionNotificationInfo gcNotifInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
49 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
50 |
public GarbageCollectionNotifInfoCompositeData(GarbageCollectionNotificationInfo info) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
51 |
this.gcNotifInfo = info; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
52 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
53 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
54 |
public GarbageCollectionNotificationInfo getGarbageCollectionNotifInfo() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
55 |
return gcNotifInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
56 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
57 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
58 |
public static CompositeData toCompositeData(GarbageCollectionNotificationInfo info) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
59 |
GarbageCollectionNotifInfoCompositeData gcnicd = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
60 |
new GarbageCollectionNotifInfoCompositeData(info); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
61 |
return gcnicd.getCompositeData(); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
62 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
63 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
64 |
private CompositeType getCompositeTypeByBuilder() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
65 |
final GcInfoBuilder builder = AccessController.doPrivileged (new PrivilegedAction<GcInfoBuilder>() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
66 |
public GcInfoBuilder run() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
67 |
try { |
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
14342
diff
changeset
|
68 |
Class<?> cl = Class.forName("com.sun.management.GcInfo"); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
69 |
Field f = cl.getDeclaredField("builder"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
70 |
f.setAccessible(true); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
71 |
return (GcInfoBuilder)f.get(gcNotifInfo.getGcInfo()); |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
72 |
} catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
73 |
return null; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
74 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
75 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
76 |
}); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
77 |
CompositeType gict = null; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
78 |
synchronized(compositeTypeByBuilder) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
79 |
gict = compositeTypeByBuilder.get(builder); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
80 |
if(gict == null) { |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
81 |
OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] { |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
82 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
83 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
84 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
85 |
builder.getGcInfoCompositeType(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
86 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
87 |
try { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
88 |
final String typeName = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
89 |
"sun.management.GarbageCollectionNotifInfoCompositeType"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
90 |
gict = new CompositeType(typeName, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
91 |
"CompositeType for GC notification info", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
92 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
93 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
94 |
gcNotifInfoItemTypes); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
95 |
compositeTypeByBuilder.put(builder,gict); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
96 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
97 |
// shouldn't reach here |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
98 |
throw Util.newException(e); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
99 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
100 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
101 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
102 |
return gict; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
103 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
104 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
105 |
protected CompositeData getCompositeData() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
106 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
107 |
// gcNotifInfoItemNames! |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
108 |
final Object[] gcNotifInfoItemValues; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
109 |
gcNotifInfoItemValues = new Object[] { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
110 |
gcNotifInfo.getGcName(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
111 |
gcNotifInfo.getGcAction(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
112 |
gcNotifInfo.getGcCause(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
113 |
GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo()) |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
114 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
115 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
116 |
CompositeType gict = getCompositeTypeByBuilder(); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
117 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
118 |
try { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
119 |
return new CompositeDataSupport(gict, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
120 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
121 |
gcNotifInfoItemValues); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
122 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
123 |
// Should never reach here |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
124 |
throw new AssertionError(e); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
125 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
126 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
127 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
128 |
// private static MappedMXBeanType gcInfoMapType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
129 |
private static final String GC_NAME = "gcName"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
130 |
private static final String GC_ACTION = "gcAction"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
131 |
private static final String GC_CAUSE = "gcCause"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
132 |
private static final String GC_INFO = "gcInfo"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
133 |
private static final String[] gcNotifInfoItemNames = { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
134 |
GC_NAME, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
135 |
GC_ACTION, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
136 |
GC_CAUSE, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
137 |
GC_INFO |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
138 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
139 |
private static HashMap<GcInfoBuilder,CompositeType> compositeTypeByBuilder = |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
140 |
new HashMap<>(); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
141 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
142 |
public static String getGcName(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
143 |
String gcname = getString(cd, GC_NAME); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
144 |
if (gcname == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
145 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
146 |
"Attribute " + GC_NAME + " has null value"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
147 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
148 |
return gcname; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
149 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
150 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
151 |
public static String getGcAction(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
152 |
String gcaction = getString(cd, GC_ACTION); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
153 |
if (gcaction == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
154 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
155 |
"Attribute " + GC_ACTION + " has null value"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
156 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
157 |
return gcaction; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
158 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
159 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
160 |
public static String getGcCause(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
161 |
String gccause = getString(cd, GC_CAUSE); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
162 |
if (gccause == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
163 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
164 |
"Attribute " + GC_CAUSE + " has null value"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
165 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
166 |
return gccause; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
167 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
168 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
169 |
public static GcInfo getGcInfo(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
170 |
CompositeData gcInfoData = (CompositeData) cd.get(GC_INFO); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
171 |
return GcInfo.from(gcInfoData); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
172 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
173 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
174 |
/** Validate if the input CompositeData has the expected |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
175 |
* CompositeType (i.e. contain all attributes with expected |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
176 |
* names and types). |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
177 |
*/ |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
178 |
public static void validateCompositeData(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
179 |
if (cd == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
180 |
throw new NullPointerException("Null CompositeData"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
181 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
182 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
183 |
if (!isTypeMatched( getBaseGcNotifInfoCompositeType(), cd.getCompositeType())) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
184 |
throw new IllegalArgumentException( |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
185 |
"Unexpected composite type for GarbageCollectionNotificationInfo"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
186 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
187 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
188 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
189 |
// This is only used for validation. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
190 |
private static CompositeType baseGcNotifInfoCompositeType = null; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
191 |
private static synchronized CompositeType getBaseGcNotifInfoCompositeType() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
192 |
if (baseGcNotifInfoCompositeType == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
193 |
try { |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
194 |
OpenType<?>[] baseGcNotifInfoItemTypes = new OpenType<?>[] { |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
195 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
196 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
197 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
198 |
GcInfoCompositeData.getBaseGcInfoCompositeType() |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
199 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
200 |
baseGcNotifInfoCompositeType = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
201 |
new CompositeType("sun.management.BaseGarbageCollectionNotifInfoCompositeType", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
202 |
"CompositeType for Base GarbageCollectionNotificationInfo", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
203 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
204 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
205 |
baseGcNotifInfoItemTypes); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
206 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
207 |
// shouldn't reach here |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
208 |
throw Util.newException(e); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
209 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
210 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
211 |
return baseGcNotifInfoCompositeType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
212 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
213 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
214 |
private static final long serialVersionUID = -1805123446483771292L; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
215 |
} |