Java Code Examples for java.lang.management.MemoryPoolMXBean#getName()

The following examples show how to use java.lang.management.MemoryPoolMXBean#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
    // optimization...
    if (handler instanceof SnmpCachedData)
        return buildPoolIndexMap((SnmpCachedData)handler);

    // not optimizable... too bad.
    final Map<String, SnmpOid> m = new HashMap<>();
    SnmpOid index=null;
    while ((index = handler.getNext(index))!=null) {
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)handler.getData(index);
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 2
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
    // optimization...
    if (handler instanceof SnmpCachedData)
        return buildPoolIndexMap((SnmpCachedData)handler);

    // not optimizable... too bad.
    final Map<String, SnmpOid> m = new HashMap<>();
    SnmpOid index=null;
    while ((index = handler.getNext(index))!=null) {
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)handler.getData(index);
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 3
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 * Optimized algorithm.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
    if (cached == null) return Collections.emptyMap();
    final SnmpOid[] indexes = cached.indexes;
    final Object[]  datas   = cached.datas;
    final int len = indexes.length;
    final Map<String, SnmpOid> m = new HashMap<>(len);
    for (int i=0; i<len; i++) {
        final SnmpOid index = indexes[i];
        if (index == null) continue;
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)datas[i];
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 4
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
    // optimization...
    if (handler instanceof SnmpCachedData)
        return buildPoolIndexMap((SnmpCachedData)handler);

    // not optimizable... too bad.
    final Map<String, SnmpOid> m = new HashMap<>();
    SnmpOid index=null;
    while ((index = handler.getNext(index))!=null) {
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)handler.getData(index);
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 5
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the name of the memory pool MXBean provided matches a list of
 * known young generation pool names.
 * 
 * @param memoryPoolMXBean
 *          The memory pool MXBean to check.
 * @return True if the pool name matches a known young generation pool name,
 *         false otherwise.
 */
static boolean isEden(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }

  String name = memoryPoolMXBean.getName();

  return name.equals("Par Eden Space")  // Oracle ParNew with Concurrent Mark Sweep GC
      || name.equals("PS Eden Space")   // Oracle Parallel GC
      || name.equals("G1 Eden")         // Oracle G1 GC
      //|| name.equals("Nursery")       // BEA JRockit 1.5, 1.6 GC
      || name.equals("Eden Space")      // Hitachi 1.5 GC
      // Allow an unknown pool name to monitor
      || (HEAP_EDEN_POOL != null && name.equals(HEAP_EDEN_POOL));
}
 
Example 6
Source File: Monitors.java    From sumk with Apache License 2.0 6 votes vote down vote up
public static String jvmInfo() {
	StringBuilder sb = new StringBuilder();
	sb.append("## name   init   max   commited    used").append(LN);
	DecimalFormat f = new DecimalFormat("#,###");
	List<MemoryPoolMXBean> mpmxbs = ManagementFactory.getMemoryPoolMXBeans();
	for (MemoryPoolMXBean mpmxb : mpmxbs) {
		if (mpmxb == null || mpmxb.getUsage() == null) {
			continue;
		}
		String name = mpmxb.getName();
		if (name == null || name.isEmpty()) {
			continue;
		}
		sb.append(name).append(BLANK).append(f.format(mpmxb.getUsage().getInit())).append(BLANK)
				.append(f.format(mpmxb.getUsage().getMax())).append(BLANK)
				.append(f.format(mpmxb.getUsage().getCommitted())).append(BLANK)
				.append(f.format(mpmxb.getUsage().getUsed())).append(LN);
	}
	return sb.toString();
}
 
Example 7
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
    // optimization...
    if (handler instanceof SnmpCachedData)
        return buildPoolIndexMap((SnmpCachedData)handler);

    // not optimizable... too bad.
    final Map<String, SnmpOid> m = new HashMap<>();
    SnmpOid index=null;
    while ((index = handler.getNext(index))!=null) {
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)handler.getData(index);
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 8
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 * Optimized algorithm.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
    if (cached == null) return Collections.emptyMap();
    final SnmpOid[] indexes = cached.indexes;
    final Object[]  datas   = cached.datas;
    final int len = indexes.length;
    final Map<String, SnmpOid> m = new HashMap<>(len);
    for (int i=0; i<len; i++) {
        final SnmpOid index = indexes[i];
        if (index == null) continue;
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)datas[i];
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 9
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpTableHandler handler) {
    // optimization...
    if (handler instanceof SnmpCachedData)
        return buildPoolIndexMap((SnmpCachedData)handler);

    // not optimizable... too bad.
    final Map<String, SnmpOid> m = new HashMap<>();
    SnmpOid index=null;
    while ((index = handler.getNext(index))!=null) {
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)handler.getData(index);
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 10
Source File: JVMMonitor.java    From fqueue with Apache License 2.0 6 votes vote down vote up
public static Map<String, MemoryUsage> getMemoryPoolCollectionUsage() {
    Map<String, MemoryUsage> gcMemory = new HashMap<String, MemoryUsage>();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        String name = memoryPoolMXBean.getName();
        if (edenSpace.contains(name)) {
            gcMemory.put("eden", memoryPoolMXBean.getCollectionUsage());
        } else if (survivorSpace.contains(name)) {
            gcMemory.put("survivor", memoryPoolMXBean.getCollectionUsage());
        } else if (oldSpace.contains(name)) {
            gcMemory.put("old", memoryPoolMXBean.getCollectionUsage());
        } else if (permSpace.contains(name)) {
            gcMemory.put("perm", memoryPoolMXBean.getCollectionUsage());
        } else if (codeCacheSpace.contains(name)) {
            gcMemory.put("codeCache", memoryPoolMXBean.getCollectionUsage());
        }

    }
    return gcMemory;
}
 
