OutOfMemoryError Comparison of HotSpot and JRockit

This section provides a tutorial example to compare the OutOfMemoryError exception between HotSpot 12, 10, 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.6 to JVM 12 gave me the same exception message, when it fails to expand the Heap to 50 MB as I specified in the "-Xmx50m" option:

C:\herong>java -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. JRockit JVM 28.2.7 gave me the same exception error, OutOfMemoryError. But it included a different message, "allocLargeObjectOrArray: [J, size 10485776":

C:\herong>\Progra~1\java\jrockit-jdk1.6.0_45-R28.2.7-4.1.0\bin\javac
   HeapMemoryCrash.java

C:\herong>\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)

Note that the exception from JRockit JVM is using allocLargeObjectOrArray() method to create my large array object.

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"

 The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

 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

 References

 Full Version in PDF/EPUB