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

查看:36
本文介绍了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:

对象头由一个标记词和一个类指针组成.

标记字有字长(4 byte在32位架构上,8 byte在64位架构上)和

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.

这种优化称为compressed oops",您也可以使用选项UseCompressedOops来控制它.

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.

标记词实际上用于很多事情.

  1. 一个是Biased Locking 2 HotSpot 可以通过它实现高效的锁定.
  2. GC期间也使用它来设置前向指针,以及存储对象的年龄.对象的身份哈希码可以存储在标记内(System.identityHashCode/Object.hashCode 之一).
  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).

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)

你也可以找到oop头文件这里.

You can also find the oop header file here.

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

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