How to determine PermGen size in a Java application (i.e. Programmatically)?

  • Is there a way to measure the currently used constant generation size (PermGen) in my Java application? I cannot use external profiling tools such as VisualVM.

  • Even better would be to estimate the memory consumption of the Java class in PermGen. Is it nearly proportional to the size of the bytecode file?

+7
java memory-management memory-footprint
source share
5 answers

You can use MemoryMXBean, which comes with the JDK. But I don't think there is a way to request permgen from a running application. Documents about MemoryMXBean .

+9
source share

You can use the jvisualvm tool from the JDK with the Visual GC plugin to monitor all areas of the JVM heap, including PermGen.

+2
source share

If you are not on Windows, you can try jmap , which comes with the JDK.

+2
source share

You can use the jmap command:

jmap [option] (for connecting to a running process)

jmap [option] (for connecting to the main file)

jmap [option] [server_id @] (to connect to a remote debug server)

where the parameters are as follows:

-heap: print java summary

-permstat: for printing permanent generation statistics

+1
source share

The size of PermGen has nothing to do with the size of your class files. The default PermGen size according to Sun is 64 MB. If you want to increase it, you can set it explicitly using:

 -XX:PermSize=164m 

on your java command line or when running the script. This is also how you can know what it tuned without relying on an external tool.

EDIT:

Read this article to determine approximately how much PermGen is currently used programmatically (i.e. there are no external tools):

http://frankkieviet.blogspot.com/2006/10/how-to-fix-dreaded-permgen-space.html

0
source share

All Articles