Tamaño del encabezado del objeto en Java en una máquina virtual de 64 bits con <4 GB de RAM
Quería saber si hay alguna forma de que la máquina virtual de 64 bits use encabezados de objetos de 8 bytes en lugar de encabezados de objetos de 12 bytes si la RAM utilizable para la JVM es de 4 GB.
¿O es así en Linux, si no en Windows? ¿Podría alguien probar esto con este código?
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class ObjectSizes {
String s1;
String s2;
public static void main(String[] args) throws Exception {
Unsafe unsafe;
try {
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
unsafe = (Unsafe)field.get(null);
} catch (Exception ex) {
throw new RuntimeException("Can't get Unsafe instance.", ex);
}
Field s1Field = ObjectSizes.class.getDeclaredField("s1");
Field s2Field = ObjectSizes.class.getDeclaredField("s2");
long s1OffSet = unsafe.objectFieldOffset(s1Field);
long s2OffSet = unsafe.objectFieldOffset(s2Field);
System.out.println("We are running "+System.getProperty("java.version"));
System.out.println("Object header size is "+s1OffSet+" bytes.");
System.out.println("Object reference size is "+(s2OffSet-s1OffSet)+" bytes.");
}
}