Java对象标头中有什么? [英] What is in Java object header?

查看:150
本文介绍了Java对象标头中有什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能给我一些有关对象头中确切存储的内容的信息吗?我知道,这可能取决于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 Wiki的链接,说明了所有内容?

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:

对象标头由一个标记词和一个克拉斯指针组成.

标记字具有字长(在32位体系结构上为4 byte,在64位体系结构上为8 byte)和

The mark word has word size (4 byte on 32 bit architectures, 8 byte on 64 bit architectures) and

黄铜指针32 bit体系结构上具有字长.在64 bit架构上,klass指针要么具有字长,但如果可以在这些4 bytes中编码堆地址,也可以具有4 byte.

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对其进行控制.

This optimization is called "compressed oops" and you can also control it with the option UseCompressedOops.

您还可以找到有关 标记词实际上用于很多事情.

The mark word is actually used for many things.

  1. 一个是Biased Locking
  1. One is Biased Locking 2 through which HotSpot can implement efficient locking.
  2. It is also used during GC to set forward pointers, and to store the age of the objects. The identity hash code of an object can be stored inside the mark (the System.identityHashCode/Object.hashCode one).

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

这篇关于Java对象标头中有什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