Can someone explain to me how the actual determination of the type of an object is performed in Java, what is the algorithm of actions?
- The title of the object at the well-known index contains a link to the class metadata, with which it gets it - etki
|
1 answer
If we talk about OpenJDK / HotSpot, then each object in the heap has a header with two fields: mark and klass .
mark contains hashcode, object age and locks.
klass is a pointer to the structure:
In fact, it is an internal analogue of java.lang.Class lying in the native memory.
As far as I know, this point is clearly not described in the JVM specification, and in other implementations it can be implemented differently.
UPD: In IBM's JVM, the order and set of header fields are different, but the essence is the same - a pointer to the class description.
|