1.工具
需要导入jar ,使用maven
<!-- https://mvnrepository.com/artifact/org.openjdk.jol/jol-core -->
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.10</version>
</dependency>
2.测试类
import org.openjdk.jol.info.ClassLayout;
public class Test {
public static void main(String[] args) {
Object o=new Object();
// o.hashCode();
System.out.println(ClassLayout.parseInstance(o).toPrintable());
}
}
3.执行结果
4.总结
object 内存布局 :
Mark Word 8 bytes
class point : 4 bytes
实例数据 : 0
对齐填充: 4 bytes
占 16 bytes.