java对象结构解说

java对象结构包含哪几部分:

对象头 + 实例数据 + 对齐填充

对象头又由:mark work  + class point 组成

mark work:占8byte = 64位

class point:占4byte = 32位

具体请看图片:https://i-blog.csdnimg.cn/blog_migrate/8c477ad05e2b7adddc20cf71a50c9aa7.png

开发工具(我用的时idea)中查询对象结构:

引入 jol 包:
maven依赖:
<dependency>
      <groupId>org.openjdk.jol</groupId>
      <artifactId>jol-core</artifactId>
      <version>0.10</version>
</dependency>


代码实例:
public static void main(String[] args) {

        System.out.println("----hashcode before");
        System.out.println(ClassLayout.parseInstance(a).toPrintable());

        //转化成16进制,方便比较
        System.out.println(Integer.toHexString(a.hashCode()));

        System.out.println("----hashcode after");
        //计算完hashcode之后的a对象的布局
        System.out.println(ClassLayout.parseInstance(a).toPrintable());
}

控制台结果:

 内容解析:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值