Is Method area still present in Java 8?

孤街醉人 提交于 2020-01-12 09:16:56

问题


Prior to Java 8 we had 5 major runtime data areas:

  1. Method Area
  2. Heap
  3. JVM Stacks
  4. PC registers
  5. Native method stacks

With Java 8, there is no Perm Gen, that means there is no more “java.lang.OutOfMemoryError: PermGen”

which is great but I also read

Method Area is part of space in the Perm Gen

but I can't seem to find anything which explicitly says Method area is no more in Java 8.

So is Perm Gen along with Method area got removed or only Perm Gen got removed and Method area is still present in old generation.

Please attach any good source material that you may have seen related to Java 8 Memory Model


回答1:


Since Method Area is a logical concept described in the specification, every JVM has a Method Area, though that doesn’t imply that it has to be reflected in the implementation code. Likewise, the Java Heap Space is specified as a concept in the specification, to be the storage of all Java objects, therefore all Java objects are stored in the Heap, per definition, regardless of how it is actually implemented.

Unlike the Perm Gen, which contained Java objects and JVM data structures other than Java objects, the memory layout of the HotSpot JVM for Java 8 has a clear separation. The Old Gen still only contains Java objects, whereas the Metaspace only contains JVM specific data and no Java objects. So Java objects formerly stored in the Perm Gen have been moved to the Old Gen. Since the Method Area contains artifacts “such as the run-time constant pool, field and method data, and the code for methods and constructors…”, in other words non-Java-objects (the pool may contain references to heap objects though), it is part of the Metaspace now.

You could now discuss whether the Metaspace is an implementation of Method Area or may contain more than the Method Area, but this has no practical relevance. Practically, the JVM contains code to manage the Metaspace and its contained artifacts and does not need to care whether these artifacts do logically belong to what the specification describes as “Method Area” or not.



来源:https://stackoverflow.com/questions/50163218/is-method-area-still-present-in-java-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!