簡體   English   中英

在 jdk 1.8+ 中,元空間如何布局 class 信息?

[英]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,您的理解不太正確。

  1. 不。代表"a"java.lang.String object 的一個實例在 Java 堆中。 只要"a"是強可達的,字符串表就包含對 object 的引用。
  2. 是的。
  3. 不。 運行時常量池包含JVMS §4.4中描述的內容。 Static字段屬於一個class鏡像,它是Java Heap中java.lang.Class的一個實例。
  4. 與1相同。
  5. 元空間(如“元”前綴所示)包含class 元數據,但不包含數據本身。 例如,元空間包含以下信息:class MetaspaceTest有一個名為literalStr的字段,類型為java.lang.String ,但它與該字段的值無關。
  6. 是的。
  7. 沒有。如上所述,元空間只包含字段的描述,不包含數據。 實例字段的實際持有者是一個object實例; static字段的實際持有者是class鏡像,即java.lang.Class在堆中的實例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM