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

 About This Book

Heap Memory Area and Size Control

 Java Exception: "java.lang.OutOfMemoryError: Java heap space"

 Memory Allocation Limits on Windows Systems

OutOfMemoryError Comparison of HotSpot and JRockit

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

 Serial Collector - "+XX:+UseSerialGC"

 Parallel Collector - "+XX:+UseParallelGC"

 Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 Object References and Garbage Collection

 Garbage Collection Performance Test Program

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 Outdated Tutorials

 References

 Full Version in PDF/EPUB