Is there a way to detect garbage collector generation placement for a given object?
Not by using "ordinary" Java, probably wit some special service/profilier APIs.
Just to be curious, why do you need it?
I want to make sure that certain big objects are not going back and forth between young and tenured/permanent generations.
Could you be more specific about service/profiler APIs?
Best is probably to use some heap-profiling Tools, where you see the activity of the generations as well as the amount of data copied. The data gathered can be used to optimize your app using JVM options.
I really advice against coding strategies to "help" the GC. You don't have control over where your stuff is placed anyway - and forcing the GC to act this or that way tends to break quickly with different jvm-settings / gc-heuristics/algorythmns.
> Could you be more specific about service/profiler APIs?
Something like jvmti (or whatever its called), where you can interact with the JVM on a very low-level basis.
This requires you to write a jvm-plugin written in C, loaded by the JVM at startup.
However such APIs tend to have a lot of overhead, so usually the are only useful for gathering information at profiling time, not at runtime.
Thank you Clemens.
I just want to go with the grain.
Certain GC behavior depends on very basic assumptions. If I can decouple short lived objects from long lived ones this would help GC.
I think coding totally oblivious of GC could be worse.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.