Java 8中仍然存在“方法"区域吗? [英] Is Method area still present in Java 8?

查看:293
本文介绍了Java 8中仍然存在“方法"区域吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java 8之前,我们有5个主要的运行时数据区域:

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

  1. 方法区域
  2. JVM堆栈
  3. PC寄存器
  4. 本机方法堆栈

在Java 8中,没有Perm Gen,这意味着不再有 "java.lang.OutOfMemoryError:PermGen"

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

这很棒,但我也读过

方法区域是Perm Gen中空间的一部分

Method Area is part of space in the Perm Gen

但是我似乎找不到任何明确表明Java 8中不再存在Method区域的东西.

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

Perm Gen和Method区域也被删除了,或者只有Perm Gen被删除了 已删除,方法区域仍旧存在.

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.

请附上您可能看到的与Java 8内存模型有关的任何良好的源材料

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

推荐答案

由于 Java堆空间在规范中被指定为一个概念,用于存储所有Java对象,因此,无论定义如何实现,所有Java对象均按定义存储在Heap中.

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.

与包含Java对象和Java对象以外的JVM数据结构的Perm Gen不同,用于Java 8的HotSpot JVM的内存布局有明显的分隔.老一代仍然仅包含Java对象,而元空间仅包含JVM特定的数据,而没有Java对象.因此,以前存储在Perm Gen中的Java对象已移至OldGen.由于Method Area包含工件例如运行时常量池,字段和方法数据以及方法和构造函数的代码……",其他非Java对象一词(尽管该池可能包含引用来堆放对象),但它现在是Metaspace的一部分.

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.

您现在可以讨论元空间是方法区的实现还是可以包含比方法区更多的内容,但这没有实际意义.实际上,JVM包含用于管理元空间及其所包含工件的代码,并且无需关心这些工件在逻辑上是否确实属于规范描述的方法区域".

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.

这篇关于Java 8中仍然存在“方法"区域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