javapointersjvmjvm-hotspot

Is Ordinary Object Pointer a pointer or an object structure in HotSpot?


I am working on a Oracle HotSpot and GC internals article, but I am confused about the meaning of OOP (Ordinary Object Pointer).

The Oracle documentation states that an OOP is a 32 or 64 bit pointer to an object datastructure on the heap:

An "oop", or ordinary object pointer in Java Hotspot parlance, is a managed pointer to an object. An oop is normally the same size as a native machine pointer

It can be compressed, but that is besides the issue.

I wanted to find articles about this datastructure but then the confusion started.

Some articles say OOP is actually the datastructure itself, not the pointer!

Some other articles seem contradictory on this point, like on infoq.com. At first it states an OOP is a pointer:

An OOP is a genuine pointer in the C / C++ sense - a machine word which points to a memory location inside the Java heap.

but after that it says:

An OOP consists of two machine words of header, which are called the Mark and the Klass words followed by the member fields of this instance.

So the pointer consists of header and member fields? That can't be true.

Finally I tried to look at the source code of Oracle JDK and OpenJDK HotSpot source (because Oracle HotSpot is not open source). But based on that it seemed OOP is really the object datastructure. But in this case what is the pointer?

So the question is: what is the OOP in HotSpot JVM?


Solution

  • oop.hpp from the HotSpot source code:

    class oopDesc {
      friend class VMStructs;
     private:
      volatile markOop  _mark;
      union _metadata {
        Klass*      _klass;
        narrowKlass _compressed_klass;
      } _metadata;
    
    ...
    

    oopsHierarchy.hpp:

    typedef class oopDesc*    oop;
    

    The name OOP (ordinary object pointer) speaks for itself: it is the pointer or reference to an object. oopDesc is the structure that describes the format of an object pointed by oop. It is oopDesc that contains the mark word and Klass pointer.

    A normal (wide) oop is just a plain address of an object in the Heap.
    A compressed (narrow) oop is an encoded address.

    There is also a notion of oop handle - a managed reference to an oop traversed and updated during GC. It is basically one more level of indirection.