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

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

问题描述

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

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

<块引用>

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

这很好,但我也读过

<块引用>

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

但我似乎找不到任何明确说明 Java 8 中不再存在方法区域的内容.

<块引用>

所以是 Perm Gen 连同 Method 区域被删除或只有 Perm Gen 得到已删除,并且方法区域仍然存在于老年代.

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

解决方案

方法区是规范中描述的一个逻辑概念,每个JVM都有一个方法区,但这并不意味着它必须反映在实现代码中.同样,Java 堆空间 在规范中被指定为一个概念,是所有 Java 对象的存储,因此所有 Java 对象都存储在堆中,根据定义,不管它是如何实际实现的.

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

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

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

解决方案

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.

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

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