jol 查看对象头内容和对象大小

import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;

/**
 * @author paul
 * @description
 * @date 2019/12/19
 * 是否开启指针压缩 -XX:-UseCompressedOops
 *

    org.openjdk.jol
    jol-core
    0.9

 */
public class TestObjectSize {
    private Object o = new Object();
    public static void main(String[] args) {
        //查看对象内部信息
        TestObjectSize testObjectSize = new TestObjectSize();
        System.out.println(ClassLayout.parseInstance(testObjectSize).toPrintable());
        System.out.println("=================");
        synchronized (testObjectSize){
            System.out.println(ClassLayout.parseInstance(testObjectSize).toPrintable());
        }
        System.out.println("=================");

        System.out.println(GraphLayout.parseInstance(testObjectSize).toPrintable());
        System.out.println("=================");
        System.out.println(GraphLayout.parseInstance(testObjectSize).totalSize());

        System.out.println(ClassLayout.parseInstance(new Object[0]).toPrintable());
    }
}

你可能感兴趣的:(jol 查看对象头内容和对象大小)