0

jmap can know size of each generation, but I want to monitor my java process real time.

With jmx, MemoryMXBean.getHeapMemoryUsage().getUsed() can get the total heap size. But I cannot find any method to get:

  1. Size of New (Young) and Tenured (Old) generations;
  2. Size of Eden and each Survivor in New generations.
auntyellow
  • 2,423
  • 2
  • 20
  • 47

1 Answers1

5

You can use ManagementFactory.getMemoryPoolMXBeans(). It shows all the memory regions. Depending on the GC you used, the names differ. pool.getCollectionUsage().getInit() gives the initial size of a pool. pool.getName() is for example 'G1 Eden Space' or 'G1 Old Gen' or 'G1 Survivor Space' if you use G1 GC.

pool.getUsage().getUsed() returns as well the amount of used memory for that region.

Ali Ben Zarrouk
  • 1,891
  • 16
  • 24