欢迎您光临本小站。希望您在这里可以找到自己想要的信息。。。

PermGen and Metaspace

java water 1990℃ 0评论

PermGen is an abbreviation for Permanent Generation and it’s a special heap space which is separate from the main Java heap where JVM keeps track of metadata of the classes which have been loaded. In Java 8 PermGen has been renamed to Metaspace – with some subtle differences. From our perspective, it is important to note that Metaspace has unlimited default maximum size. On the contrary, PermGen from Java 7 and earlier has the default maximum size of 64 MB on 32-bit JVM and 82 MB on 64-bit one. Of course, these are not the same as the initial sizes. Java 7 and earlier starts with something around 12-21 MB of the initial PermGen space.

It is worthwhile to mention that prior to Java 7, interned Strings used to be kept on the PermGen. That used caused some serious problems with the infamous

java.lang.OutOfMemoryError: PermGen space

Whenever there is a need to resize PermGen/Metaspace, JVM will do it as it does with the standard heap. Resizing those spaces requires a full GC, which is always an expensive operation. It can be usually observed during a startup when a lot of classes are being loaded. Especially if the application has dependencies on many external libraries. If there are a lot of full GCs during the startup, it’s usually because of that. If that case, increasing the initial size can boost the startup performance.

JVM Default maximum PermGen size (MB) Default maximum Metaspace size
32-bit client JVM 64 unlimited
32-bit server JVM 64 unlimited
64-bit JVM 82 unlimited

To increase PermGen, we have the following commands:

-XX:PermSize=N – sets the initial (and minimum size) of the Permanent Generation space

-XX:MaxPermSize=N – sets the maximum size of the Permanent Generation space

In Java 8 and onwards, we can set the initial and maximum size of Metaspace using the following commands:

-XX:MetaspaceSize=N – sets the initial (and minimum size) of the Metaspace

-XX:MaxMetaspaceSize=N – sets the maximum size of the Metaspace

转载请注明:学时网 » PermGen and Metaspace

喜欢 (1)or分享 (0)

您必须 登录 才能发表评论!