302

Specifically, why would it help to fix a PermGen OutOfMemoryError issue?

Also, bonus points for an answer that points me to the documentation on JVM arguments...

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Zefira
  • 4,329
  • 3
  • 25
  • 31
  • http://mark.koli.ch/2009/01/understanding-javas-perm-gen-maxpermsize-heap-space-etc.html – Paul Tomblin Aug 24 '12 at 17:40
  • 6
    http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html How will you give me those bonus points now ? :) – Denys Séguret Aug 24 '12 at 17:40
  • 1
    @PaulTomblin I'm not sure the guy whose article you're linking to (the first result by Google) has any idea of what he's speaking about. – Denys Séguret Aug 24 '12 at 17:52
  • @dystroy I could send you a cookie? Or you could just take satisfaction in a question well answered ;) – Zefira Aug 27 '12 at 18:27
  • 6
    This does not answer the question specifically but if you are looking at JVM memory management, the best articles I have read on it are [this](http://www.infoq.com/articles/G1-One-Garbage-Collector-To-Rule-Them-All) and this [infoq link](http://www.infoq.com/articles/Java_Garbage_Collection_Distilled) – Abe Aug 16 '13 at 19:40

3 Answers3

314

The permanent space is where the classes, methods, internalized strings, and similar objects used by the VM are stored and never deallocated (hence the name).

This Oracle article succinctly presents the working and parameterization of the HotSpot GC and advises you to augment this space if you load many classes (this is typically the case for application servers and some IDE like Eclipse) :

The permanent generation does not have a noticeable impact on garbage collector performance for most applications. However, some applications dynamically generate and load many classes; for example, some implementations of JavaServer Pages (JSP) pages. These applications may need a larger permanent generation to hold the additional classes. If so, the maximum permanent generation size can be increased with the command-line option -XX:MaxPermSize=.

Note that this other Oracle documentation lists the other HotSpot arguments.

Update : Starting with Java 8, both the permgen space and this setting are gone. The memory model used for loaded classes and methods is different and isn't limited (with default settings). You should not see this error any more.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
97

-XX:PermSize -XX:MaxPermSize are used to set size for Permanent Generation.

Permanent Generation: The Permanent Generation is where class files are kept. These are the result of compiled classes and JSP pages. If this space is full, it triggers a Full Garbage Collection. If the Full Garbage Collection cannot clean out old unreferenced classes and there is no room left to expand the Permanent Space, an Out‐of‐ Memory error (OOME) is thrown and the JVM will crash.

sampathsris
  • 21,564
  • 12
  • 71
  • 98
stones333
  • 8,588
  • 1
  • 25
  • 27
58

In Java 8 that parameter is commonly used to print a warning message like this one:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0

The reason why you get this message in Java 8 is because Permgen has been replaced by Metaspace to address some of PermGen's drawbacks (as you were able to see for yourself, one of those drawbacks is that it had a fixed size).

FYI: an article on Metaspace: http://java-latte.blogspot.in/2014/03/metaspace-in-java-8.html

AndrewBourgeois
  • 2,634
  • 7
  • 41
  • 58
  • 7
    See also: [PermGen elimination in JDK 8](http://stackoverflow.com/questions/18339707/permgen-elimination-in-jdk-8) (stackoverflow). – will Dec 30 '14 at 23:29