JVM Tutorials - Herong's Tutorial Examples - v5.13, by Herong Yang
"-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 way 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"
herong> java -XX:+PrintGC -XX:+UseSerialGC -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.
Table of Contents
JVM (Java Virtual Machine) Specification
Java HotSpot VM - JVM by Oracle/Sun
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
JVM Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
►Micro Benchmark Runner and JVM Options
BenchmarkRunner.java - Benchmark Runner Program
emptyLoop() - The Empty Loop Test Method
"-XX:+PrintCompilation" - Watching JIT Compilation Logs
"-XX:+PrintGC" - Watching GC (Garbage Collection) Logs
►"-Xms" and "-Xmx" - Avoiding GC with Large Memory Size
Benchmark Affected by Other Running Applications
"-Xint" - Running in Interpreted-Only Mode
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations