Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the permanent generation always collected serially on the HotSpot VM?

From reading a rather mature Oracle blog entry, I learned that

(...) the permanent generation is currently collected serially.

However, this blog entry is from quite some years ago and I was wondering how the recent advancements in garbage collection algorithms might have changed the accuracy of this statement. I am especially wondering about the new G1 garbage collector which is desribed by Oracle with:

The older garbage collectors (serial, parallel, CMS) all structure the heap into three sections: young generation, old generation, and permanent generation of a fixed memory size. (...) When performing garbage collections, G1 operates in a manner similar to the CMS collector.

but never mentions the permanent generation in the entire tutorial again.

From reading about CMS - which according to the above statement works similar to G1 - I did not find any explicit information on the permanent generation either but learned from this other blog entry that

(...) the Concurrent Mark and Sweep does not compact at all. Once objects cannot be allocated anymore a serial major GC is triggered.

So I am wondering if modern garbage collectors, such as CMS or G1, just completely ignore the permanent generation and leave it to full GC invocations which run the old serial GC to clean out the permanent generation (while this serial GC also collects the young and mature generations serially which I would not understand to be desirable when G1 was used instead of CMS). I am mainly interested in finding out if it is more expensive in terms of STW and collection time to perform garbage collection on the permanent generation than it is to collection the tenured generation.

Bonus question: The Oracle tutorial mentions that the permanent generation is part of the heap. I always thought that the permanant generation was explicitly allocated outside of the heap. Did this change in recent HotSpot implementations?

Thank you for your help!

like image 795
Rafael Winterhalter Avatar asked Dec 08 '13 12:12

Rafael Winterhalter


People also ask

Which generation is collected quickly during GC in the Hotspot JVM?

Young Generation. Most newly allocated objects are allocated in the young generation (see Figure 1), which is typically small and collected frequently.

Does garbage collection occur in permanent generation space in JVM?

Permanent Generation It is populated by the JVM at runtime based on classes in use by the application. Classes that are no longer in use may be garbage collected from the Permanent Generation.

Which garbage collector is most suitable for long running process in the Hotspot VM?

Parallel GC As the name implies, it uses multiple VM threads to perform the garbage collection. It also executes in a stop-the-world fashion. Applications that require a high rate of throughput can benefit from this GC.

Is PermGen garbage collected?

The PermGen is garbage collected like the other parts of the heap. The thing to note here is that the PermGen contains meta-data of the classes and the objects i.e. pointers into the rest of the heap where the objects are allocated.


1 Answers

There is a JEP156 about making G1 able to unload classes without a full GC, but the dependences section states that it makes sense to wait with [JEP122] until the permanent generation is gone to make JEP156 easier to implement.

So it looks like that this problem may indeed be solved in Java 8, but not just thanks to the meta space, instead because meta space is taken as a pre-requisite to do incremental GC of classes.

That's my understanding.

edit: Over the past few days I've been listening to some of this year's JavaOne sessions and quite luckily I found one just today about PermGen removal that says it all:

  • HotSpot currently requires full GC to collect PermGen
  • This will still be true even after introduction of Metaspace
  • The summary slide at the end seems to confirm that JEP156 is still planned (but she does not talk about it)
  • It even answers the bonus question for which I had an answer but no source: Yes, PermGen is in the heap
like image 58
Djizeus Avatar answered Sep 27 '22 18:09

Djizeus