3 ms·
Your point about the VM being aware of stack layout is of course correct. That aside, Java references can be more complex than a simple pointer to the reference
by cygx 12y ago
Your point about the VM being aware of stack layout is of course correct. That aside, Java references can be more complex than a simple pointer to the referenced object. In particular:
In some of Oracle’s implementations of the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers: one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object, and the other to the memory allocated from the heap for the object data.
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.7 http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.htm...
- nly 12y agoThat's not really to enable garbage collection. In C++, for example, objects with dynamic storage duration will be referenced off the stack by a pointer to your object, which in turn, if the object is of polymorphic type, contains a pointer to the class vtable and runtime type information. That's not so much wrapping as required infrastructure for runtime polymorphism, interfaces etc... even if you replicate the same features in C. Presumably the major difference in Java with re: GC is that there's enough introspection left in the RTTI after compilation for the GC to identify internal references.