Permanent Generation Heap Space and Metaspace

Sarwan Soomro Feb 16, 2024
  1. Permanent Generation Heap Space in Java
  2. Key Characteristics of PermGen in Java
  3. PermGen Vs Metaspace in Java
  4. Metaspace (Java 8)
  5. Summary
Permanent Generation Heap Space and Metaspace

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.

Note
The said apps could require a larger permanent generation to accommodate the extra classes.

If such a case arises, we can use the command line to increase the MAX: PermGen size. Command to increase MAX: PermGen Size: -XX:MaxPermSize=SIZE, -XX:PermSize=[size].

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:

  1. Space for JVM Class Metadata.
  2. The internal representation of Java Classes in Hotspot.
  3. Information about the class structure, fields, and identifiers.
  4. Information on method compilation and bytecodes.
  5. Variables
  6. Always-on pool and symbolic resolution.

Common Issues With PermGen:

  1. Limited memory for MaxPermSize.
  2. Larger MaxPermSize caused restarts.
  3. Out of memory error issue.
  4. Class unloading was triggered due to the application reference.
  5. 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.

S.N Permanent Generation Metaspace
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
Note
The PermGen out of memory error is no longer the issue since its replacement with the Metaspace.

Nevertheless, if you want to learn more on this, please refer to this link: Virtual Machine Garbage Collection Tuning.

Summary

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.

Sarwan Soomro avatar Sarwan Soomro avatar

Sarwan Soomro is a freelance software engineer and an expert technical writer who loves writing and coding. He has 5 years of web development and 3 years of professional writing experience, and an MSs in computer science. In addition, he has numerous professional qualifications in the cloud, database, desktop, and online technologies. And has developed multi-technology programming guides for beginners and published many tech articles.

LinkedIn