[英]In jdk 1.8+, how metaspace layout the class info?
在jdk1.8+中,MetaspaceTest class加载到jvm时,这是我对memory布局的理解,对吗?
public class MetaspaceTest {
/*
1. "a" would be interned into the global String Table of heap;
2. object created by [new String("a")] would be placed in heap;
3. constant STR_OBJ would be placed in the constant-pool of MetaspaceTest class info,
and pointing to the string object created by [new String("a")];
*/
private final static String STR_OBJ = new String("a");
/*
4. "b" would be interned in the global String Table of heap;
5. static field literalStr would be placed in metaspace,
and pointing to the string "b" which is interned into the global String Table of heap;
*/
private static String literalStr = "b";
/*
6. object created by [new Integer(8)] would be placed in heap;
7. static field intNum would be placed in metaspace,
and pointing to the object created by [new Integer(8)];
*/
private static Integer intNum = new Integer(8);
}
首先,像Metaspace、String Table之类的东西,在JLS或者JVMS中都没有规定。 它完全是特定 JVM 的内部实现细节。例如,完全兼容的 JVM 实现根本没有元空间。
如果我们谈论现代 HotSpot JVM,您的理解不太正确。
"a"
的java.lang.String
object 的一个实例在 Java 堆中。 只要"a"
是强可达的,字符串表就包含对 object 的引用。java.lang.Class
的一个实例。MetaspaceTest
有一个名为literalStr
的字段,类型为java.lang.String
,但它与该字段的值无关。java.lang.Class
在堆中的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.