3

I'd like to know what is approximately the default schedule GC runs on java 6 (64bit) machines? I know it can be triggered without any schedule, but still, what would be the default behaviour?

I don't know if the java runs as with -server option. How can I check that? I don't see it in the java process command (when I do 'ps ax|grep java'), but still, can it be run in server mode anyway? Does it depend on a jvm installed, or the type of the physical server? Please let me know how can I know this.

javagirl
  • 1,635
  • 6
  • 27
  • 43
  • 4
    no you can NOT trigger it! you can ask it kindly – Philipp Sander Sep 24 '13 at 11:22
  • I know that. My point was that GC can run independently of any schedule, either it was triggered by human ("asked kindly" as you put it), or by itself, say if it's getting out of memory – javagirl Sep 24 '13 at 11:25
  • 3
    There is no time-based schedule, if that's what you are implying. – Marko Topolnik Sep 24 '13 at 11:30
  • @MarkoTopolnik If you see on the memory usage by jconsole - gc runs quite regularly, so there should be some sort of timer in place. Of course i didn't mean time-based schedule like cron does... – javagirl Sep 24 '13 at 12:07
  • 3
    The gc runs regularly if and only if the memory allocation happens at a steady pace. There are definitely no timers involved. – Marko Topolnik Sep 24 '13 at 12:11
  • @MarkoTopolnik so what's the regularity in case "memory allocation happens at a steady pace"? Can you disclose it please? – javagirl Sep 24 '13 at 12:16
  • It's all about heap allocation thresholds. The primary scenario is an allocation attempt within the eden space, which fails because the eden space is too full, regardless of any other heap regions. This triggers a minor GC, which is very fast, but only cleans up the eden space. – Marko Topolnik Sep 24 '13 at 12:22
  • I recommend using `visualgc` to see a much richer live view of all the heap regions. – Marko Topolnik Sep 24 '13 at 12:24
  • Also, see this Q/A: http://stackoverflow.com/q/4667483/772000 – Aleš Sep 24 '13 at 18:06

3 Answers3

4

First, to print all the default JVM settings, use : java -XX:+PrintFlagsFinal -version

By default, JVM Hotspot runs in the -client mode.

You can use the following parameters when starting your script -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=jvm.log to obtain a log containing all the properties/arguments set at the VM startup.

Regarding the GC, the defaults are determined by the JVM Ergonomics, see Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning. In short :

If not otherwise set on the command line, the initial and maximum heap sizes are calculated based on the amount of memory on the machine, the default maximum heap size will not exceed 1GB, regardless of how much memory is installed on the machine.

In the same document, the chosen GC algorithm depends on the hardware setup, the VM will decide between Serial and Parallel collectors. To see which one is running in the end, enable GC logging.

And, you should check out the following Q/A: How is the default java heap size determined?

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

Info about garbage collector: http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

If you want to know if your VM runs in server mode:

java -version

Then look for something like:

Java HotSpot(TM) 64-Bit Server VM (...)

isnot2bad
  • 24,105
  • 2
  • 29
  • 50
  • thanks for the -server part of your answer. But GC - it's a huge document, and i thought someone will give a precise answer on it. So my jvm is a server one indeed, 1.6, 64 bit. What's the schedule in that case? – javagirl Sep 24 '13 at 12:05
  • Well, that is the problem, there is no short answer. – Aleš Sep 25 '13 at 16:07
2

If you are creating 10 MB/second of garbage and you have a 100 MB Eden space it will take 10 seconds to fill up and you will see a GC every 10 seconds. Create less garbage or make the Eden space larger and the interval between collections will be higher.

There is a default timer of one hour this is called the "DGC". If no collection occurs for an hour, a full GC can be triggered to clean up any distributed objects. I usually have this set to a week.

The defaults are

-Dsun.rmi.dgc.client.gcInterval=3600000
-Dsun.rmi.dgc.server.gcInterval=3600000

BTW As I design low latency systems, I make the Eden space larger than the amount of garbage created in a day. I do a full collection triggered in code once per day when the system is not being used. This way you will see no collections, minor or major during the day.

Here is an example from a real low latency trading system in Java.

http://vanillajava.blogspot.com/2011/06/how-to-avoid-garbage-collection.html

BTW Java 6 update 25 is pretty old now and I would consider Java 6 update 45 if not Java 7 update 40.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130