The Most Awesomely Useful GC Tuning Tool Ever

You too can tune your Java applications’ GC performance to total perfection! How can you do this?

Using jvmstat, the most useful GC tool ever!

It displays graphically the amount of memory the eden, two survivor spaces, and tenured generations are using; and when compile and GC blips occur. You simply run your Java game, get the task manager up to find its process ID, and then from the command prompt type visualgc and Bob’s your uncle.

By watching the graphs whilst playing Alien Flux I’ve discovered to my delight that the only memory allocations going on during the game were in eden space, slowly, and that during the normal course of the game none of the objects survived to the survivor or tenured generation. So I set my eden space to be super small (500K) and hence collected much, much more frequently. I also picked an appropriate collector from the 4 now available to use on my dualie 1GHz dev box and ended up with this neat-o set of parameters for running AF:


-server -XX:CompileThreshold=200 -XX:MaxInlineSize=16 -Xmx32m -Xms32m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:NewSize=500K -XX:MaxNewSize=500K -XX:+DisableExplicitGC -Djava.library.path=.

I’d be especially interested if anyone could test this config. on a slower box (300-600MHz) to tell me if it’s unnacceptably slow starting up (>20secs).

Cas :slight_smile:

Yeah I’ve been playing with that too… (I mentioned it here a couple weeks ago - didn’t get any comments :frowning: )

It is pretty darn sweet.

Aren’t -XX:+UseConcMarkSweepGC and -XX:+UseParNewGC mutually exclusive???

I pasted those two options directly out of the Hotspot GC tuning guide, where they appear together.

Cas :slight_smile:

Well there you go… I’ve probably been using the parallel thing wrong all along… ::slight_smile:
I’m glad someone read the manual ;D

Ah I just discovered my confusion about those GC options… There is an older option -XX:+UseParallelGC and it DOES conflict with -XX:+UseConcMarkSweepGC

Gregory and others that were following the GC issues thread.
This thread is about jvmstat a tool available from Sun that graphs all sorts of nice stats in realtime pertaining to GC and other stuff. (e.g. JIT compiling)

I was looking at this before but wasn’t able to get this to run on OSX (JDK1.4.1). Since it looks like its supposed to work, I will try running it again and report issues to the Apple java team.

Yeah, actually I realize now that I only used it on Windows.

Also keep in mind that version 2.0 of jvmstat requires Java 1.4.2

Like you say it looks like it should work. It is Java and appears to use RMI or something.

On Mac I have trouble getting it to link up with my Java process. “Could not find expected counter”

I installed it. It looks very cool with all these dials, bars and stuff, but what do they all mean? I couldn’t find any extensive documentation. I got no clue what eden is. Where do I start to learn to decipher all of this.

In short:
a) What is it trying to tell me?
b) What should I do about it?

What you’re trying to achieve is a jitter-free frame rate for the vast majority of your game, with no regular or long pauses.

To achieve this you need to understand how the garbage collectors work in Java:
http://java.sun.com/docs/hotspot/gc1.4.2/index.html

Armed with knowledge of how memory is allocated and deallocated in Java, you can then use this tool to see the pattern of memory allocation in your game. You can watch for example eden filling up every 60 frames graphically, which is really quite handy. It’s then a matter of tweaking the GC tuning parameters outlined in that document until the pauses you get during normal running of your game fit into a frame or only occur when it doesn’t matter.

Cas :slight_smile:

One recommendation, dump the -XX:CompileThreshold=200, you are causing way more compilations then are required. This will cause less profile data to be collected, and subsequently worse performance. -XX:MaxInlineSize=16 is also suspect, dump it.

I tried to get jvmstat to run, but had no luck. Nutters!

I can run jvmstat -gcutil 0 1000 3, from the docs, but running jvmps gives nothing. Is there some other way to get the process id I need?

I’m using eclipse to start my app, but I also tried double clicking the jar. jvmps never showed anything.

I’m in windows XP.

Help! ???

Regards,
Aaron R>

Get the process id on Windows with the Windows Task Mananger. Look at the “Processes” tab and in the “View” menu choose “Select Columns…” and check off “PID (Process Identifier)”

ajiva - could you divulge the default value of MaxInlineSize? (& FreqInlineSize)?

Cas :slight_smile:

The best way is to download the 1.4.2 source code, but here are the answers anyway:

FreqInlineSize=325 (This is X86 specific)
MaxInlineSize = 35

Thanks, that’s interesting to know.

Cas :slight_smile: