简体   繁体   中英

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM