Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'PermSize' in Java?

Tags:

java

memory

I was going through the document in Java Memory Management and in that I came across PermSize which I couldn't understand. The document says that it stores, "JVM stores its metadata", but I couldn't exactly get what is meant by metadata. I was googling and somewhere I read it stores a value object (user defined object).

What kind of objects are stored there? An example with an explanation would be great.

like image 901
Anand Avatar asked Oct 27 '09 23:10

Anand


People also ask

What is PermSize in Tomcat?

Solution. By default, Tomcat is assigned a very little PermGen memory for the running process. 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.

What does XX PermSize mean?

The -XX:MaxPermSize option specifies the maximum size for the permanent generation, which is the memory holding objects such as classes and methods. Properly tuning this parameter can reduce memory issues in the permanent generation.

What is meta space in Java?

Simply put, Metaspace is a new memory space – starting from the Java 8 version; it has replaced the older PermGen memory space. The most significant difference is how it handles memory allocation. Specifically, this native memory region grows automatically by default.

What is Metaspace size in Java?

Metaspace is introduced in Java 8 and default size of it is unlimited(limited to physical memory) with dynamic growth.


2 Answers

A quick definition of the "permanent generation":

"The permanent generation is used to hold reflective data of the VM itself such as class objects and method objects. These reflective objects are allocated directly into the permanent generation, and it is sized independently from the other generations." [ref]

In other words, this is where class definitions go (and this explains why you may get the message OutOfMemoryError: PermGen space if an application loads a large number of classes and/or on redeployment).

Note that PermSize is additional to the -Xmx value set by the user on the JVM options. But MaxPermSize allows for the JVM to be able to grow the PermSize to the amount specified. Initially when the VM is loaded, the MaxPermSize will still be the default value (32mb for -client and 64mb for -server) but will not actually take up that amount until it is needed. On the other hand, if you were to set BOTH PermSize and MaxPermSize to 256mb, you would notice that the overall heap has increased by 256mb additional to the -Xmx setting.

like image 92
Pascal Thivent Avatar answered Sep 29 '22 18:09

Pascal Thivent


This blog post gives a nice explanation and some background. Basically, the "permanent generation" (whose size is given by PermSize) is used to store things that the JVM has to allocate space for, but which will not (normally) be garbage-collected (hence "permanent") (+). That means for example loaded classes and static fields.

There is also a FAQ on garbage collection directly from Sun, which answers some questions about the permanent generation. Finally, here's a blog post with a lot of technical detail.

(+) Actually parts of the permanent generation will be GCed, e.g. class objects will be removed when a class is unloaded. But that was uncommon when the permanent generation was introduced into the JVM, hence the name.

like image 38
sleske Avatar answered Sep 29 '22 19:09

sleske