views:

104

answers:

3

hi al,

Assume i'm executing a jvm where garbage collection is not running in parallel. That is when GC executes my main thread is halted.

Is there a way in which i can specify what method was running that current moment that the GC was invoked? I know i can get info about time but this is not enough. I assume such profiling info would be easy for the JVM to provide as it would only just be a matter of returning the top most element (stack frame) of each stack of a halted thread.

thanks.

+2  A: 

Generally no. If you can then it is a vendor specific extension.

Question is, why you want to know?

Thorbjørn Ravn Andersen
I'm currently doing some benchmarking tests. I want to see if GC is called while the benchmarked method is executing.
kourdoun
+4  A: 

I figure you want to make sure that garbage collection should not affect your benchmarking. Some ideas:

  1. Garbage collection is a part of your software, it will always affect your software, so it should be represented in your benchmark.
  2. Measure your function several times and ignore the slowest 3% of the results.
  3. Call System.gc() just before starting the timer.
Arian
A: 

If you gave acces to JMX you can see memory consumption and where there is spike there is also a garbage collection.

It's not precise as to see what method was running, but from the top of the stack you could allways get String.equals() and know nothingt.

Hurda