[英]Trying to understand the footprint of ArrayList in JOLSample_16_AL_LL
public static void main(String[] args) throws Exception {
out.println(VM.current().details());
List<Integer> al = new ArrayList<Integer>();
List<Integer> ll = new LinkedList<Integer>();
for (int i = 0; i < 1000; i++) {
Integer io = i; // box once
al.add(io);
ll.add(io);
}
PrintWriter pw = new PrintWriter(out);
pw.println(GraphLayout.parseInstance(al).toFootprint());
pw.println(GraphLayout.parseInstance(ll).toFootprint());
pw.println(GraphLayout.parseInstance(al, ll).toFootprint());
pw.close();
}
當我按原樣運行代碼時,我看到以下內容:
java.util.ArrayList@5f205aad footprint:
COUNT AVG SUM DESCRIPTION
1 4952 4952 [Ljava.lang.Object;
1000 16 16000 java.lang.Integer
1 24 24 java.util.ArrayList
1002 20976 (total)
我不確定[Ljava.lang.Object;的4952字節在哪里; 來自。 如果我更新ArrayList的創建並將初始大小設置為1000,以便不增長,則會得到以下信息:
java.util.ArrayList@5f205aad footprint:
COUNT AVG SUM DESCRIPTION
1 4016 4016 [Ljava.lang.Object;
1000 16 16000 java.lang.Integer
1 24 24 java.util.ArrayList
1002 20040 (total)
謝謝。
更新
我關閉了CompressedOops(-XX:-UseCompressedOops)。 這是新結果:
java.util.ArrayList@1996cd68d footprint:
COUNT AVG SUM DESCRIPTION
1 8024 8024 [Ljava.lang.Object;
1000 24 24000 java.lang.Integer
1 40 40 java.util.ArrayList
1002 32064 (total)
因此,當禁用CompressedOops時,參考大小將增加到8個字節。 對我來說,更有意義的是Object數組包含對1000個Integer Objects的引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.