Visit Support

Java Heap Memory

Table of Contents

Looking for Zing? The Azul Zing Virtual Machine is now Azul Zulu Prime Builds of OpenJDK and part of Azul Platform Prime. Learn more.

Java heap memory is the amount of memory dynamically allocated to a Azul Zulu Prime Builds of OpenJDK (Azul Zulu Prime JVM) instance running on the system. Objects in Java heap can be shared between threads.

Its size is specified using the –Xmx command-line option. It is the amount of memory the Azul Zulu Prime JVM instance needs to run the Java application, not including Pause Prevention and Contingency memory.

The -XX:JavaMemMax option allows you to set an upper bound on the amount of memory used for the Java heap. If this option is not set, the maximum is unlimited, though, in practice, it is limited by the size of the Contingency Memory.

  • A larger Java heap

    • Allows more objects to be created

    • Takes longer to fill

    • Allows the Azul Zulu Prime JVM instance to run longer between garbage collections (GC)

    • Consumes less CPU for garbage collection

  • A smaller Java heap

    • Holds fewer objects

    • Fills more quickly

    • Garbage is collected more frequently

    • May lead to out-of-memory errors

    • Consumes more CPU for garbage collection over time

Temporary Java Heap Memory

When needed to support the Java application, Azul Zulu Prime JVM temporarily allocates memory from Contingency memory and/or Pause Prevention memory. See Contingency Memory and Pause Prevention Memory.

Heap Memory in 32-Bit vs. 64-Bit Systems

Azul Zulu Prime JVM requires 64-bit systems. So, when determining the amount of Java heap memory to allocate, remember there is a difference in memory use in a 32-bit or 64-bit system.

Java heap memory requirements for 64-bit systems are generally 1.5 times greater than 32-bit systems. Though primitives such as integers use 32-bit words on either a 32-bit or 64-bit system, Java object headers and pointers use 32-bits on a 32-bit system and 64-bits on a 64-bit system. This applies to all Java environments, whether they are running JVMs from other vendors or a Azul Zulu Prime JVM instance.

The result is that proportionally more memory is used to accommodate the same number of objects on a 64-bit system. Increasing the efficiency of the garbage collector on a 64-bit system requires additional space relative to a 32-bit system.

The drawing below shows the relative scale for the cost of 32-bit and 64-bit words in Java objects. Notice, in the brown label area, that the same number of words consumes more memory for the 64-bit system. If no additional Java heap memory is allocated when using a 64-bit system then the available Java heap memory and the number of objects that can reside in the Java heap are reduced.