开发者

Java Garbage Collection - How to find what method was running when it was called

Assume i'm executing a jvm where garbage collection is not running in parallel. T开发者_StackOverflow社区hat 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.


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.


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

Question is, why you want to know?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