1 /*
2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
55 private final GcInfo info;
56 private final GcInfoBuilder builder;
57 private final Object[] gcExtItemValues;
58
59 public GcInfoCompositeData(GcInfo info,
60 GcInfoBuilder builder,
61 Object[] gcExtItemValues) {
62 this.info = info;
63 this.builder = builder;
64 this.gcExtItemValues = gcExtItemValues;
65 }
66
67 public GcInfo getGcInfo() {
68 return info;
69 }
70
71 public static CompositeData toCompositeData(final GcInfo info) {
72 final GcInfoBuilder builder = AccessController.doPrivileged (new PrivilegedAction<GcInfoBuilder>() {
73 public GcInfoBuilder run() {
74 try {
75 Class cl = Class.forName("com.sun.management.GcInfo");
76 Field f = cl.getDeclaredField("builder");
77 f.setAccessible(true);
78 return (GcInfoBuilder)f.get(info);
79 } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
80 return null;
81 }
82 }
83 });
84 final Object[] extAttr = AccessController.doPrivileged (new PrivilegedAction<Object[]>() {
85 public Object[] run() {
86 try {
87 Class cl = Class.forName("com.sun.management.GcInfo");
88 Field f = cl.getDeclaredField("extAttributes");
89 f.setAccessible(true);
90 return (Object[])f.get(info);
91 } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
92 return null;
93 }
94 }
95 });
96 GcInfoCompositeData gcicd =
97 new GcInfoCompositeData(info,builder,extAttr);
98 return gcicd.getCompositeData();
99 }
100
101 protected CompositeData getCompositeData() {
102 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
103 // baseGcInfoItemNames!
104 final Object[] baseGcInfoItemValues;
105
106 try {
107 baseGcInfoItemValues = new Object[] {
165 MEMORY_USAGE_AFTER_GC,
166 };
167
168
169 private static MappedMXBeanType memoryUsageMapType;
170 static {
171 try {
172 Method m = GcInfo.class.getMethod("getMemoryUsageBeforeGc");
173 memoryUsageMapType =
174 MappedMXBeanType.getMappedType(m.getGenericReturnType());
175 } catch (NoSuchMethodException | OpenDataException e) {
176 // Should never reach here
177 throw new AssertionError(e);
178 }
179 }
180
181 static String[] getBaseGcInfoItemNames() {
182 return baseGcInfoItemNames;
183 }
184
185 private static OpenType[] baseGcInfoItemTypes = null;
186 static synchronized OpenType[] getBaseGcInfoItemTypes() {
187 if (baseGcInfoItemTypes == null) {
188 OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
189 baseGcInfoItemTypes = new OpenType<?>[] {
190 SimpleType.LONG,
191 SimpleType.LONG,
192 SimpleType.LONG,
193 SimpleType.LONG,
194
195 memoryUsageOpenType,
196 memoryUsageOpenType,
197 };
198 }
199 return baseGcInfoItemTypes;
200 }
201
202 public static long getId(CompositeData cd) {
203 return getLong(cd, ID);
204 }
205 public static long getStartTime(CompositeData cd) {
206 return getLong(cd, START_TIME);
|
1 /*
2 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
55 private final GcInfo info;
56 private final GcInfoBuilder builder;
57 private final Object[] gcExtItemValues;
58
59 public GcInfoCompositeData(GcInfo info,
60 GcInfoBuilder builder,
61 Object[] gcExtItemValues) {
62 this.info = info;
63 this.builder = builder;
64 this.gcExtItemValues = gcExtItemValues;
65 }
66
67 public GcInfo getGcInfo() {
68 return info;
69 }
70
71 public static CompositeData toCompositeData(final GcInfo info) {
72 final GcInfoBuilder builder = AccessController.doPrivileged (new PrivilegedAction<GcInfoBuilder>() {
73 public GcInfoBuilder run() {
74 try {
75 Class<?> cl = Class.forName("com.sun.management.GcInfo");
76 Field f = cl.getDeclaredField("builder");
77 f.setAccessible(true);
78 return (GcInfoBuilder)f.get(info);
79 } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
80 return null;
81 }
82 }
83 });
84 final Object[] extAttr = AccessController.doPrivileged (new PrivilegedAction<Object[]>() {
85 public Object[] run() {
86 try {
87 Class<?> cl = Class.forName("com.sun.management.GcInfo");
88 Field f = cl.getDeclaredField("extAttributes");
89 f.setAccessible(true);
90 return (Object[])f.get(info);
91 } catch(ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
92 return null;
93 }
94 }
95 });
96 GcInfoCompositeData gcicd =
97 new GcInfoCompositeData(info,builder,extAttr);
98 return gcicd.getCompositeData();
99 }
100
101 protected CompositeData getCompositeData() {
102 // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
103 // baseGcInfoItemNames!
104 final Object[] baseGcInfoItemValues;
105
106 try {
107 baseGcInfoItemValues = new Object[] {
165 MEMORY_USAGE_AFTER_GC,
166 };
167
168
169 private static MappedMXBeanType memoryUsageMapType;
170 static {
171 try {
172 Method m = GcInfo.class.getMethod("getMemoryUsageBeforeGc");
173 memoryUsageMapType =
174 MappedMXBeanType.getMappedType(m.getGenericReturnType());
175 } catch (NoSuchMethodException | OpenDataException e) {
176 // Should never reach here
177 throw new AssertionError(e);
178 }
179 }
180
181 static String[] getBaseGcInfoItemNames() {
182 return baseGcInfoItemNames;
183 }
184
185 private static OpenType<?>[] baseGcInfoItemTypes = null;
186 static synchronized OpenType<?>[] getBaseGcInfoItemTypes() {
187 if (baseGcInfoItemTypes == null) {
188 OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
189 baseGcInfoItemTypes = new OpenType<?>[] {
190 SimpleType.LONG,
191 SimpleType.LONG,
192 SimpleType.LONG,
193 SimpleType.LONG,
194
195 memoryUsageOpenType,
196 memoryUsageOpenType,
197 };
198 }
199 return baseGcInfoItemTypes;
200 }
201
202 public static long getId(CompositeData cd) {
203 return getLong(cd, ID);
204 }
205 public static long getStartTime(CompositeData cd) {
206 return getLong(cd, START_TIME);
|