"-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?

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.

Last update: 2010.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

Micro Benchmark Runner and JVM Options

 What Is Micro Benchmark?

 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

 Outdated Tutorials


 PDF Printing Version