How to calculate the numerical age of an object in Java

I want to know the age of an object in Java, when we use a new keyword, a custom object is created in Java, but when will it be destroyed?

Is this the time taken to intersect the JVM material space? Can I find out the numerical age of an object using JNI programming?

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

+3
source share
3 answers

The object will be destroyed after it becomes suitable for the GC, and the JVM decides to launch the GC in the heap area (new / old generation) where the object is located. You can find out when it is destroyed by overriding the finalization method or using WeakReference and ReferenceQueue.

+2
source

In Java, the age of an object is stored in the 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, perhaps you can find out the age of the object if you know its address.

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

Please read Memory Management on the Java HotSpot Virtual Machine .

enter image description here
(source: oracle.com )

, / .

+2

, finalize(). finalize() Object. super.finalize() finalize() ( GC finalize() Object, )

, GC . Perm gen , , .

+1

Source: https://habr.com/ru/post/1667410/


All Articles