In fact, it is not indicated anywhere how many bytes the reference variable will have, and in fact it is not the same everywhere.
Shared virtual machines for 32-bit systems (i.e. systems with 32-bit memory bus addresses) typically use 32-bit (= 4 bytes, same as int and float ) as the size for object references, while how virtual machines for 64-bit systems often use their own address size of 64 bits (= 8 bytes). (Note that most 64-bit systems can also run 32-bit programs, so even there you will use a 32-bit virtual machine.)
It's just a matter of simplifying the implementation if you can use the actual memory address for your references, and not something else.
Since this increases the size of the memory used (and often we actually do not need to access such large memory), from Java 7 to 64-bit, HotSpot will be able to use 32-bit links under certain conditions, that is, when the heap is less than 32 GB (8 2 32 bytes). To convert them to the actual memory address, they are multiplied by 8 (since the objects will be aligned at 8-byte boundaries), and then added to the base address (if it's not zero). (For heaps smaller than 4 GB, we do not need a multiplication step.)
Other virtual machines may use similar tricks.
Paลญlo Ebermann Mar 18 '11 at 19:17 2011-03-18 19:17
source share