1.用于统计Java对象内存大小的jar包:jol
<!--Java内测布局查看包-->
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.14</version>
</dependency>
2、使用示例
public static void main(String[] args) {
HashMap<String,String> hashMap=new HashMap();
hashMap.put("1","obj1");
hashMap.put("2","obj2");
System.out.println(ClassLayout.parseClass(Object.class).toPrintable());
System.out.println(ClassLayout.parseInstance(new Integer(1)).toPrintable());
//hashmap对象内部信息
System.out.println(ClassLayout.parseInstance(hashMap).toPrintable());
//查看hashmap对象外部信息
System.out.println(GraphLayout.parseInstance(hashMap).toPrintable());
//hashmap对象的总大小(包括里面的key)
System.out.println(GraphLayout.parseInstance(hashMap).totalSize());
}