Example 11
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 * Optimized algorithm.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
    if (cached == null) return Collections.emptyMap();
    final SnmpOid[] indexes = cached.indexes;
    final Object[]  datas   = cached.datas;
    final int len = indexes.length;
    final Map<String, SnmpOid> m = new HashMap<>(len);
    for (int i=0; i<len; i++) {
        final SnmpOid index = indexes[i];
        if (index == null) continue;
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)datas[i];
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 12
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds a map pool-name => pool-index from the SnmpTableHandler
 * of the JvmMemPoolTable.
 * Optimized algorithm.
 **/
private static Map<String, SnmpOid> buildPoolIndexMap(SnmpCachedData cached) {
    if (cached == null) return Collections.emptyMap();
    final SnmpOid[] indexes = cached.indexes;
    final Object[]  datas   = cached.datas;
    final int len = indexes.length;
    final Map<String, SnmpOid> m = new HashMap<>(len);
    for (int i=0; i<len; i++) {
        final SnmpOid index = indexes[i];
        if (index == null) continue;
        final MemoryPoolMXBean mpm =
            (MemoryPoolMXBean)datas[i];
        if (mpm == null) continue;
        final String name = mpm.getName();
        if (name == null) continue;
        m.put(name,index);
    }
    return m;
}
 
Example 13
Source File: JmxSupport.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
MemoryPoolMXBean getPermGenPool() {
    try {
        if (permGenPool == null) {
            JvmMXBeans jmx = getJvmMXBeans();
            if (jmx != null) {
                Collection<MemoryPoolMXBean> pools = jmx.getMemoryPoolMXBeans();
                for (MemoryPoolMXBean pool : pools) {
                    MemoryType type = pool.getType();
                    String name = pool.getName();
                    if (MemoryType.NON_HEAP.equals(type) &&
                            (PERM_GEN.equals(name) ||
                            PS_PERM_GEN.equals(name) ||
                            CMS_PERM_GEN.equals(name) ||
                            G1_PERM_GEN.equals(name) ||
                            METASPACE.equals(name) ||
                            IBM_PERM_GEN.equals(name))) {
                        permGenPool = pool;
                        break;
                    }
                }
            }
        }
        return permGenPool;
    } catch (Exception e) {
        LOGGER.throwing(JmxSupport.class.getName(), "getPermGenPool", e); // NOI18N
        return null;
    }
}
 
Example 14
Source File: GarbageCollectorImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
synchronized String[] getAllPoolNames() {
    if (poolNames == null) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        poolNames = new String[pools.size()];
        int i = 0;
        for (MemoryPoolMXBean m : pools) {
            poolNames[i++] = m.getName();
        }
    }
    return poolNames;
}
 
Example 15
Source File: GarbageCollectorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
synchronized String[] getAllPoolNames() {
    if (poolNames == null) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        poolNames = new String[pools.size()];
        int i = 0;
        for (MemoryPoolMXBean m : pools) {
            poolNames[i++] = m.getName();
        }
    }
    return poolNames;
}
 
Example 16
Source File: MonitorMemory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onConfigured(final ConfigurationContext config) throws InitializationException {
    final String desiredMemoryPoolName = config.getProperty(MEMORY_POOL_PROPERTY).getValue();
    final String thresholdValue = config.getProperty(THRESHOLD_PROPERTY).getValue().trim();
    threshold = thresholdValue;

    final Long reportingIntervalValue = config.getProperty(REPORTING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    if (reportingIntervalValue == null) {
        reportingIntervalMillis = config.getSchedulingPeriod(TimeUnit.MILLISECONDS);
    } else {
        reportingIntervalMillis = reportingIntervalValue;
    }

    final List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == null; i++) {
        MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
        String memoryPoolName = memoryPoolBean.getName();
        if (desiredMemoryPoolName.equals(memoryPoolName)) {
            monitoredBean = memoryPoolBean;
            if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
                long calculatedThreshold;
                if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
                    calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
                } else {
                    final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
                    final double pct = Double.parseDouble(percentage) / 100D;
                    calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
                }
                monitoredBean.setUsageThreshold(calculatedThreshold);
            }
        }
    }

    if (monitoredBean == null) {
        throw new InitializationException("Found no JVM Memory Pool with name " + desiredMemoryPoolName + "; will not monitor Memory Pool");
    }
}
 
