use of com.sun.management.GarbageCollectorMXBean in project jdk8u_jdk by JetBrains.
the class LastGCInfo method main.
public static void main(String[] argv) throws Exception {
boolean hasGcInfo = false;
System.gc();
List mgrs = ManagementFactory.getGarbageCollectorMXBeans();
for (ListIterator iter = mgrs.listIterator(); iter.hasNext(); ) {
Object mgr = iter.next();
if (mgr instanceof GarbageCollectorMXBean) {
GarbageCollectorMXBean gc = (GarbageCollectorMXBean) mgr;
GcInfo info = gc.getLastGcInfo();
if (info != null) {
checkGcInfo(gc.getName(), info);
hasGcInfo = true;
}
}
}
if (!hasGcInfo) {
throw new RuntimeException("No GcInfo returned");
}
System.out.println("Test passed.");
}
use of com.sun.management.GarbageCollectorMXBean in project jdk8u_jdk by JetBrains.
the class MemoryPoolProxy method getStat.
public MemoryPoolStat getStat() throws java.io.IOException {
long usageThreshold = (pool.isUsageThresholdSupported() ? pool.getUsageThreshold() : -1);
long collectThreshold = (pool.isCollectionUsageThresholdSupported() ? pool.getCollectionUsageThreshold() : -1);
long lastGcStartTime = 0;
long lastGcEndTime = 0;
MemoryUsage beforeGcUsage = null;
MemoryUsage afterGcUsage = null;
long gcId = 0;
if (lastGcInfo != null) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
}
Set<Map.Entry<ObjectName, Long>> set = gcMBeans.entrySet();
for (Map.Entry<ObjectName, Long> e : set) {
GarbageCollectorMXBean gc = client.getMXBean(e.getKey(), com.sun.management.GarbageCollectorMXBean.class);
Long gcCount = e.getValue();
Long newCount = gc.getCollectionCount();
if (newCount > gcCount) {
gcMBeans.put(e.getKey(), new Long(newCount));
lastGcInfo = gc.getLastGcInfo();
if (lastGcInfo.getEndTime() > lastGcEndTime) {
gcId = lastGcInfo.getId();
lastGcStartTime = lastGcInfo.getStartTime();
lastGcEndTime = lastGcInfo.getEndTime();
beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
assert (beforeGcUsage != null);
assert (afterGcUsage != null);
}
}
}
MemoryUsage usage = pool.getUsage();
return new MemoryPoolStat(poolName, usageThreshold, usage, gcId, lastGcStartTime, lastGcEndTime, collectThreshold, beforeGcUsage, afterGcUsage);
}
Aggregations