Could you give me some information on what is exactly stored in object header? I know, that it's probably JVM dependent, but maybe for HotSpot at least? I'm looking for exact description specifically for a first row.
I've read several information that I can't verify positively with information I find. Maybe you have a link to OpenJDK wiki that says it all?
You can find the object layout from HotSpot sources.
The header consists of markOop followed by a pointer (or compressed pointer) to instanceKlass.
For HotSpot:
The object header consists of a mark word and a klass pointer.
The mark word has word size (
4 byte
on 32 bit architectures,8 byte
on 64 bit architectures) andthe klass pointer has word size on
32 bit
architectures. On64 bit
architectures the klass pointer either has word size, but can also have4 byte
if the heap addresses can be encoded in these4 bytes
.This optimization is called "compressed oops" and you can also control it with the option
UseCompressedOops
.You can also find a wiki entry about this 1.
The mark word is actually used for many things.
Biased Locking
2 through which HotSpot can implement efficient locking.GC to set forward pointers
, andto store the age of the objects
. The identity hash code of an object can be stored inside the mark (theSystem.identityHashCode
/Object.hashCode
one).There is a comment in the source code of markOop.hpp that describes the layout depending on the architecture:
You can also find the oop header file here.
The following presentation gives you a general idea of the object contents and the object header: http://www.slideshare.net/cnbailey/memory-efficient-java
The actual header for any object is JVM vendor, version and object type specific.