On Tue, Mar 02, 2010 at 12:41:34AM -0800, Ang BeePeng wrote:
I saw the following in win32 VM interp.c,
# define pointerForOop(oop) ((char *)(sqMemoryBase + ((usqInt)(oop)))) ... char* localSP; char* localIP; sqInt currentBytecode; browserPluginInitialiseIfNeeded(); /* begin internalizeIPandSP */ localIP = pointerForOop(instructionPointer);
//foo->instructionPointer localSP = pointerForOop(stackPointer);
Is it true that char* in bold explain difference in both version? localIP = pointerForOop(instructionPointer); instead of localIP = pointerForOop(foo->instructionPointer);
Yes. You can think of an oop as a 32 bit unsigned-int (for 32-bit object memories, the usual case). Its value represents an offset into the object memory, and it is defined as an usqInt so that an oop value can be stored into a "slot" in the object memory.
The actual addressing of object memory is done by bytes, hence the cast to (char *) in converting to memory addresses. This allows addressing individual bytes (of course) and also supports the trick used for small integers; if an "oop" has a 1 in the low order bit, then it cannot be pointing to a valid 32-bit location in the object memory, so it is not really an oop. These "oop values" are used to directly represent small integers.
Dave