Java Code Examples for java.lang.management.MemoryPoolMXBean.setUsageThreshold()

The following are Jave code examples for showing how to use setUsageThreshold() of the java.lang.management.MemoryPoolMXBean class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ChronoBike   File: CodeManager.java   View Source Code Vote up 6 votes
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);
		}
	}
}
 
Example 2
Project: ChronoBike   File: ThreadStatementGC.java   View Source Code Vote up 6 votes
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;
			}				
		}
	}
}
 
Example 3
Project: openjdk-jdk10   File: UsageThresholdIncreasedTest.java   View Source Code Vote up 6 votes
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());
}
 
Example 4
Project: openjdk-jdk10   File: UsageThresholdNotExceededTest.java   View Source Code Vote up 6 votes
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());
}
 
Example 5
Project: openjdk-jdk10   File: LargeHeapThresholdTest.java   View Source Code Vote up 6 votes
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");
}
 
Example 6
Project: openjdk-jdk10   File: CodeCacheUtils.java   View Source Code Vote up 5 votes
public static final void hitUsageThreshold(MemoryPoolMXBean bean,
        BlobType btype) {
    long initialSize = bean.getUsage().getUsed();
    bean.setUsageThreshold(initialSize + 1);
    long usageThresholdCount = bean.getUsageThresholdCount();
    long addr = WB.allocateCodeBlob(1, btype.id);
    WB.fullGC();
    Utils.waitForCondition(()
            -> bean.getUsageThresholdCount() == usageThresholdCount + 1);
    WB.freeCodeBlob(addr);
}
 
Example 7
Project: openjdk-jdk10   File: PoolsIndependenceTest.java   View Source Code Vote up 4 votes
protected void runTest() {
    MemoryPoolMXBean bean = btype.getMemoryPool();
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
            addNotificationListener(this, null, null);
    bean.setUsageThreshold(bean.getUsage().getUsed() + 1);
    long beginTimestamp = System.currentTimeMillis();
    CodeCacheUtils.WB.allocateCodeBlob(
            CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    CodeCacheUtils.WB.fullGC();
    /* waiting for expected event to be received plus double the time took
     to receive expected event(for possible unexpected) and
     plus 1 second in case expected event received (almost)immediately */
    Utils.waitForCondition(() -> {
        long currentTimestamp = System.currentTimeMillis();
        int eventsCount
                = counters.get(btype.getMemoryPool().getName()).get();
        if (eventsCount > 0) {
            if (eventsCount > 1) {
                return true;
            }
            long timeLastEventTook
                    = beginTimestamp - lastEventTimestamp;
            long timeoutValue
                    = 1000L + beginTimestamp + 3L * timeLastEventTook;
            return currentTimestamp > timeoutValue;
        }
        return false;
    });
    for (BlobType bt : BlobType.getAvailable()) {
        int expectedNotificationsAmount = bt.equals(btype) ? 1 : 0;
        CodeCacheUtils.assertEQorGTE(btype, counters.get(bt.getMemoryPool().getName()).get(),
                expectedNotificationsAmount, String.format("Unexpected "
                        + "amount of notifications for pool: %s",
                        bt.getMemoryPool().getName()));
    }
    try {
        ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
                removeNotificationListener(this);
    } catch (ListenerNotFoundException ex) {
        throw new AssertionError("Can't remove notification listener", ex);
    }
    System.out.printf("INFO: Scenario with %s finished%n", bean.getName());
}