An object header can accept 8 bytes in a 32-bit JVM and 12 bytes in a 32-bit JVM.
Each primitive takes a number of bits (without specifying a byte)
The distribution of objects is 8 bytes, so there should be up to 7 bytes at the end of the object. that is, the actual used space is rounded to the next multiple of 8.
class Demo{ // 8 or 12 bytes byte b; // 1 byte int i; // 4 bytes long l; // 8 bytes } Demo obj = new Demo();
Thus, the size of an object can take 24 bytes on a 32-bit JVM and 32 bytes on a 64-bit JVM.
source share