Permanent Generation Heap Space and Metaspace
- Permanent Generation Heap Space in Java
- Key Characteristics of PermGen in Java
- PermGen Vs Metaspace in Java
- Metaspace (Java 8)
This brief demonstration of JVM memory spaces explores how the Java Virtual Machine handles user data memory allocation. Although we will not cover this topic with graphs, it is rather basic, and we believe our explanation will suffice to form your clarity.
In addition, we will compare the PermGen to the Metaspace and both. This brief article contains a lot of information for you, so keep reading to find out more.
Permanent Generation Heap Space in Java
The PermGen is a short form of permanent generation heap space used by Java Virtual Machine. It is the space that occupies all the classes, methods, objects, internalized strings, etc.
For most applications, permanent generation has no discernible effect on garbage collector efficiency. Nevertheless, some applications dynamically create and load many classes, such as JSPs.
If such a case arises, we can use the command line to increase the
MAX: PermGen size. Command to increase MAX:
But there is one thing to keep in mind here. Since Java has removed this memory space in the Java Development Kit Version 8 release, we will be hit with these warnings if we use these tuning flags in Java 8 or later.
>> java -XX:PermSize=100m -XX:MaxPermSize=200m -version OpenJDK 64-Bit Server VM warning: Ignoring option PermSize; support was removed in 8.0 OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Key Characteristics of PermGen in Java
PG is also included in the full garbage collection:
- Space for JVM Class Metadata.
- The internal representation of Java Classes in Hotspot.
- Information about the class structure, fields, and identifiers.
- Information on method compilation and bytecodes.
- Always-on pool and symbolic resolution.
Common Issues With PermGen:
- Limited memory for
- Out of memory error issue.
- Class unloading was triggered due to the application reference.
MaxPermSize(64-MB to 85-MB only).
Besides these issues, there are others that you should read here: 1, 2.
PermGen Vs Metaspace in Java
Since Java 8, we have seen the replacement of PermGen with Metaspace. Slight differences were also prevalent in this change.
For example, the Metaspace has an unlimited default maximum size, while the former did not. If we read the official docs, we learn that the PermGen has a default maximum size of 64 MB on 32-bit JVMs.
Likewise, it has 82 MB on 64-bit JVMs in Java 7 and older versions. But since now you know that the out-of-memory error is no longer a concern.
Must we not explore Metaspace instead? Obviously, yes.
Metaspace (Java 8)
Please take it as a container, a place where the Java VM hold your memory, such as classes, methods, variables, strings, and so on, since we have already signified the most important differences between the older memory space and this one.
So without any delay, let us find out what is different in Metaspace?
The following table compares and contrasts Metaspace and PermGen.
|1||The PermGen Space was eliminated in Java 8.||The new space metaspace replaced it, which was released with Java 8.|
|2||It always had a constant memory size, as the name suggests.||Dynamic allocation of memory depending on the Operating System.|
|3||Ineffective Garbage Collector (GC).||Effective GC|
Nevertheless, if you want to learn more on this, please refer to this link: Virtual Machine Garbage Collection Tuning.
Even though it was a brief and to-the-point article, we presented a short characterization of permanent generation and metaspace memory spaces, garbage collectors’ role, and how the JVM structures all of them.
Besides that, we differentiated each with real-time examples and cited helpful references. In a nutshell, the permanent generation is still present in JDK 7 and earlier versions.
The Metaspace, on the other hand, offers more reliable and flexible memory space for our applications.