Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace Runtime.gc() with my own implementation?

I've observed "Full GC (System)" messages being written to my logs every 60 minutes. When I do this:

jstat -gccause {pid} 5s 

I see that this is coming from explicit calls to System.gc(). I'm trying to track down what code is calling System.gc(), as I suspect that this is happening in one of my dependencies, not my own code.

I do realize I can disable explicit GC calls with -XX:-DisableExplicitGC, but I need to figure out where the calls are coming from. I have read here and here that this guy was able to change the Runtime class to log the stack trace when gc() is called. But I'm not clear on how to do this. Can someone point me in the right direction?

like image 708
John McCann Avatar asked Sep 03 '26 14:09

John McCann


1 Answers

Get the source code for Runtime.java, and add code to the gc() method:

try {
    throw new Exception("Who is the GC culprit?");
} catch (Exception e) {
    e.printStackTrace();
}

After you compile the class, update rt.jar with the new class file.

like image 162
bdkosher Avatar answered Sep 06 '26 03:09

bdkosher