3

I'm using Java Hotspot 1.8.0_191-b12 (64 bit, Xmx < 32 GB) and I'm looking at a jmap dump (hprof format) with various tools.

VisualVM (and NetBeans profiler based tools) reports differ a lot from Yourkit and Eclipse Memory Analyzer.

I looked at the most simple objects, and even those differ... for java.lang.Integer, VisualVm reports 20 bytes, instead of 16 as the others (that in my interpretation is because = 12 bytes header + 4 bytes int 'value' filed from the Integer class = 16, no padding needed).

Which one is correct and why?

4

1 回答 1

3

唯一正确使用的工具是JOL,所有其他工具可能都不准确。

并且报告16 bytes:标题为 12 +int自身为 4(所以你是正确的)。

  Integer i = 42;

  System.out.println(ClassLayout.parseInstance(i).toPrintable());

我把它留给你来运行这段代码并自己查看输出。请注意,如果UseCompressedOops已禁用,它可能会更多;在这种情况下,将有一个额外的4 bytes+ 额外4 bytes的填充。

于 2019-01-14T14:10:59.927 回答