JOL工具能够计算对象的内存布局。
我注意到,静态字段不参与计算,例如:
public class Foo {
private static final int i = 1;
private char value;
public Foo(char value) {
this.value = value;
}
}
然后,
System.out.println(ClassLayout.parseClass(Foo.class).toPrintable());
给出以下输出:
com.kishlaly.Foo object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 2 char Foo.value N/A
14 2 (loss due to the next object alignment)
Instance size: 16 bytes (estimated, the sample instance is not available)
Space losses: 0 bytes internal + 2 bytes external = 2 bytes total
private static final int在内存中的什么位置?