简体   繁体   中英

Permgen is part of heap or not?

I have found picture from official oracle site 在此处输入图片说明

but in popular SO answer I have found that permanent generation is not part of heap

Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.

I messed with these contradictory datas. I believe that at both places data valid but with reservations. Please clarify this question for me.

PS

let speak only about Sun/Oracle jvms.

PS2

I have read explanation of jvm gcs(serial,parallel, cms and g1) and I didn't see mentions about permgen it argument to side that permanent generation is not heap part.

I believe you are referring the diagram from here , about Oracle's official site, and yes they are quoting "permanent generation" as heap area but I guess intent was just trying to explain the "generations" in JVM memory; but as per best of my knowledge (and I guess many experts will agree with it) "permanent generation" is not part of heap area, it is part of non-heap area which is used by JVM to internal purpose like JIT optimization, method areas etc .

Oracle official references

I would like to quote below 3 official Oracle references to help you get convinced that "permanent generation" is not part of heap area.

  1. jConsole guide from Oracle .
  2. Blog of a Oracle GC developer .
  3. Oracle article on GC tuning

In the first link above, you can clearly see that it is explained that Java manages 2 kind of memory - Heap and Non-Heap Memory , and then they have listed "generations" present in each type of memory. You can read this section in the link "Monitoring Memory Consumption", and below is some excerpt.

在此处输入图片说明 在此处输入图片说明

Then in the second link from above , GC developer has very well explained the purpose and insight of "permanent generation", using which it can be clearly understood that "permanent generation" is not a heap area, see below diagram from the blog:

在此处输入图片说明

Then in the third link from above , you can refer the memory measurements done in section 3.2 "Measurement", which also makes it clear that "permanent generation" is not part of heap area.

Also, you would know that after a full GC in "Tenured generation", in worst case JVM would throw out of memory exception but would not promoted the objects to "permanent generation" because it is not part of heap area.

Non-Oracle references

Checkout below diagram, and many such diagrams can be found which explains the memory tuning arguments of JVM. If you see from memory tuning JVM arguments perspective as well then also it is self-evident that "permanent generation" is not part of heap area.

在此处输入图片说明

In the end

Now, I think it should be clear to you that the diagram (and its article) was just meant to explain the JVM memory concept from "generations" perspective, but in implementation JVM doesn't consider "permanent generation" to be part of heap memory where it can promote the long-lived objects.

Java 8 has no PermGen, however the MetaSpace provide the same function and works similar but no the same.

Java <= 7 has a PermGen and while it is a Java managed space is it not the same heap which objects are allocated in. It doesn't count towards the maximum heap size nor does it count toward the 32 GB limit addressable by CompressOops for example. It is cleaned up as a part of the garbage collection.

It makes sense to have it in the same diagram, but it doesn't mean PermGen/MetaSpace is part of the same heap.

Also note that when the heap space runs out you get

java.lang.OutOfMemoryError: Heap space space

However when you run out of PermGen you get a different error.

java.lang.OutOfMemoryError: PermGen space

https://plumbr.eu/outofmemoryerror/java-heap-space

https://plumbr.eu/outofmemoryerror/permgen-space

https://plumbr.eu/outofmemoryerror/metaspace

Permgen is fixed size memory area in Java 7 and earlier releases. It has been removed in Java 8 ( release notes ). There are the following reasons behind removal I'm aware of:

  1. Merge of hotshot and jrockit
  2. 'java.lang.OutOfMemoryError: PermGen space' appearing in applications that do bytecode generation

The memory objects that took place in permgen are placed to metaspace since Java 8. Metaspace is resizable memory area and is placed into heap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM