Programmatically detect if/when GC ran?

J

joe.no_junk

Hi all.

The mode in which GC is running in my JVM is best for overall
throughput,
but has a difficult side-effect of occasionally halting all threads
for over
10 seconds. This upsets some applications with timing requirements.
Assuming that all practical economies of object reuse have been
applied,
my code could benefit from being able to detect ASAP after the fact,
that
GC had just run, so the apparent hang/pause in a given thread could be
attributed to this necessary process, rather than to the application
functionality.
Thanks in advance,
Joe
 
M

Mark Space

Hi all.

The mode in which GC is running in my JVM is best for overall
throughput,
but has a difficult side-effect of occasionally halting all threads
for over
10 seconds. This upsets some applications with timing requirements.
Assuming that all practical economies of object reuse have been
applied,
my code could benefit from being able to detect ASAP after the fact,
that
GC had just run, so the apparent hang/pause in a given thread could be
attributed to this necessary process, rather than to the application
functionality.

A profiler can detect when the GC runs, and will show you when your
threads get suspended for that purpose too. There's also some command
line options for printing a log line when the GC runs (kind of poor
man's profiling). If you're looking for "not my fault" sort of stuff
for a running app, these might help.

<http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp>


-XX:printCommandLineFlags Print flags that appeared on the command
line. (Introduced in 5.0.)

-XX:printCompilation Print message when a method is compiled.

-XX:printGC Print messages at garbage collection. Manageable.

-XX:printGCDetails Print more details at garbage collection.
Manageable. (Introduced in 1.4.0.)

-XX:printGCTimeStamps Print timestamps at garbage collection.
Manageable (Introduced in 1.4.0.)


I don't have the profiler options handy, you'll have to check the docs
for those.
 
A

angrybaldguy

Hi all.

The mode in which GC is running in my JVM is best for overall
throughput,
but has a difficult side-effect of occasionally halting all threads
for over
10 seconds. This upsets some applications with timing requirements.
Assuming that all practical economies of object reuse have been
applied,
my code could benefit from being able to detect ASAP after the fact,
that
GC had just run, so the apparent hang/pause in a given thread could be
attributed to this necessary process, rather than to the application
functionality.
Thanks in advance,
Joe

You can detect when a given object has been collected using reference
queues and the various kinds of weak reference (SoftReference,
WeakReference, and PhantomReference), but you can't detect, in
general, when the GC has run without a profiling agent.

Are you sure you need to maximize GC throughput at the expense of
responsiveness? Would a less onerous GC mode (continuous mark &
sweep, maybe) that loses some throughput still collect "fast enough"
without disrupting the application? I ask because I've never managed
to swamp the ConcMarkSweep GC, despite extremely heavy use of small
transient objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top