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();
}
}
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);
}
}
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));
}
}
}
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);
}
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;
}
Aggregations