∟"-Xms" and "-Xmx" - Avoiding GC with Large Memory Size
This section provides a tutorial example on how to allocate more memory to JVM to avoid GC to reduce the impact benchmark tests.
There is no obvious to turn off GC (Garbage Collection) completely in HotSpot JVM.
But you can avoid GC by giving the JVM enough memory to work with using "-Xms" and "-Xmx"
options.
Here is another test I did with "-Xms100m" and "-Xmx100m"
C:\herong\jvm>java -XX:+PrintGC -Xms100m -Xmx100m BenchmarkRunner
BenchmarkLoopTest emptyLoop 10000 3 3
Are you ready?
y
Waking up the JIT compiler...
Run: 1, Time: 8661, Test returns: 3
Run: 2, Time: 3911, Test returns: 3
Run: 3, Time: 3911, Test returns: 3
...
Run: 4853, Time: 1956, Test returns: 3
Run: 4854, Time: 10616, Test returns: 3
Run: 4855, Time: 1955, Test returns: 3
...
Run: 6984, Time: 1956, Test returns: 3
Run: 6985, Time: 1676, Test returns: 3
Run: 6986, Time: 24025, Test returns: 3
Run: 6987, Time: 2514, Test returns: 3
Run: 6988, Time: 1956, Test returns: 3
...
As you can see from the test result, no GC was performed for 10000 runs,
because 100 MB of minimum memory and maximum memory allocation give the benchmark
program enough memory to work without any GC.
However, 2 test runs were still interrupted by some other activities in the JVM or
the operating system.