Skip to content

CAUTION: This site hosts draft documentation for the next release. For published content of the latest release, visit eclipse.dev/openj9/docs

-Xms / -Xmx

The Oracle® HotSpot™ option -Xms sets the initial or the minimum Java™ heap size, and the -Xmx HotSpot option sets the maximum heap size. These options are recognized by the Eclipse OpenJ9™ VM.

Notes:

  • If you set -Xms > -Xmx, the VM fails with the message -Xms too large for -Xmx.
    If you do not explicitly set the maximum object heap size with -Xmx and the VM uses the default value of -Xmx, then even if -Xms is greater than -Xmx initially, the VM starts successfully because the default -Xmx value is increased automatically to match -Xms.

    For example, for a VM with 16 GB RAM, the default maximum size is 25% of RAM, therefore the default value of Xmx will be 4 GB. If the initial size is specified as 6 GB (-Xms6g), then -Xms (6 GB) is greater than -Xmx (4 GB) and before the 0.53.0 release that VM used to fail. But now with current adjustment, the default maximum heap size is increased automatically to 6 GB and the VM starts. This change in behavior was added from the 0.53.0 release onwards.
  • If you exceed the limit set by the -Xmx option, the VM generates an OutofMemoryError.
  • If you set a value for -Xms, the -XX:InitialRAMPercentage option is ignored.
  • If you set a value for -Xmx, the -XX:MaxRAMPercentage option is ignored.

For the gencon GC policy, you can also use the -Xmo option:

  • If the scavenger is enabled, -Xms-Xmn + -Xmo
  • If the scavenger is disabled, -Xms-Xmo

Syntax

Setting Effect Default
-Xms<size> Set initial heap size 8 MB
-Xmx<size> Set maximum heap size 25% of available memory (25 GB maximum)

See Using -X command-line options for more information about the <size> parameter.
See Default settings for the OpenJ9 VM for more about default values.

The -Xmx option can be used with all OpenJ9 GC policies. However, the -Xms option can be used with all GC policies except for the metronome GC policy because the heap is always fully expanded.

Examples

-Xms2m -Xmx64m
Heap starts at 2 MB and grows to a maximum of 64 MB.
-Xms100m -Xmx100m
Heap starts at 100 MB and never grows.
-Xms50m
Heap starts at 50 MB and grows to the default maximum.
-Xmx256m
Heap starts at the default initial value and grows to a maximum of 256 MB.

See also