8

While monitoring a java program with VisualVM, I noticed an interesting pattern in the garbage collector's behaviour. It seems like very often, right after doing a 'normal' garbage collection run, the GC does a second, much more cpu intensive run, which appears to have no additional effect (The used heap after the more aggressive run is about the same as it is after the lighter run).

I've indicated on VisualVM's output where you can see the garbage collector runs and corresponding heap-usage changes.

interesting garbage collector behaviour

My question is basically what is the Garbage collector doing here and why? What is causing it to attempt these really cpu-intensive runs when there's plenty of free memory, and no observable benefit versus the lighter runs? Or am I misinterpreting the graph?

The performance of the program isn't really affected, I'm just curious.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Gordon Bailey
  • 3,881
  • 20
  • 28
  • 1
    I doubt anybody here is going to be able to answer "why". You'd probably have to read the JVM source code to find out, and it may well change at any point. – Jim Garrison Apr 01 '13 at 21:48
  • 1
    @JimGarrison I feel like there must be at least one SO user who's worked on the JVM enough to answer the question ;-) – bdesham Apr 02 '13 at 16:24

1 Answers1

2

Looking at graphs is a good thing to get an overview of GC runs but if you want to study why the GC is running in a particular moment, you need to dig deep into the GC logs.

Enable full GC logging, start collecting jstat as well. Focus on those times where you see unexpected GC cycles and trace them back in the logs. What do you see there? Try to see :

  • is it Full or minor GC?
  • what are occupations of eden, perm, oldGen, survivor spaces, etc?
  • what are allocation rates, live data set size, promotion rates in those intervals?
  • etc.

Answering these questions could lead you to the problem of why the GC is running.

UPDATE: you can find technical details on howto tune GC e.g. in: Is there a cookbook guide for GC problems?

Community
  • 1
  • 1
Aleš
  • 8,896
  • 8
  • 62
  • 107