取值
hotspot-jdk7u40-b62\src\share\vm\runtime\globals.hpp
- 类型0, 引用在原始类型前面, 然后依次是longs/doubles, ints, shorts/chars, bytes, 最后是填充字段, 以满足对其要求.
- 类型1, 引用在原始类型后面
- 类型2, JVM在布局时会尽量使父类对象和子对象挨在一起, 原因后面解释.
调试
代码
public class OopKlassTest {
public int theInt;
public long theLong;
public String theString;
public static void main(String[] args) {
OopKlassTest oopKlassTest = new OopKlassTest();
oopKlassTest.theInt = 10;
oopKlassTest.theLong = 20;
oopKlassTest.theString = "oopKlassTest";
int x = 100;
int y = 200;
int z = 300;
}
}
FieldsAllocationStyle=0
编译调试
栈
堆
FieldsAllocationStyle=1
同理FieldsAllocationStyle=1时,引用在原始类型后面
堆