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?
The only correct tool to use is JOL, all others might be inaccurate.
And that reports
16 bytes: 12 for headers + 4 forintitself (so you are correct).I am leaving it to you to run this code and see the output yourself. Just notice that it could have been more, if
UseCompressedOopswould have been disabled; in such a case there would be an extra4 bytes+ extra4 bytesfor padding.