问题描述
在Java 8之前,我们有5个主要的运行时数据区域:
Prior to Java 8 we had 5 major runtime data areas:
- 方法区域
- 堆
- JVM堆栈
- PC寄存器
- 本机方法堆栈
这很棒,但我也读过
但是我似乎找不到任何明确表明Java 8中不再存在Method区域的东西.
but I can't seem to find anything which explicitly says Method area is no more in Java 8.
请附上您可能看到的与Java 8内存模型有关的任何良好的源材料
Please attach any good source material that you may have seen related to Java 8 Memory Model
推荐答案
由于方法区域是规范中描述的逻辑概念,每个JVM都有一个方法区域",尽管这并不意味着它必须反映在实现代码中.同样, 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中仍然存在“方法"区域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!