Java对象的大小 [英] Size of Java object

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

问题描述

Java对象的最小大小如何为8个字节(仅对象标头),

How is it possible that minimal size of Java object is 8 bytes (only the object header),

什么是对象在Java?

如果在表示Java对象的C ++类中,

if in the C++ class representing the java object,

http ://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/9b0ca45cd756/src/share/vm/oops/oop.hpp

我可以看到班上有更多成员

i can see that the class has more members

class oopDesc {
  friend class VMStructs;
 private:
  volatile markOop  _mark; // this is the object header
  union _metadata {
    wideKlassOop    _klass;
    narrowOop       _compressed_klass;
  } _metadata; // what about size of this member?

推荐答案

这是可能的,因为在32位JVM对象中包含4个字节的标记头和4个字节的类引用.标记标头包含不同的信息,具体取决于对象类型(位大小):

It's possible because in 32bit JVM object contains 4 bytes of mark header and 4 bytes of class reference. Mark headers contains different information depending the object type (sizes in bits):

正常对象->未使用:25哈希:31 cms_free:1年龄:4biased_lock:1锁:2

normal objects -> unused:25 hash:31 cms_free:1 age:4 biased_lock:1 lock:2

有偏对象-> JavaThread *:54时代:2 cms_free:1年龄:4biased_lock:1锁:2

biased objects -> JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2

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

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