Zeruno
Zeruno

Reputation: 1639

Java JVM Default Garbage Collector: is it configured the same across different applications?

Simply as specified in the title.

I ran a test and recorded its memory heap usage pattern over time using JMX. Then I reran my jar file later and studied its memory behavior again. The result was a slightly different memory pattern. In both cases I didn't preconfigure my garbage collector. So I want to know now if two default garbage collectors have the same configurations on the same machine.

If not, how can I ensure that my garbage collector is the same without specifying many parameters? Also what could contribute to my result if not the GC config?

Upvotes: 0

Views: 311

Answers (1)

Speakjava
Speakjava

Reputation: 3392

If you run the same application on the same machine, with the same JVM, the heap and GC parameters will be the same.

Ergonomics was a feature introduced way back in JDK 5.0 to try and take some of the guesswork out of GC tuning. A server-class machine (2 or more cores and 2 or more Gb of memory) will use 1/4 of physical memory (up to 1Gb) for both the initial and maximum heap sizes (see https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html). So different machines may have different configurations by default.

To find out exactly what flags you have set, use: java -XX:+PrintFlagsFinal -version

The difference in memory usage pattern is simply the non-deterministic behaviour of your application. Even with the exact same set of inputs, I doubt you'd see exactly the same memory behaviour just down to so many other OS and hardware effects (cache, core affinity, etc.)

Upvotes: 2

Related Questions