We will discuss here why PermGen space was removed from Java 8. If you specify the JVM arguments PermSize and MaxPermSize then these arguments are ignored by Java HotSpot and JVM issues warnings.
The warning may look like “Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0”.
PermGen Space and Metaspace
The PermGen or permanent generation space is a special space because it holds meta-data describing user classes, i.e., classes that are not part of the Java language.
Examples of such meta-data are objects describing classes and methods, such as, fully qualified name of the class, fully qualified name of the immediate parent class, variable information, constructor information, constant pool, static fields, etc. and they are stored in the PermGen space.
Applications with large code-base can quickly fill up this segment of the heap which will cause
java.lang.OutOfMemoryError: PermGen, no matter how high your
-Xmx and how much memory you have on the machine.
Static methods and variables were Stored in the PermGen space prior to Java version 8. But now in Java 8, a new memory space was introduced, called MetaSpace, where all fields of the class, methods of a class with the byte code of the methods, constant pool, JIT optimizations, etc are stored.
There are few advantages of MetaSpace:
- Storage area is loaded per class loader
- Linear allocation
- No individual reclaim except redefine classes and class loading failure
- No GC scan or compaction
- No relocation for metaspace objects
The maximum metaspace size can be set using -XX:MaxMetaspaceSize argument and the default size is unlimited, which means your system memory is the limit.
The -XX:MetaspaceSize flag only defines the initial size of the metaspace and if you do not specify anything then metaspace will allocate the memory dynamically depending on the application’s demand at runtime.
Reason for removing PermGen
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
- It deallocates class data concurrently but not during GC pause
- You will never get java.lang.OutOfMemoryError
- It helps in improving Garbage Collection Performance by reclaiming the JVM memory
Thanks for reading.Tags: Java FAQs