什么是java对象头文件 [英] What is in java object header
问题描述
您能否告诉我一些关于对象标题中存储内容的信息?我知道,它可能依赖于JVM,但至少可能对HotSpot有用吗?我正在寻找第一行的具体描述。
Could you give me some information on what is exactly stored in object header? I know, that it's probably JVM dependent, but maybe for HotSpot at least? I'm looking for exact description specifically for a first row.
我已经阅读了一些我无法用我发现的信息验证的信息。也许你有一个指向OpenJDK维基的链接?
I've read several information that I can't verify positively with information I find. Maybe you have a link to OpenJDK wiki that says it all?
推荐答案
对于HotSpot:
对象标题包含一个标记词和一个klass指针。
标记字在32位体系结构上具有字长( 4字节
,在64位上具有 8字节
架构)和
The mark word has word size (4 byte
on 32 bit architectures, 8 byte
on 64 bit architectures) and
klass指针在 32位
架构上的字大小。在 64位
架构中,klass指针有字大小,但如果堆地址可以是 4字节
以 4个字节
编码。
the klass pointer has word size on 32 bit
architectures. On 64 bit
architectures the klass pointer either has word size, but can also have 4 byte
if the heap addresses can be encoded in these 4 bytes
.
此优化称为压缩oops,您也可以使用选项 UseCompressedOops $ c来控制它$ C>。
This optimization is called "compressed oops" and you can also control it with the option UseCompressedOops
.
您还可以找到关于此的wiki条目 1 。
You can also find a wiki entry about this 1.
标记词实际上用于很多事情。
The mark word is actually used for many things.
- 一个是
有偏见的锁定
2 ,HotSpot可以通过它实现高效锁定。 - 它也在
GC期间用于设置转发指针
,而用于存储对象的年龄
。对象的标识哈希码可以存储在标记内(System.identityHashCode
/Object.hashCode
一个) 。
- One is
Biased Locking
2 through which HotSpot can implement efficient locking. - It is also used during
GC to set forward pointers
, andto store the age of the objects
. The identity hash code of an object can be stored inside the mark (theSystem.identityHashCode
/Object.hashCode
one).
markOop.hpp ,根据体系结构描述布局:
There is a comment in the source code of markOop.hpp that describes the layout depending on the architecture:
// 32 bits:
// --------
// hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object)
// JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object)
// size:32 ------------------------------------------>| (CMS free block)
// PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object)
//
// 64 bits:
// --------
// unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object)
// JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object)
// PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object)
// size:64 ----------------------------------------------------->| (CMS free block)
//
// unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object)
// JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object)
// narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object)
// unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block)
您还可以找到oop头文件这里。
You can also find the oop header file here.
- 1 https ://wiki.openjdk.java.net/display/HotSpot/CompressedOops
- 2 https://wiki.openjdk.java.net/display/HotSpot/Synchronization
- 1 https://wiki.openjdk.java.net/display/HotSpot/CompressedOops
- 2 https://wiki.openjdk.java.net/display/HotSpot/Synchronization
这篇关于什么是java对象头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!