Is there any way to measure the currently used size of permanent generation (PermGen) within my Java application? I cannot use external profiling tools such as VisualVM.
Even better would be an estimation of the memory consumption of a Java class in the PermGen. Is it nearly proportional to the size of the bytecode file?
PermGen is the memory area for storing class data like static variable,byte code and etc. By default 64 Mb is allocated for PermGen.
lang. OutOfMemoryError: PermGen Space is a runtime error in Java which occurs when the permanent generation (PermGen) area in memory is exhausted. The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays.
To fix it, increase the PermGen memory settings by using the following Java VM options. -XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size. In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.
Method Area is a part of space in the PermGen and it is used to store the class structure and the code for methods and constructors. The biggest disadvantage of PermGen is that it contains a limited size which leads to an OutOfMemoryError.
You could use MemoryMXBean that comes with JDK. But I don't think there is a way to query on the permgen usage from within a running application. Docs about MemoryMXBean.
You can use jvisualvm tool from JDK with Visual GC plugin to monitor all JVM heap areas including PermGen.
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