java java对象头中有什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26357186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is in java object header
提问by alobodzk
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.
你能给我一些关于对象头中究竟存储什么的信息吗?我知道,它可能依赖于 JVM,但至少对于 HotSpot 来说可能?我正在寻找专门针对第一行的确切描述。
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?
我已经阅读了一些无法用我找到的信息进行正面验证的信息。也许你有一个指向 OpenJDK wiki 的链接,它说明了一切?
回答by box
For HotSpot:
对于热点:
The object header consists of a mark word and a klass pointer.
对象头由一个标记字和一个类指针组成。
The mark wordhas word size (4 byte
on 32 bit architectures, 8 byte
on 64 bit architectures) and
所述标记字具有(字大小4 byte
在32位体系结构中,8 byte
在64位体系结构)和
the klass pointerhas 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
.
在克拉斯指针对字大小32 bit
的架构。在64 bit
体系结构上,klass 指针要么具有字大小,但4 byte
如果堆地址可以在这些4 bytes
.
This optimization is called "compressed oops"and you can also control it with the option UseCompressedOops
.
这种优化称为“压缩 oops”,您也可以使用选项来控制它UseCompressedOops
。
You can also find a wiki entry about this 1.
您还可以找到有关此1的 wiki 条目。
The mark wordis actually used for many things.
该标志词实际上是使用了很多东西。
- One is
Biased Locking
2through 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).
- 一个是
Biased Locking
2,HotSpot可以通过它实现高效的锁定。 - 它也用于
GC to set forward pointers
, 和to store the age of the objects
。对象的身份哈希码可以存储在标记(System.identityHashCode
/Object.hashCode
一)内。
There is a comment in the source code of markOop.hppthat describes the layout depending on the architecture:
markOop.hpp的源码中有一段注释,根据架构描述了布局:
// 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)
You can also find the oop header file here.
您还可以在此处找到 oop 头文件。
回答by apangin
You can find the object layout from HotSpot sources.
您可以从HotSpot 源中找到对象布局。
The header consists of markOopfollowed by a pointer (or compressed pointer) to instanceKlass.
标头由markOop后跟一个指向instanceKlass的指针(或压缩指针)组成。
回答by Chris Bailey
The following presentation gives you a general idea of the object contents and the object header: http://www.slideshare.net/cnbailey/memory-efficient-java
下面的介绍让你大致了解对象内容和对象头:http: //www.slideshare.net/cnbailey/memory-efficient-java
The actual header for any object is JVM vendor, version and object type specific.
任何对象的实际标头都是特定于 JVM 供应商、版本和对象类型的。