public class Test {
public static void lockTest(){
synchronized (Test.class) {
System.out.println("hello");
}
}
}
public class Test {
static ReentrantLock reentrantLock=new ReentrantLock();
public static void lockTest(){
reentrantLock.lock();
System.out.println("hello");
reentrantLock.unlock();
}
}
/**
* The synchronization state.
*/
private volatile int state;
public class Test {
boolean flag=false;//占 1byte
}
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol‐core</artifactId>
<version>0.9</version>
</dependency>
public class A {
//没有任何数据
}
public class Test {
public static void main(String[] args) {
A a=new A();
//解析对象a在JVM中的内存分配
System.out.println(ClassLayout.parseInstance(a).toPrintable());
}
}
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) 13 d3 d9 ef (00010011 11010011 11011001 11101111) (-270937325)
12 4 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
public class A {
boolean flag=false;//大小占1Byte
}
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) 8e 65 da ef (10001110 01100101 11011010 11101111) (-2709826)
12 1 boolean A.flag false
13 3 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 3 bytes external = 3 bytes total
The first word of every object header. Usually a set of bitfields including synchronization state and identity hash code. May also be a pointer (with characteristic low bit encoding) to synchronization related information. During GC, may contain GC state bits.
The second word of every object header. Points to another object (a metaobject) which describes the layout and behavior of the original object. For Java objects, the “klass” contains a C++ style “vtable”.
// bits:
// --------
// unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object)
// JavaThread*: epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object)
// PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object)
// size: ----------------------------------------------------->| (CMS free block)
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) 13 d3 d9 ef (00010011 11010011 11011001 11101111) (-270937325)
12 4 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
public class Test {
public static void main(String[] args) {
A a=new A();
//显性计算对象hashcode,并转为十六进制
System.out.println(Integer.toHexString(a.hashCode()));
//解析对象a在JVM中的内存分配
System.out.println(ClassLayout.parseInstance(a).toPrintable());
}
}
22b8ff
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 ff b8 22 (00000001 11111111 10111000 00100010) (5829249)
4 4 (object header) 00 00 00 (01100100 00000000 00000000 00000000) (100)
8 4 (object header) 75 11 da ef (01110101 00010001 11011010 11101111) (-270921355)
12 4 (loss due to the next object alignment)
Instance size: 16 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- azee.cn 版权所有 赣ICP备2024042794号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务