Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Why does MaxPermSize exist?

Tags:

java

jvm

Why does MaxPermSize exist?

like image 337
Jonathan Allen Avatar asked Jul 28 '10 18:07

Jonathan Allen


People also ask

What is MaxPermSize in Java?

What it does. 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.

Why does Java 8 remove PermGen space?

The main reason for removing PermGen in Java 8 is: It is very hard to predict the required size of PermGen. It is fixed size at startup, so difficult to tune. Future improvements were limited by PermGen space.

What is MaxPermSize in Tomcat?

You can set the PermGen maximum limit with the following JVM parameter: -XX:MaxPermSize=256m. For performance reasons, it is recommended that the application is run in Server mode. Apache Tomcat does not run in Server mode by default. You can set the Server mode by using the JVM -server parameter.

What is permanent generation in Java?

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.


1 Answers

Here is a good article on the Permanent generation in the Garbage collector:

Presenting the Permanent Generation on Jon Masamitsu's Weblog

EDIT:

I haven't seen anything that would indicate why they made the design decision to have a max limit on the permanent generation size. But i imagine it was done for several reasons.

  1. It makes it much easier to implement, GCs are decidedly non trivial so simplifying your implementation in any way is probably a good idea.

  2. YAGNI (You aint gonna need it) most applications load a fixed number of classes and usually its not particularly large, so they have probably optimized for the common case and just picked a sane default and left it configurable.

  3. Assuming that your perm gen size is growing to be unpredictably large, then you probably have an error in a class loader (or need to rethink your architecture). Even in applications that do generate classes at run time (or do other such tricks) the number of generated classes is usually fixed as well, so you should be able to tune maxperm to fit your needs.

  4. I'm no expert on all the details of java class loading and garbage collection but they are both complicated parts of the JVM so i imagine that they would try to keep these two components as orthogonal as possible, and allowing for the perm gen to grow dynamically would probably couple these two components together in complicated ways (especially because both components have serious threading considerations)

  5. There are probably some performance benefits to capping the max perm generation, allowing it to grow might involve extra copying of the collection, or it might mean that your perm generation no longer exists in a contiguous address space, which could effect the way your other algorithms work for managing the collection.

Obviously these are all speculation. But even if all these are wrong i definitely don't think that it is 'idiotic' for sun to have chosen a fixed size, there are probably way more engineering and implementation considerations than i could even dream of :)

like image 153
luke Avatar answered Sep 19 '22 11:09

luke