JVM之对象头内存模型
这篇文章我们来看一下对象的内存结构。先上图
1、内存图

下面来验证一下
2、导入可视化工具
<!--java对象内存模型可视化工具-->
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.9</version>
</dependency>测试外部对象
public class Boy {
byte aByte; //1
boolean aBoolean;//1
short aShort;//2
int anInt;//4
long aLong;//8
char aChar;//2
float aFloat;//4
double aDouble;//8
}@Test
public void test04(){
String s = ClassLayout.parseInstance(new Boy()).toPrintable();
System.out.println(s);
}结果
测试内部类加子类对象
class Student extends MyTest{
Byte aByte1;
Integer integer;
Short aShort1;
Long aLong;
Boolean[] booleans;
Boolean aBoolean;
boolean[] booleans1;
String string;
int[] ints;
public void test(){
}
}@Test
public void test03(){
Student student=new Student();
String s=ClassLayout.parseInstance(student).toPrintable();
System.out.println(s);
}
版权声明:本文为weixin_43894816原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。