Java – What is the reserved size of java.lang.Integer?

What is the reserved size of java.lang.Integer?… here is a solution to the problem.

What is the reserved size of java.lang.Integer?

I’m using Java Hotspot 1.8.0_191-b12 (64-bit, Xmx < 32 GB) and I’m using various tools to view jmap dumps (hprof format).

VisualVM (and NetBeans analyzer-based tools) reports are very different from Yourkit and Eclipse Memory Analyzer.

I looked at the simplest objects, even those that are different… For java.lang.Integer, VisualVm reports 20 bytes instead of the other 16 bytes (in my interpretation because = 12 bytes header + 4 bytes int ‘value’ = 16 submitted from the Integer class, no padding required).

Which is correct and why?

Solution

The only tool used correctly is JOL, which may not be accurate by all others.

And reports 16 bytes: 12 for header + 4 for int itself (so you’re right).

  Integer i = 42;

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

I’ll let you run this code myself and see the output. Note that if UseCompressedOops is disabled, it may be more; In this case, there will be an extra 4 bytes + an extra 4 bytes for padding.

Related Problems and Solutions