Search in sources :

Example 61 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project openj9 by eclipse.

the class TestManagementFactory method testMemoryMXBeanProxy.

@Test
public void testMemoryMXBeanProxy() {
    try {
        MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=Memory", MemoryMXBean.class);
        MemoryMXBean stdProxy = proxy;
        AssertJUnit.assertNotNull(stdProxy);
        AssertJUnit.assertNotNull(proxy.toString());
        AssertJUnit.assertEquals("java.lang:type=Memory", proxy.getObjectName().toString());
        MemoryUsage proxiedUsage = proxy.getHeapMemoryUsage();
        AssertJUnit.assertNotNull(proxiedUsage);
        AssertJUnit.assertTrue(proxiedUsage.getCommitted() > -1);
        AssertJUnit.assertTrue(proxiedUsage.getUsed() > -1);
        int proxiedCount = proxy.getObjectPendingFinalizationCount();
        AssertJUnit.assertTrue(proxiedCount > -1);
        AssertJUnit.assertEquals(proxy.isVerbose(), ManagementFactory.getMemoryMXBean().isVerbose());
    // TODO : Test out setVerbose when the VM API is implemented.
    } catch (IOException e) {
        Assert.fail("Unexpected IOException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) IOException(java.io.IOException) MemoryUsage(java.lang.management.MemoryUsage) Test(org.testng.annotations.Test)

Example 62 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project openj9 by eclipse.

the class MemoryMXBeanShutdownNotification method hookAction.

private static void hookAction() {
    logger.info("The hook thread is running.");
    try {
        MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
        logger.info("Bean successfully initialized " + bean.getObjectPendingFinalizationCount());
    } catch (Exception e) {
        unexpected(e);
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 63 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project pravega by pravega.

the class Main method onShutdown.

@VisibleForTesting
static void onShutdown(ControllerServiceMain controllerServiceMain) {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    boolean previousVerbose = memoryMXBean.isVerbose();
    memoryMXBean.setVerbose(true);
    try {
        log.info("Shutdown hook memory usage dump: Heap memory usage: {}, non heap memory usage {}", memoryMXBean.getHeapMemoryUsage(), memoryMXBean.getNonHeapMemoryUsage());
    } finally {
        memoryMXBean.setVerbose(previousVerbose);
    }
    log.info("Controller service shutting down");
    try {
        controllerServiceMain.stopAsync();
        controllerServiceMain.awaitTerminated();
    } finally {
        if (Config.DUMP_STACK_ON_SHUTDOWN) {
            Thread.getAllStackTraces().forEach((key, value) -> log.info("Shutdown Hook Thread dump: Thread {} stackTrace: {} ", key.getName(), value));
        }
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 64 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project egit by eclipse.

the class GitRepositoriesViewRepoDeletionTest method waitForFinalization.

/**
 * Best-effort attempt to get finalization to occur.
 *
 * @param maxMillis
 *            maximum amount of time in milliseconds to try getting the
 *            garbage collector to finalize objects
 */
private void waitForFinalization(int maxMillis) {
    long stop = System.currentTimeMillis() + maxMillis;
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    do {
        System.gc();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            break;
        }
    } while (System.currentTimeMillis() < stop && memoryBean.getObjectPendingFinalizationCount() > 0);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 65 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project openolat by klemens.

the class RuntimeWebService method getMemoryStatisticsVO.

private MemoryStatisticsVO getMemoryStatisticsVO() {
    MemoryStatisticsVO stats = new MemoryStatisticsVO();
    Runtime runtime = Runtime.getRuntime();
    stats.setUsedMemory((runtime.totalMemory() - runtime.freeMemory()) / mb);
    stats.setFreeMemory(runtime.freeMemory() / mb);
    stats.setTotalMemory(runtime.totalMemory() / mb);
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    stats.setInitHeap(memoryBean.getHeapMemoryUsage().getInit() / mb);
    stats.setInitNonHeap(memoryBean.getNonHeapMemoryUsage().getInit() / mb);
    stats.setUsedHeap(memoryBean.getHeapMemoryUsage().getUsed() / mb);
    stats.setUsedNonHeap(memoryBean.getNonHeapMemoryUsage().getUsed() / mb);
    stats.setCommittedHeap(memoryBean.getHeapMemoryUsage().getCommitted() / mb);
    stats.setCommittedNonHeap(memoryBean.getNonHeapMemoryUsage().getCommitted() / mb);
    stats.setMaxHeap(memoryBean.getHeapMemoryUsage().getMax() / mb);
    stats.setMaxNonHeap(memoryBean.getNonHeapMemoryUsage().getMax() / mb);
    long collectionTime = 0l;
    long collectionCount = 0l;
    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gcBean : gcBeans) {
        collectionCount += gcBean.getCollectionCount();
        collectionTime += gcBean.getCollectionTime();
    }
    stats.setGarbageCollectionCount(collectionCount);
    stats.setGarbageCollectionTime(collectionTime);
    return stats;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryStatisticsVO(org.olat.restapi.system.vo.MemoryStatisticsVO)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)84 MemoryUsage (java.lang.management.MemoryUsage)30 RuntimeMXBean (java.lang.management.RuntimeMXBean)18 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)12 IOException (java.io.IOException)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 ThreadMXBean (java.lang.management.ThreadMXBean)11 NotificationEmitter (javax.management.NotificationEmitter)10 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 ObjectName (javax.management.ObjectName)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Properties (java.util.Properties)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Notification (javax.management.Notification)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4