FieldsAllocationStyle参数对对象内存布局的影响

取值

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时,引用在原始类型后面

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容