Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I discover what is in the permanent generation

Given a heapdump or a running VM, how do I discover what the contents of the permanent generation is ? I know about 'jmap -permstat' but that's not available on Windows.

like image 883
Tom Avatar asked Oct 11 '08 18:10

Tom


People also ask

What is permanent generation?

PermGen (Permanent Generation) is a special heap space separated from the main memory heap. The JVM keeps track of loaded class metadata in the PermGen. Additionally, the JVM stores all the static content in this memory section.

What is stored in Perm Generation Space in Java?

The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays. Therefore, the PermGen size requirements depend on the number of classes and methods as well as their size. Java memory is separated into different regions - Young, Tenured and PermGen.

Is permanent generation part of stack?

permanent-generation is not part of heap Save this answer.

What is PermSize?

-XX:PermSize : It's is initial value of Permanent Space which is allocated at startup of JVM. Examples of using -XX:PermSize VM (JVM) option in java > Example1 of using -XX:PermSize VM (JVM) option in java > java -XX:PermSize=512 MyJavaProgram. It will set initial value of Permanent Space as 512 bytes to JVM.


2 Answers

This article Memory Monitoring with Java SE 5 describes how to programmatically discover information on heap usage, memory pools (including permgen space) and so on. Its very simple:

    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    long nonHeapFree = usage.getMax() - usage.getUsed();
    long nonHeapTotal = usage.getMax();

In my testing on OSX (Sun VM) "non heap memory usage" matches the values returned for the permgen pool closely and presumably will do something useful on VMs that don't have permgen.

like image 173
David Tinker Avatar answered Sep 22 '22 02:09

David Tinker


The permanent generation contains the class object. So you should check the heap dump or other form of object list for classes. If you have problem with the size of permanent generation usually it is caused by two reason:

  • your program or a library you use creates classes dynamically and the default size of permanent generation is too small - simple increate the size with -XX:MaxPermSize=256m
  • your program or a library you use creates new classes dynamically every time it is called, so the size of permanent generation increases non-stop - this is a programming error you should fix it (or search a fix/create a bug report)

To see which is your case check the size of the permanent generation over a larger period.

And a good overview about permanent generation:

http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation

like image 28
laszlot Avatar answered Sep 21 '22 02:09

laszlot