author | sjiang |
Fri, 17 Apr 2015 09:40:02 +0200 | |
changeset 30355 | e37c7eba132f |
parent 25859 | jdk/src/java.management/share/classes/sun/management/GarbageCollectionNotifInfoCompositeData.java@3317bb8137f4 |
permissions | -rw-r--r-- |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2011, 2015, 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 |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
26 |
package com.sun.management.internal; |
9698
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 javax.management.openmbean.CompositeData; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
31 |
import javax.management.openmbean.CompositeType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
32 |
import javax.management.openmbean.CompositeDataSupport; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
33 |
import javax.management.openmbean.OpenDataException; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
34 |
import javax.management.openmbean.OpenType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
35 |
import javax.management.openmbean.SimpleType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
36 |
import java.security.AccessController; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
37 |
import java.security.PrivilegedAction; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
38 |
import java.lang.reflect.Field; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
39 |
import java.util.HashMap; |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
40 |
import sun.management.LazyCompositeData; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
41 |
import static sun.management.LazyCompositeData.getString; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
42 |
import sun.management.Util; |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
43 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
44 |
/** |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
45 |
* A CompositeData for GarbageCollectionNotificationInfo for the local management support. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
46 |
* This class avoids the performance penalty paid to the |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
47 |
* construction of a CompositeData use in the local case. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
48 |
*/ |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
49 |
public class GarbageCollectionNotifInfoCompositeData extends LazyCompositeData { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
50 |
private final GarbageCollectionNotificationInfo gcNotifInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
51 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
52 |
public GarbageCollectionNotifInfoCompositeData(GarbageCollectionNotificationInfo info) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
53 |
this.gcNotifInfo = info; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
54 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
55 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
56 |
public GarbageCollectionNotificationInfo getGarbageCollectionNotifInfo() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
57 |
return gcNotifInfo; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
58 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
59 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
60 |
public static CompositeData toCompositeData(GarbageCollectionNotificationInfo info) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
61 |
GarbageCollectionNotifInfoCompositeData gcnicd = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
62 |
new GarbageCollectionNotifInfoCompositeData(info); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
63 |
return gcnicd.getCompositeData(); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
64 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
65 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
66 |
private CompositeType getCompositeTypeByBuilder() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
67 |
final GcInfoBuilder builder = AccessController.doPrivileged (new PrivilegedAction<GcInfoBuilder>() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
68 |
public GcInfoBuilder run() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
69 |
try { |
25405
aa7f539c3569
8049820: Fix raw and unchecked lint warnings in sun.management
darcy
parents:
14342
diff
changeset
|
70 |
Class<?> cl = Class.forName("com.sun.management.GcInfo"); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
71 |
Field f = cl.getDeclaredField("builder"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
72 |
f.setAccessible(true); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
73 |
return (GcInfoBuilder)f.get(gcNotifInfo.getGcInfo()); |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
74 |
} catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) { |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
75 |
return null; |
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 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
78 |
}); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
79 |
CompositeType gict = null; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
80 |
synchronized(compositeTypeByBuilder) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
81 |
gict = compositeTypeByBuilder.get(builder); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
82 |
if(gict == null) { |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
83 |
OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] { |
9698
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 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
86 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
87 |
builder.getGcInfoCompositeType(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
88 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
89 |
try { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
90 |
final String typeName = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
91 |
"sun.management.GarbageCollectionNotifInfoCompositeType"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
92 |
gict = new CompositeType(typeName, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
93 |
"CompositeType for GC notification info", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
94 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
95 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
96 |
gcNotifInfoItemTypes); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
97 |
compositeTypeByBuilder.put(builder,gict); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
98 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
99 |
// shouldn't reach here |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
100 |
throw new RuntimeException(e); |
9698
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 |
} |
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 |
return gict; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
105 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
106 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
107 |
protected CompositeData getCompositeData() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
108 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
109 |
// gcNotifInfoItemNames! |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
110 |
final Object[] gcNotifInfoItemValues; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
111 |
gcNotifInfoItemValues = new Object[] { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
112 |
gcNotifInfo.getGcName(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
113 |
gcNotifInfo.getGcAction(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
114 |
gcNotifInfo.getGcCause(), |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
115 |
GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo()) |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
116 |
}; |
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 |
CompositeType gict = getCompositeTypeByBuilder(); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
119 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
120 |
try { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
121 |
return new CompositeDataSupport(gict, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
122 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
123 |
gcNotifInfoItemValues); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
124 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
125 |
// Should never reach here |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
126 |
throw new AssertionError(e); |
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 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
129 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
130 |
// private static MappedMXBeanType gcInfoMapType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
131 |
private static final String GC_NAME = "gcName"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
132 |
private static final String GC_ACTION = "gcAction"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
133 |
private static final String GC_CAUSE = "gcCause"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
134 |
private static final String GC_INFO = "gcInfo"; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
135 |
private static final String[] gcNotifInfoItemNames = { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
136 |
GC_NAME, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
137 |
GC_ACTION, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
138 |
GC_CAUSE, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
139 |
GC_INFO |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
140 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
141 |
private static HashMap<GcInfoBuilder,CompositeType> compositeTypeByBuilder = |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
142 |
new HashMap<>(); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
143 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
144 |
public static String getGcName(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
145 |
String gcname = getString(cd, GC_NAME); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
146 |
if (gcname == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
147 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
148 |
"Attribute " + GC_NAME + " has null value"); |
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 |
return gcname; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
151 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
152 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
153 |
public static String getGcAction(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
154 |
String gcaction = getString(cd, GC_ACTION); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
155 |
if (gcaction == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
156 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
157 |
"Attribute " + GC_ACTION + " has null value"); |
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 |
return gcaction; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
160 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
161 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
162 |
public static String getGcCause(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
163 |
String gccause = getString(cd, GC_CAUSE); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
164 |
if (gccause == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
165 |
throw new IllegalArgumentException("Invalid composite data: " + |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
166 |
"Attribute " + GC_CAUSE + " has null value"); |
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 |
return gccause; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
169 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
170 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
171 |
public static GcInfo getGcInfo(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
172 |
CompositeData gcInfoData = (CompositeData) cd.get(GC_INFO); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
173 |
return GcInfo.from(gcInfoData); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
174 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
175 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
176 |
/** Validate if the input CompositeData has the expected |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
177 |
* CompositeType (i.e. contain all attributes with expected |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
178 |
* names and types). |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
179 |
*/ |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
180 |
public static void validateCompositeData(CompositeData cd) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
181 |
if (cd == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
182 |
throw new NullPointerException("Null CompositeData"); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
183 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
184 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
185 |
if (!isTypeMatched( getBaseGcNotifInfoCompositeType(), cd.getCompositeType())) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
186 |
throw new IllegalArgumentException( |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
187 |
"Unexpected composite type for GarbageCollectionNotificationInfo"); |
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 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
190 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
191 |
// This is only used for validation. |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
192 |
private static CompositeType baseGcNotifInfoCompositeType = null; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
193 |
private static synchronized CompositeType getBaseGcNotifInfoCompositeType() { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
194 |
if (baseGcNotifInfoCompositeType == null) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
195 |
try { |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
9698
diff
changeset
|
196 |
OpenType<?>[] baseGcNotifInfoItemTypes = new OpenType<?>[] { |
9698
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 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
199 |
SimpleType.STRING, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
200 |
GcInfoCompositeData.getBaseGcInfoCompositeType() |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
201 |
}; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
202 |
baseGcNotifInfoCompositeType = |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
203 |
new CompositeType("sun.management.BaseGarbageCollectionNotifInfoCompositeType", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
204 |
"CompositeType for Base GarbageCollectionNotificationInfo", |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
205 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
206 |
gcNotifInfoItemNames, |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
207 |
baseGcNotifInfoItemTypes); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
208 |
} catch (OpenDataException e) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
209 |
// shouldn't reach here |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
210 |
throw new RuntimeException(e); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
211 |
} |
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 |
return baseGcNotifInfoCompositeType; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
214 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
215 |
|
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
216 |
private static final long serialVersionUID = -1805123446483771292L; |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
diff
changeset
|
217 |
} |