分析对象布局工具
加锁与不加锁能看出区别
pom.xml中加入
<!-- https://mvnrepository.com/artifact/org.openjdk.jol/jol-core -->
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.16</version>
<scope>provided</scope>
</dependency>
TT t = new TT();
String s = ClassLayout.parseInstance(t).toPrintable();
System.out.println(s);
synchronized (t) {
System.out.println(ClassLayout.parseInstance(t).toPrintable());
}
com.example.demospringboot.test.ParseClassApp$TT object internals:
OFF SZ TYPE DESCRIPTION VALUE
0 8 (object header: mark) 0x0000000000000001 (non-biasable; age: 0)
8 4 (object header: class) 0xf800c143
12 4 int TT.m 0
Instance size: 16 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total
com.example.demospringboot.test.ParseClassApp$TT object internals:
OFF SZ TYPE DESCRIPTION VALUE
0 8 (object header: mark) 0x0000009f57fff1c0 (thin lock: 0x0000009f57fff1c0)
8 4 (object header: class) 0xf800c143
12 4 int TT.m 0
Instance size: 16 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total
Process finished with exit code 0