When you are using JVM in 32-bit mode, the maximum heap size that can be allocated is 1280 MB. So, if you want to go beyond that, you need to invoke JVM in 64-mode.

You can use following:

$ java -d64 -Xms512m -Xmx4g HelloWorld

where,

  • -d64: Will enable 64-bit JVM
  • -Xms512m: Will set initial heap size as 512 MB
  • -Xmx4g: Will set maximum heap size as 4 GB

You can tune in -Xms and -Xmx as per you requirements (YMMV)

A very good resource on JVM performance tuning, which might want to look into: http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

Answer from mohitsoni on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-is-the-default-max-java-heap-size-determined
How is the default max Java Heap size determined? - GeeksforGeeks
July 23, 2025 - The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one-fourth of the physical memory up to a physical memory size of 1 gigabyte.
Discussions

JVM (total) max memory
Yes, from a developer point of view, that would be easier. It's probably because its complex memory management model that this is not possible. What I mostly do is: Pack the Java application in a container (so you know it's the only running process). Set the memory limit on the container level. For example, attribute 4 GB max to the container. Start the container with -XX:MaxRAMPercentage=80.0 (this leaves enough room for other types of memory and OS processes. The above is probably a bit on the safe side, so when you monitor your application a bit longer, it may be safe to put the MaxRamPercentage value a bit higher. More on reddit.com
🌐 r/java
18
18
June 10, 2023
How is the default max Java heap size determined? - Stack Overflow
If I omit the -Xmxn option from the Java command line then a default value will be used. According to Java documentation "the default value is chosen at runtime based on system configuration&... More on stackoverflow.com
🌐 stackoverflow.com
Increase heap size in Java - Stack Overflow
How can I increase the heap memory maximum? I am using the -Xmx1500m flag to increase the heap size to 1500 Mb. Can I increase the heap memory to 75% of physical memory (6 GB Heap)? ... Just wanted to mention here that, starting from Java 8 It is now possible to set the heap memory as a fraction ... More on stackoverflow.com
🌐 stackoverflow.com
How to increase java' heap size, whatever that is
The Java Virtual Machine (JVM) reserves some amount of memory at startup. This memory is called the heap and is used for objects during runtime. If the JVM doesn't have enough heap memory programs will start throwing OutOfMemoryExceptions and usually crash. You can configure the JVM to reserve more memory at startup with some flags: -Xms256m: This tells the JVM to reserve a minimum of 256 megabytes at startup. If you want to reserve more just increase the amount. 1024m is 1 gigabyte. 2014 is 2 gigabytes. -Xmx1024m: This tells the JVM to not use more than 1024 megabytes during runtime. If your program tries to use more memory then you'll get the OutOfMemoryExceptions explained above. The error you are seeing is likely because -Xms is being set to a larger value than -Xmx. It doesn't make any sense to request more minimum memory than the maximum you've specified, right? I suggest making the values of -Xms and -Xmx the same. More on reddit.com
🌐 r/javahelp
17
3
December 29, 2017
🌐
Oracle
docs.oracle.com › cd › E19159-01 › 819-3681 › abeii › index.html
Tuning the Java Heap (Sun Java System Application Server 9.1 Performance Tuning Guide)
By default, the JVM grows or shrinks the heap at each GC to try to keep the proportion of free space to the living objects at each collection within a specific range. This range is set as a percentage by the parameters -XX:MinHeapFreeRatio=minimum and -XX:MaxHeapFreeRatio=maximum; and the total size bounded by -Xms and -Xmx.
🌐
Blogger
javarevisited.blogspot.com › 2013 › 04 › what-is-maximum-heap-size-for-32-bit-64-JVM-Java-memory.html
What is the maximum Heap Size of 32 bit or 64-bit JVM in Windows and Linux?
Maximum heap size for 32 bit or 64 bit JVM looks easy to determine by looking at addressable memory space like 2^32 (4GB) for 32 bit JVM and 2^64 for 64 bit JVM. The confusion starts here because you can not really set 4GB as the maximum heap ...
🌐
Medium
medium.com › @maheshwar.ramkrushna › understanding-heap-size-and-its-impact-on-java-application-performance-d4c312bbd13c
Understanding Heap Size and its Impact on Java Application Performance | by Ramkrushna Maheshwar | Medium
May 25, 2023 - We recommend increasing the maximum heap allocation to 512 MB or 1024 MB when dealing with discovery ranges equivalent to a class B subnet, or in excess of 30,000 addressable devices.
🌐
IBM
ibm.com › support › pages › recommended-maximum-heap-sizes-32-and-64-bit-websphere-java-instances
Recommended Maximum Heap Sizes on 32 and 64 bit WebSphere Java instances
For 32 bit platforms and Java stacks in general, the recommended Maximum Heap range for WebSphere Application Server (WAS), would be between (1024M - 1536M) or (1G - 1.5G); higher values will most likely eventually result in Native Memory contention.
🌐
Oracle
docs.oracle.com › en › graalvm › jdk › 21 › docs › reference-manual › native-image › optimizations-and-performance › MemoryManagement
Memory Management
April 21, 2026 - For example, on a machine with 4GB of RAM, the maximum Java heap size will be set to 3.2GB. If the same image is executed on a machine that has 32GB of RAM, the maximum Java heap size will be set to 25.6GB. Note that this is just the maximum value. Depending on the application, the amount of ...
Find elsewhere
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › java-xmx-xms-memory-heap-size-control
How to control Java heap size (memory) allocation (xmx, xms) | alvinalexander.com
January 31, 2026 - The default size is 64M. (The -server flag increases the default size to 128M.) The maximum heap limit is about 2 GB (2048MB). When setting the Java heap size, you should specify your memory argument using one of the letters “m” or “M” for MB, or “g” or “G” for GB.
🌐
Eclipse OpenJ9 Blog
blog.openj9.org › 2020 › 04 › 30 › default-java-maximum-heap-size-is-changed-for-java-8
Default Java Maximum Heap Size is changed for Java 8 – Eclipse OpenJ9 Blog
April 30, 2020 - From OpenJ9 release 0.20, The default Java Maximum Heap Size (Xmx) is changed to be consistent with Java 11, so by default in Java 8, 25% physical memory up to 25GB for the Xmx will be expected.
🌐
IBM
ibm.com › docs › en › itcam-app-mgr › 7.2.1
Setting the maximum Java heap size
Build, govern, and manage your data for generative AI solutions · Use pre-integrated automation technologies to design, build, and run automation applications and services on the cloud
🌐
Reddit
reddit.com › r/java › jvm (total) max memory
r/java on Reddit: JVM (total) max memory
June 10, 2023 -

I was pondering it for a while now and... it would be great if JVM would allow specifying maximum (total) JVM memory usage.

Currently, we can specify it for various parts of JMV (most notably heap) but very often other parts (meta, threads, code, gc, symbols, etc) take also part of memory (often significant) thus specifying only heap can be tricky, especially if we want to maximize resource usage on the machine (be that VM or within container)...

Top answer
1 of 5
10
Yes, from a developer point of view, that would be easier. It's probably because its complex memory management model that this is not possible. What I mostly do is: Pack the Java application in a container (so you know it's the only running process). Set the memory limit on the container level. For example, attribute 4 GB max to the container. Start the container with -XX:MaxRAMPercentage=80.0 (this leaves enough room for other types of memory and OS processes. The above is probably a bit on the safe side, so when you monitor your application a bit longer, it may be safe to put the MaxRamPercentage value a bit higher.
2 of 5
2
I highly recommend reading the Measuring Performance article from the Quarkus team. They touch on what metric to look at in order to capture the entire, actual memory usage of a JVM process. If you‘re using Micrometer, you can include RSS metrics via https://github.com/mweirauch/micrometer-jvm-extras . Micrometer ships with metrics for Heap and Non-Heap usage out of the box. You should monitor heap, non-heap, and RSS of your application under load to get an idea what a sensible MaxRAMPercentage might be. We ran with MaxRAMPercentage=90.0 and were experiencing OOMKilled issues on k8s, despite our Heap metrics staying well below the memory limit configured in our deployment. It turned out that we used a compression library that essentially was just a JNI binding to a native library, and it was buffering large amounts of data off-heap.
🌐
IBM
ibm.com › support › pages › largest-possible-maximum-heap-size-websphere-java-64-bit-linux-x86-64
Largest Possible Maximum Heap Size for WebSphere Java 64 Bit on Linux x86-64
Java on Linux x86-64 supports 48-bit pointers and 256 TB of virtual address space, of which 128 terabytes is reserved for the Kernel, and 128 terabytes for User space. Maximum Heap in theory on WAS Linux x86-64 would be -Xmx128t with the caveat or requirement of having -Xnocompressedrefs in ...
🌐
Linux.org
linux.org › home › forums › general linux forums › general computing
How to increase Java runtime maximum heap memory? | Linux.org
December 1, 2024 - VM settings: Max. Heap Size (Estimated): 3.86G Using VM: OpenJDK 64-Bit Server VM · Click to expand... This according to my understanding means that Java applications will be limited to 4GB of memory, however my system has 16GB and I want to increase it to at least 8GB because I need it for a game.
🌐
IBM
ibm.com › docs › en › sdk-java-technology › 8
IBM SDK, Java Technology Edition 8
Understanding the operations of the Garbage Collector (GC) helps you set initial and maximum heap sizes for efficient management of the heap.
Top answer
1 of 10
669

On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

2 of 10
130

For Java SE 5: According to Garbage Collector Ergonomics [Oracle]:

initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

UPDATE:

As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

with the exception of 32 bit platforms running a version of the Windows operating system. On all other platforms the default values are the same as the default values for version 1.4.2.

In the J2SE platform version 1.4.2 by default the following selections were made

  • initial heap size of 4 Mbyte
  • maximum heap size of 64 Mbyte
🌐
Azul
docs.azul.com › prime › Heap-Size
Recommended Heap Size
Intel Ice Lake and newer x86 ... a maximum heap size of 14000 GB (14 TB). + When ZST is installed, the default value is 1GB and the maximum is 20000GB (20TB). -Xms<size>[m|M|g|G] Starting with 21.07.0.0, this flag specifies the minimum size of the Java heap that is committed ...
🌐
Mike my bytes
mikemybytes.com › 2022 › 11 › 15 › what-happens-when-you-only-limit-the-maximum-heap-size
What happens when you only limit the maximum heap size? | Mike my bytes
November 15, 2022 - Let’s have an example to illustrate ... 32M [0.003s][info][gc,init] Heap Initial Capacity: 32M [0.003s][info][gc,init] Heap Max Capacity: 104M...