Example 17
Source File: GarbageCollectorImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized String[] getAllPoolNames() {
    if (poolNames == null) {
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
        poolNames = new String[pools.size()];
        int i = 0;
        for (MemoryPoolMXBean m : pools) {
            poolNames[i++] = m.getName();
        }
    }
    return poolNames;
}
 
Example 18
Source File: LastGCInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkGcInfo(String name, GcInfo info) throws Exception {
    System.out.println("GC statistic for : " + name);
    System.out.print("GC #" + info.getId());
    System.out.print(" start:" + info.getStartTime());
    System.out.print(" end:" + info.getEndTime());
    System.out.println(" (" + info.getDuration() + "ms)");
    Map usage = info.getMemoryUsageBeforeGc();

    List pnames = new ArrayList();
    for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String poolname = (String) entry.getKey();
        pnames.add(poolname);
        MemoryUsage busage = (MemoryUsage) entry.getValue();
        MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
        if (ausage == null) {
            throw new RuntimeException("After Gc Memory does not exist" +
                " for " + poolname);
        }
        System.out.println("Usage for pool " + poolname);
        System.out.println("   Before GC: " + busage);
        System.out.println("   After GC: " + ausage);
    }

    // check if memory usage for all memory pools are returned
    List pools = ManagementFactory.getMemoryPoolMXBeans();
    for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
        MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
        if (!pnames.contains(p.getName())) {
            throw new RuntimeException("GcInfo does not contain " +
                "memory usage for pool " + p.getName());
        }
    }
}
 
Example 19
Source File: JvmMem.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
public MemInfo(MemoryPoolMXBean pool) {
	this(pool.getName(), pool.getUsage());
}
 
Example 20
Source File: VMInfo.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public synchronized void getDelta(boolean print) {

        try {
            if (VMInfo.isSunOsMBean(osMXBean)) {
                long curUptime = runtimeMXBean.getUptime();
                long curProcessTime = getLongFromOperatingSystem(osMXBean, "getProcessCpuTime");
                //百分比, uptime是ms,processTime是nano
                if ((curUptime > lastUpTime) && (curProcessTime >= lastProcessCpuTime)) {
                    float curDeltaCpu = (float) (curProcessTime - lastProcessCpuTime) / ((curUptime - lastUpTime) * totalProcessorCount * 10000);
                    processCpuStatus.setMaxMinCpu(curDeltaCpu);
                    processCpuStatus.averageCpu = (float) curProcessTime / (curUptime * totalProcessorCount * 10000);

                    lastUpTime = curUptime;
                    lastProcessCpuTime = curProcessTime;
                }
            }

            for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) {

                GCStatus gcStatus = processGCStatus.gcStatusMap.get(garbage.getName());
                if (gcStatus == null) {
                    gcStatus = new GCStatus();
                    gcStatus.name = garbage.getName();
                    processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus);
                }

                long curTotalGcCount = garbage.getCollectionCount();
                gcStatus.setCurTotalGcCount(curTotalGcCount);

                long curtotalGcTime = garbage.getCollectionTime();
                gcStatus.setCurTotalGcTime(curtotalGcTime);
            }

            if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) {
                for (MemoryPoolMXBean pool : memoryPoolMXBeanList) {

                    MemoryStatus memoryStatus = processMomoryStatus.memoryStatusMap.get(pool.getName());
                    if (memoryStatus == null) {
                        memoryStatus = new MemoryStatus();
                        memoryStatus.name = pool.getName();
                        processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus);
                    }
                    memoryStatus.commitedSize = pool.getUsage().getCommitted();
                    memoryStatus.setMaxMinUsedSize(pool.getUsage().getUsed());
                    long maxMemory = memoryStatus.commitedSize > 0 ? memoryStatus.commitedSize : memoryStatus.maxSize;
                    memoryStatus.setMaxMinPercent(maxMemory > 0 ? (float) 100 * memoryStatus.usedSize / maxMemory : -1);
                }
            }

            if (print) {
                LOG.info(processCpuStatus.getDeltaString() + processMomoryStatus.getDeltaString() + processGCStatus.getDeltaString());
            }

        } catch (Exception e) {
            LOG.warn("no need care, the fail is ignored : vmInfo getDelta failed " + e.getMessage(), e);
        }
    }