Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To add a bit of (admittedly vague) data to @templatetypedef's excellent answer. These numbers are for typical recent 32-bit JVMs, but they are <em>implementation specific</em>:</p> <ul> <li><p>The header overhead for each object <em>typically</em> 2 words for a regular object and 3 words for an array. The header includes GC related flags, and some kind of pointer to the object's actual class. For an array, an extra word is needed to hold the array size.</p></li> <li><p>If you've called (directly or indirectly) <code>System.identityHashCode()</code> on an object, and it has survived a GC cycle, then add an extra word to store the hashcode value. (Modern JVMs use a clever trick to avoid reserving a hashcode header field for <em>all</em> objects ...)</p></li> <li><p>The storage allocation granularity <em>may be</em> a multiple of words; e.g. 2.</p></li> <li><p>Fields of an object are typically word aligned; i.e. they are not packed.</p></li> <li><p>Elements of an array of a primitive type are packed, but booleans are typically represented by a byte in packed form.</p></li> <li><p>References occupy 4 bytes both as fields and as array elements.</p></li> </ul> <p>Things are a bit more complicated for 64-bit JVMs because of pointer compression (OOPS) in some JVMs. Also, I'm not sure if fields 32 or 64 bit aligned.</p> <hr> <p>(Note: the above are based on what I've heard / read in various places from various "knowledgeable people". There is no definitive source for this kind of information apart from Oracle / Sun, and (AFAIK) they haven't published anything.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload