JMM For Object Size(摘抄整理)

对象大小(64位机)

观察虚拟机配置

java -XX:+PrintCommandLineFlags -version

普通对象

  1. 对象头:markword 8
  2. ClassPointer指针:-XX:+UseCompressedClassPointers 为4字节 不开启为8字节
  3. 实例数据
    1. 引用类型:-XX:+UseCompressedOops 为4字节 不开启为8字节 Oops Ordinary Object Pointers
  4. Padding对齐,8的倍数

数组对象

  1. 对象头:markword 8
  2. ClassPointer指针同上
  3. 数组长度:4字节
  4. 数组数据
  5. 对齐 8的倍数

 

Hotspot开启内存压缩的规则(64位机)

  1. 4G以下,直接砍掉高32位
  2. 4G - 32G,默认开启内存压缩 ClassPointers Oops
  3. 32G,压缩无效,使用64位 内存并不是越大越好(^-^)

 

IdentityHashCode的问题

当一个对象计算过identityHashCode之后,不能进入偏向锁状态

https://cloud.tencent.com/developer/article/1480590 

https://cloud.tencent.com/developer/article/1484167

https://cloud.tencent.com/developer/article/1485795

https://cloud.tencent.com/developer/article/1482500

对象定位(建议参考周志明老师的深入了解JVM)

https://blog.csdn.net/clover_lily/article/details/80095580

  1. 句柄池
  2. 直接指针
posted @ 2020-09-01 21:14  gabin  阅读(141)  评论(0编辑  收藏  举报