What is the reason for the additional indirection in Handle?
gbenson at redhat.com
Mon Sep 8 00:30:48 PDT 2008
Ramón García wrote:
> The Handle class, and subclasses like KlassHandle have an additional
> indirection to the Oop they are pointing to.
> Instead of storing the oop inside (which is already a pointer),
> they store a pointer to the oop. This causes an additional memory
> allocation of an object of size pointer, to contain the actual
> pointer to the oop.
> I guess it must have something to do with garbage collection, so
> that in case the underlying oop is moved, the pointer is updated. I
> guess a pointer in the stack cannot be updated. Or perhaps with
> scanning: the stack is not scanned for references, but the malloced
> heap where the pointers to references are.
It is for garbage collection. You need to use handles to protect
oops across function calls that might GC.
More information about the hotspot-runtime-dev