如何在Java中计算对象的数字年龄 [英] How to calculate numerical age of an Object in Java

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

问题描述

我想知道Java对象的年龄,当我们使用new关键字时,用户定义的对象是用Java创建的,但是何时将其销毁?

I want to know age of an object in Java, when we use new keyword the user-defined object is created in Java, but when would it be destroyed ?

跨越JVM的权限空间需要花费时间吗?我可以使用JNI编程知道对象的数字年龄吗?

Is it the time taken to cross the perm space of the JVM? Can I know the numerical age of an object using JNI programming?

生存空间,烫发空间和物体年龄之间是什么关系?

What is the relationship between survival space, perm space and object age?

推荐答案

在Java中,对象的年龄存储在

In Java, an object's age is stored in Object Header.

// The markOop describes the header of an object.
//
// Note that the mark is not a real oop but just a word.
// It is placed in the oop hierarchy for historical reasons.
//
// Bit-format of an object header (most significant first, big endian layout below):
//
//  32 bits:
//  --------
//             hash:25 ------------>| age:4    biased_lock:1 lock:2 (normal object)
//
//  64 bits:
//  --------
//  unused:25 hash:31 -->| unused:1   age:4    biased_lock:1 lock:2 (normal object)

因此,如果您知道对象的地址,也许您可​​以获得该对象的年龄.

So, may be you can get an object's age if you know the object's address.

生存空间,烫发空间和物体年龄之间是什么关系?

What is the relationship between survival space, perm space and object age?

请阅读 Java HotSpot虚拟机中的内存管理.


(来源: oracle.com )


(source: oracle.com)

如果对象的年龄超过了年龄阈值,它将从伊甸园/幸存者移到旧世代.

If an object's age exceed the age threshold, it will be moved from eden/survior to old generation.

这篇关于如何在Java中计算对象的数字年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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