Search in sources :

Example 1 with GarbageCollectorMXBean

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.");
}
Also used : GcInfo(com.sun.management.GcInfo) GarbageCollectorMXBean(com.sun.management.GarbageCollectorMXBean)

Example 2 with GarbageCollectorMXBean

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);
}
Also used : GarbageCollectorMXBean(com.sun.management.GarbageCollectorMXBean) MemoryUsage(java.lang.management.MemoryUsage) Map(java.util.Map) HashMap(java.util.HashMap) ObjectName(javax.management.ObjectName)

Aggregations

GarbageCollectorMXBean (com.sun.management.GarbageCollectorMXBean)2 GcInfo (com.sun.management.GcInfo)1 MemoryUsage (java.lang.management.MemoryUsage)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ObjectName (javax.management.ObjectName)1