了解JVM中的对象开销 [英] Learn about object overhead in JVM

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

问题描述

我正在研究java,我记得在某个地方读过java对象,在JVM中有一些开销,这是由虚拟机用于管理的原因。所以我的问题是,有人可以告诉我是否以及如何在HotSpot JVM中获取对象的总大小,以及它可能带来的任何开销?

I am studying java, and I remember reading somewhere that java objects, had some overhead inside the JVM, which was used for administration reasons by the virtual machine. So my question is, can someone tell me if and how I can get an object's total size in the HotSpot JVM, along with any overhead it may come with?

推荐答案

您不能直接获得开销。开销量取决于实现,并且可能因许多因素而异(例如,精确的JVM版本,以及您是使用32位还是64位JVM)。

You can't get the overhead directly. The amount of overhead is implementation dependent, and can vary based on a number of factors (e.g. the precise JVM version, and whether you are on a 32 or 64bit JVM).

然而,假设在像HotSpot这样的典型现代JVM实现中,每个对象的开销<8>在16到16个字节之间,这是相当安全的。数组的开销通常比其他对象大4个字节(包含整数数组长度)。

However it is reasonably safe to assume that in typical modern JVM implementations like HotSpot, the overhead per object is between 8 and 16 bytes. Arrays typically have an overhead that is 4 bytes larger than other objects (to contain the integer array length).

另请参阅:

  • In Java, what is the best way to determine the size of an object?
  • Memory usage of Java objects: general guide

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

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