JVM Tutorials - Herong's Tutorial Examples - Version 4.23, by Dr. Herong Yang
OutOfMemoryError Comparison of HotSpot and JRockit
This section provides a tutorial example to compare the OutOfMemoryError exception between HotSpot 1.8, 1.7, 1.6 and JRockit 28.2.7.
As a comparison, I test my example, HeapMemoryCrash.java, with other versions of HotSpot JVM and JRockit JVM.
1. HotSpot Server JVM 1.8.0 gave me some interesting output. It failed expand the Heap to 50 MB as I specified in "-Xmx50m":
C:\herong>\progra~1\java\jdk1.8.0\bin\javac HeapMemoryCrash.java C:\herong>\progra~1\java\jdk1.8.0\bin\java -server -Xms20m -Xmx50m HeapMemoryCrash Total memory: 20185088 Free memory: 19926784 Used memory: 258304 Press ENTER key to continue: 1: 10 MB of objects created. Total memory: 20185088 Free memory: 9410016 Used memory: 10775072 Press ENTER key to continue: 2: 20 MB of objects created. Total memory: 30932992 Free memory: 9672144 Used memory: 21260848 Press ENTER key to continue: 3: 30 MB of objects created. Total memory: 41156608 Free memory: 9409984 Used memory: 31746624 Press ENTER key to continue: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at HeapMemoryCrash.main(HeapMemoryCrash.java:10)
2. HotSpot JVM 1.7.0_45 gave me very similar result as HotSpot JVM 1.8.0:
C:\herong>\progra~1\java\jdk1.7.0_45\bin\javac HeapMemoryCrash.java C:\herong>\progra~1\java\jdk1.7.0_45\bin\java -Xms20m -Xmx50m HeapMemoryCrash Total memory: 20447232 Free memory: 20288808 Used memory: 158424 Press ENTER key to continue: 1: 10 MB of objects created. Total memory: 25862144 Free memory: 15183232 Used memory: 10678912 Press ENTER key to continue: 2: 20 MB of objects created. Total memory: 50724864 Free memory: 29560712 Used memory: 21164152 Press ENTER key to continue: 3: 30 MB of objects created. Total memory: 50724864 Free memory: 19074936 Used memory: 31649928 Press ENTER key to continue: 4: 40 MB of objects created. Total memory: 50724864 Free memory: 8589160 Used memory: 42135704 Press ENTER key to continue: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at HeapMemoryCrash.main(HeapMemoryCrash.java:10)
3. HotSpot JVM 1.6.0_45 also gave me very similar result as HotSpot JVM 1.8.0:
C:\herong>\progra~1\java\jdk1.6.0_45\bin\javac HeapMemoryCrash.java C:\herong>\progra~1\java\jdk1.6.0_45\bin\java -Xms20m -Xmx50m HeapMemoryCrash Total memory: 20447232 Free memory: 20318872 Used memory: 128360 Press ENTER key to continue: 1: 10 MB of objects created. Total memory: 25796608 Free memory: 15157088 Used memory: 10639520 Press ENTER key to continue: 2: 20 MB of objects created. Total memory: 50724864 Free memory: 29599800 Used memory: 21125064 Press ENTER key to continue: 3: 30 MB of objects created. Total memory: 50724864 Free memory: 19114024 Used memory: 31610840 Press ENTER key to continue: 4: 40 MB of objects created. Total memory: 50724864 Free memory: 8628248 Used memory: 42096616 Press ENTER key to continue: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at HeapMemoryCrash.main(HeapMemoryCrash.java:10)
4. JRockit JVM 28.2.7 gave me the same exception error, OutOfMemoryError. But it included a different message, "allocLargeObjectOrArray: [J, size 10485776":
Note that the exception from JRockit JVM is using allocLargeObjectOrArray() method to create my large array object.
C:\>\Progra~1\java\jrockit-jdk1.6.0_45-R28.2.7-4.1.0\bin\javac HeapMemoryCrash.java C:\>\Progra~1\java\jrockit-jdk1.6.0_45-R28.2.7-4.1.0\bin\java -Xms20m -Xmx50m HeapMemoryCrash Total memory: 20971520 Free memory: 17905560 Used memory: 3065960 Press ENTER key to continue: 1: 10 MB of objects created. Total memory: 20971520 Free memory: 9496216 Used memory: 11475304 Press ENTER key to continue: 2: 20 MB of objects created. Total memory: 31760384 Free memory: 10510888 Used memory: 21249496 Press ENTER key to continue: 3: 30 MB of objects created. Total memory: 47411200 Free memory: 15675928 Used memory: 31735272 Press ENTER key to continue: 4: 40 MB of objects created. Total memory: 47411200 Free memory: 5190216 Used memory: 42220984 Press ENTER key to continue: Exception in thread "Main Thread" java.lang.OutOfMemoryError: allocLargeObjectOrArray: [J, size 10485776 at HeapMemoryCrash.main(HeapMemoryCrash.java:10)
Last update: 2014.
Table of Contents
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
JRockit JVM 28.2.7 by Oracle Corporation
►Memory Management and Garbage Collectors
Memory Management General Rules
Java Exception: "java.lang.OutOfMemoryError: Java heap space"
►OutOfMemoryError Comparison of HotSpot and JRockit
Garbage Collection Demonstration
JVM Memory Manager - Garbage Collector
Generational Garbage Collection in HotSpot
Young Generation Collection - Minor Collection
Tenured Generation Collection - Full Collection
HotSpot Default Garbage Collector - Serial Collector
"-XX:+PrintGCDetails" - Garbage Collection Logging
GC Log Messages on GarbageCollection.java
Serial, Parallel, Concurrent, and Regionalized Collectors
Parallel Collector GC Log Message Format
Parallel Compacting Collector GC Log Message Format
Concurrent Mark-Sweep Collector GC Log Message Format
Garbage First GC Log Message Format
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
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode