Skip to main content

Detecting Garbage Collector Generation

4 replies [Last post]
volkanh
Offline
Joined: 2009-02-07

Is there a way to detect garbage collector generation placement for a given object?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linuxhippy
Offline
Joined: 2004-01-07

Not by using "ordinary" Java, probably wit some special service/profilier APIs.
Just to be curious, why do you need it?

- Clemens

volkanh
Offline
Joined: 2009-02-07

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?

linuxhippy
Offline
Joined: 2004-01-07

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.

- Clemens

volkanh
Offline
Joined: 2009-02-07

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.