當前位置: 首頁>>代碼示例>>Java>>正文


Java MemoryPoolMXBean類代碼示例

本文整理匯總了Java中java.lang.management.MemoryPoolMXBean的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean類的具體用法?Java MemoryPoolMXBean怎麽用?Java MemoryPoolMXBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MemoryPoolMXBean類屬於java.lang.management包,在下文中一共展示了MemoryPoolMXBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
@Override
public void run() {
    List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
        @Override
        public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
            return mbean.getName().equals(garbageCollector);
        }
    });

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        String pool = memoryPoolMXBean.getName();
        if (memoryPools.contains(pool)) {
            GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
            events.get(pool).slideAndInsert(event);
        }
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:GarbageCollectionCheck.java

示例2: reportUsage

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
private void reportUsage(MemoryPoolMXBean mxBean, MetricRecorder.Context metricContext)
{
    String name = mxBean.getName();
    Metric usedMetric = Metric.define("MemoryPoolUsed_" + name);
    Metric maxMetric = Metric.define("MemoryPoolMax_" + name);
    Metric percMetric = Metric.define("MemoryPoolUsage_" + name);

    MemoryUsage usage = mxBean.getUsage();
    long used = usage.getUsed();
    long max = usage.getMax();

    metricContext.record(usedMetric, used / M, Unit.MEGABYTE);

    // max can be undefined (-1) https://docs.oracle.com/javase/8/docs/api/java/lang/management/MemoryUsage.html
    if (max >= 0) {
        metricContext.record(maxMetric, max / M, Unit.MEGABYTE);

        double used_percent = 100.0 * ((double)used/(double)max);
        metricContext.record(percMetric, used_percent, Unit.PERCENT);
    }

}
 
開發者ID:awslabs,項目名稱:swage,代碼行數:23,代碼來源:MemoryPoolSensor.java

示例3: findInCache

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * WARNING: This should probably be moved to JvmMemPoolTableMetaImpl
 **/
private int findInCache(SnmpTableHandler handler,
                        String poolName) {

    if (!(handler instanceof SnmpCachedData)) {
        if (handler != null) {
            final String err = "Bad class for JvmMemPoolTable datas: " +
                handler.getClass().getName();
            log.error("getJvmMemPoolEntry", err);
        }
        return -1;
    }

    final SnmpCachedData data = (SnmpCachedData)handler;
    final int len = data.datas.length;
    for (int i=0; i < data.datas.length ; i++) {
        final MemoryPoolMXBean pool = (MemoryPoolMXBean) data.datas[i];
        if (poolName.equals(pool.getName())) return i;
    }
    return -1;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:JVM_MANAGEMENT_MIB_IMPL.java

示例4: buildPoolIndexMap

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:JvmMemMgrPoolRelTableMetaImpl.java

示例5: isTenured

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * Determines if the name of the memory pool MXBean provided matches a list of known tenured pool
 * names.
 * 
 * Package private for testing.
 * 
 * @param memoryPoolMXBean The memory pool MXBean to check.
 * @return True if the pool name matches a known tenured pool name, false otherwise.
 */
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
  if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
    return false;
  }

  String name = memoryPoolMXBean.getName();

  return name.equals("CMS Old Gen") // Sun Concurrent Mark Sweep GC
      || name.equals("PS Old Gen") // Sun Parallel GC
      || name.equals("G1 Old Gen") // Sun G1 GC
      || name.equals("Old Space") // BEA JRockit 1.5, 1.6 GC
      || name.equals("Tenured Gen") // Hitachi 1.5 GC
      || name.equals("Java heap") // IBM 1.5, 1.6 GC
      || name.equals("GenPauseless Old Gen") // azul C4/GPGC collector

      // Allow an unknown pool name to monitor
      || (HEAP_POOL != null && name.equals(HEAP_POOL));
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:28,代碼來源:HeapMemoryMonitor.java

示例6: getAllMemoryPoolNames

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * Returns the names of all available memory pools as a single string.
 */
