I am trying to find out programatically the max permgen and max heap size with which a the JVM for my program has been invoked, not what is currently available to them.
Is there a way to do that?
I am familiar with the methods in Java Runtime object, but its not clear what they really deliver.
Alternatively, is there a way to ask Eclipse how much was allocated for these two?
1. Overview In this quick tutorial, we're going to get familiar with a few different ways to get the heap size of a running Java application. To find the heap and metaspace related info of a running Java application, we can use the jcmd command-line utility: First, let's find the process id of a particular Java application using the jps command:
PermGen contains meta-data of the classes and the objects i.e. pointers into the rest of the heap where the objects are allocated. The PermGen also contains Class-loaders which have to be manually destroyed at the end of their use else they stay in memory and also keep holding references to their objects on the heap.
Java Heap space: Java objects are instantiations of Java classes. Our JVM has an internal representation of those Java objects and those internal representations are stored in the heap. This Java heap memory is divided again into regions, called generations. Eden Space : When object created using new keyword memory allocated on this space.
Our JVM has an internal representation of those Java objects and those internal representations are stored in the heap. This Java heap memory is divided again into regions, called generations. Eden Space : When object created using new keyword memory allocated on this space. Newly created objects are usually located in this space.
Try something like this for max perm gen:
public static long getPermGenMax() {
for (MemoryPoolMXBean mx : ManagementFactory.getMemoryPoolMXBeans()) {
if ("Perm Gen".equals(mx.getName())) {
return mx.getUsage().getMax();
}
}
throw new RuntimeException("Perm gen not found");
}
For max heap, you can get this from Runtime, though you can also use the appropriate MemoryPoolMXBean.
Try this ones:
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
mem.getHeapMemoryUsage().getUsed();
mem.getNonHeapMemoryUsage().getUsed();
But they only offer snapshot data, not a cummulated value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With