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?

jack malkovick
  • 503
  • 2
  • 14

1 Answers1

3

The only correct tool to use is JOL, all others might be inaccurate.

And that reports 16 bytes : 12 for headers + 4 for int itself (so you are correct).

  Integer i = 42;

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

I am leaving it to you to run this code and see the output yourself. Just notice that it could have been more, if UseCompressedOops would have been disabled; in such a case there would be an extra 4 bytes + extra 4 bytes for padding.

Eugene
  • 117,005
  • 15
  • 201
  • 306