private static String getAllMemoryPoolNames() {
  StringBuilder builder = new StringBuilder("[");

  for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) {
    builder.append("(Name=").append(memoryPoolBean.getName()).append(";Type=")
        .append(memoryPoolBean.getType()).append(";UsageThresholdSupported=")
        .append(memoryPoolBean.isUsageThresholdSupported()).append("), ");
  }

  if (builder.length() > 1) {
    builder.setLength(builder.length() - 2);
  }
  builder.append("]");

  return builder.toString();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:20,代碼來源:HeapMemoryMonitor.java

示例7: startJVMThresholdListener

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * Register with the JVM to get threshold events.
 * 
 * Package private for testing.
 */
void startJVMThresholdListener() {
  final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();

  // Set collection threshold to a low value, so that we can get
  // notifications after every GC run. After each such collection
  // threshold notification we set the usage thresholds to an
  // appropriate value.
  if (!testDisableMemoryUpdates) {
    memoryPoolMXBean.setCollectionUsageThreshold(1);
  }

  final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
  this.cache.getLoggerI18n().info(
      LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1,
      new Object[] {Long.valueOf(usageThreshold), memoryPoolMXBean.getName()});

  MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
  NotificationEmitter emitter = (NotificationEmitter) mbean;
  emitter.addNotificationListener(this, null, null);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:HeapMemoryMonitor.java

示例8: initCodeSizeLimits

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
public static void initCodeSizeLimits(int nMaxSizeMemPoolCodeCache, int nMaxSizeMemPoolPermGen)
{
	// PJD remove ibm JMV
	List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
	for (MemoryPoolMXBean p: pools)
	{
		if(p.getType().compareTo(MemoryType.NON_HEAP) == 0)
		{
			String cs = p.getName();
			if(cs.equalsIgnoreCase("Code Cache"))
				p.setUsageThreshold((long)nMaxSizeMemPoolCodeCache * 1024L * 1024L);
			else if(cs.equalsIgnoreCase("Perm Gen"))
				p.setUsageThreshold((long)nMaxSizeMemPoolPermGen * 1024L * 1024L);
		}
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:17,代碼來源:CodeManager.java

示例9: setMemThreshold

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
private void setMemThreshold()
{
	m_bMaxPermanentHeap_MoSet = false;

	List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
	for (MemoryPoolMXBean p: pools)
	{
		if(p.getType().compareTo(MemoryType.HEAP) == 0)
		{
			String cs = p.getName();
			if(cs.equalsIgnoreCase("Tenured gen"))
			{
				long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
				p.setUsageThreshold(l);
				m_tenuredPool = p;
			}				
		}
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:20,代碼來源:ThreadStatementGC.java

示例10: poolSummaries

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
/**
 * Returns a summary information about the memory pools.
 */
public static String poolSummaries() {
    // Why ? list-archive?4273859
    // How ? http://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage
    //       http://stackoverflow.com/questions/8356416/xxmaxpermsize-with-or-without-xxpermsize
    StringBuilder sb = new StringBuilder();
    Iterator<MemoryPoolMXBean> iter =
            ManagementFactory.getMemoryPoolMXBeans().iterator();
    while (iter.hasNext()) {
        MemoryPoolMXBean item = iter.next();
        String name = item.getName();
        MemoryType type = item.getType();
        MemoryUsage usage = item.getUsage();
        MemoryUsage peak = item.getPeakUsage();
        MemoryUsage collections = item.getCollectionUsage();
        sb.append(String.format("Memory pool name: " + name
                                + ", type: " + type
                                + ", usage: " + usage
                                + ", peak: " + peak
                                + ", collections: " + collections
                                + "\n"));
    }
    return sb.toString();
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:27,代碼來源:Memory.java

示例11: eatMetaspace

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
private List<Object> eatMetaspace(float targetUsage) {
    List<Object> list = new ArrayList<>();
    MemoryPoolMXBean metaspacePool = getMatchedMemoryPool(".*Metaspace.*");
    float currentUsage;
    GeneratedClassProducer gp = new GeneratedClassProducer();
    do {
        try {
            list.add(gp.create(0));
        } catch (OutOfMemoryError oome) {
            list = null;
            throw new RuntimeException("Unexpected OOME '" + oome.getMessage() + "' while eating " + targetUsage + " of Metaspace.");
        }
        MemoryUsage memoryUsage = metaspacePool.getUsage();
        currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax());
    } while (currentUsage < targetUsage);
    return list;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:GarbageProducer.java

示例12: runTest

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
protected void runTest() {
    long headerSize = CodeCacheUtils.getHeaderSize(btype);
    long allocationUnit = Math.max(0, CodeCacheUtils.MIN_ALLOCATION - headerSize);
    MemoryPoolMXBean bean = btype.getMemoryPool();
    long initialCount = bean.getUsageThresholdCount();
    long initialSize = bean.getUsage().getUsed();
    bean.setUsageThreshold(initialSize + THRESHOLD_STEP);
    for (int i = 0; i < ALLOCATION_STEP - 1; i++) {
        CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);
    }
    // Usage threshold check is triggered by GC cycle, so, call it
    CodeCacheUtils.WB.fullGC();
    checkUsageThresholdCount(bean, initialCount);
    long filledSize = bean.getUsage().getUsed();
    bean.setUsageThreshold(filledSize + THRESHOLD_STEP);
    for (int i = 0; i < ALLOCATION_STEP - 1; i++) {
        CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);
    }
    CodeCacheUtils.WB.fullGC();
    checkUsageThresholdCount(bean, initialCount);
    System.out.println("INFO: Case finished successfully for " + bean.getName());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:UsageThresholdIncreasedTest.java

示例13: runTest

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
protected void runTest() {
    int iterationsCount
            = Integer.getInteger("jdk.test.lib.iterations", 1);
    MemoryPoolMXBean bean = btype.getMemoryPool();
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
            addNotificationListener(this, null, null);
    for (int i = 0; i < iterationsCount; i++) {
        CodeCacheUtils.hitUsageThreshold(bean, btype);
    }
    Asserts.assertTrue(
            Utils.waitForCondition(
                    () -> (CodeCacheUtils.isCodeHeapPredictable(btype) ?
                            (counter == iterationsCount) : (counter >= iterationsCount)),
                    WAIT_TIME),
            "Couldn't receive expected notifications count");
    try {
        ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
                removeNotificationListener(this);
    } catch (ListenerNotFoundException ex) {
        throw new AssertionError("Can't remove notification listener", ex);
    }
    System.out.printf("INFO: Scenario finished successfully for %s%n",
            bean.getName());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ThresholdNotificationsTest.java

示例14: runTest

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
protected void runTest() {
    MemoryPoolMXBean bean = btype.getMemoryPool();
    long initialThresholdCount = bean.getUsageThresholdCount();
    long initialUsage = bean.getUsage().getUsed();

    bean.setUsageThreshold(initialUsage + 1 + CodeCacheUtils.MIN_ALLOCATION);
    long size = CodeCacheUtils.getHeaderSize(btype);

    CodeCacheUtils.WB.allocateCodeBlob(Math.max(0, CodeCacheUtils.MIN_ALLOCATION
            - size), btype.id);
    // a gc cycle triggers usage threshold recalculation
    CodeCacheUtils.WB.fullGC();
    CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), initialThresholdCount,
            String.format("Usage threshold was hit: %d times for %s. "
                    + "Threshold value: %d with current usage: %d",
                    bean.getUsageThresholdCount(), bean.getName(),
                    bean.getUsageThreshold(), bean.getUsage().getUsed()));
    System.out.println("INFO: Case finished successfully for " + bean.getName());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:UsageThresholdNotExceededTest.java

示例15: main

import java.lang.management.MemoryPoolMXBean; //導入依賴的package包/類
public static void main(String[] args) {
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    boolean verified = false;
    for (MemoryPoolMXBean i : pools) {
        if ((i.getUsage().getMax() >= TWO_G)
                && i.isUsageThresholdSupported()) {
            i.setUsageThreshold(TWO_G);
            if(i.getUsageThreshold() != TWO_G)
                throw new RuntimeException("Usage threshold for"
                        + " pool '" + i.getName() + "' is " + i.getUsageThreshold()
                        + " and not equal to 2GB");
            verified = true;
        }
    }
    System.out.println("Ability to use big heap thresholds has "
            + (verified ? "" : "NOT ") + "been verified");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:LargeHeapThresholdTest.java


注:本文中的java.lang.management.MemoryPoolMXBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。