Recently I was able to get an object's address using sun.misc.Unsafe class.
And now I am trying to find programmatically an actual generation where my object is located. For this I want to know the starting and ending points of each generation. If Java (Oracle JVM) provides any tools to resolve this issue? I believe not, since even different GCs require different memory structures (e.g. G1), and this makes the task even more interesting :)
What I want to know here is just a couple of numbers representing the borders of generations in memory, like this:
young gen: start point - 8501702198
end point - 9601256348
Would love to hear even your craziest ideas about a black magic that allows to determine where different generation areas are placed in memory.
The optimal choice depends on the lifetime distribution of the objects allocated by the application. By default, the young generation size is controlled by the parameter NewRatio . For example, setting -XX:NewRatio=3 means that the ratio between the young and tenured generation is 1:3.
Young Generation : the newly created objects are allocated to the young gen. Old Generation : If the new object requests for a larger heap space, it gets allocated directly into the old gen. Also objects which have survived a few GC cycles gets promoted to the old gen i.e long lived objects house in old gen.
The Young Generation is where all new objects are allocated and aged. When the young generation fills up, this causes a minor garbage collection. Minor collections can be optimized assuming a high object mortality rate. A young generation full of dead objects is collected very quickly.
Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually, the old generation needs to be collected.
The Old Generation is used to store long surviving objects. Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually, the old generation needs to be collected.
From a high level, the young generation is where all new objects start out. Once they’re allocated in the Java code, they go specifically to this subsection called the eden space. Eventually, the eden space fills up with objects. At this point, a minor garbage collection event occurs.
If you wanted to know how old you were when something happened in the past, simply enter the date of the event at the top part of the calculator & it will calculate how old you were then. Aging: a natural process every living organism goes through. For centuries, humans have been searching for the fountain of youth to reverse old age.
This is possible with HotSpot JVM though somehow complicated.
The key idea is to use VMStructs
- the information about HotSpot internal constants and types embedded right into JVM shared library.
For example, ParallelScavengeHeap::_young_gen
VM global variable contains the pointer to PSYoungGen
structure that has _virtual_space
member with the boundaries of Parallel collector's young generation. Similarly, GenCollectedHeap::_gch
global points to the structure describing CMS collector generations.
I've made a proof-of-concept project to demonstrate the usage of VMStructs. It is pure Java, no extra libraries required, but it deeply relies on the undocumented JDK internals and may not work on all Java versions. I've tested this on JDK 8u40 and JDK 7u80 on Windows and Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With