What are the -Xms and -Xmx parameters when starting JVM?
⚡TLDR
Adjust JVM heap size with -Xms
for starting memory and -Xmx
for maximum memory. Get better Java application performance with appropriate settings:
-Xms256m
= 256MB as an initial heap, -Xmx1g
= 1GB as a max heap. Now let's step into the practical application and details of these parameters.
Operational detail of -Xms
and -Xmx
The role of parameters
-Xms
: Affects startup efficiency by setting initial heap size.-Xmx
: Limits max heap size, preventingjava.lang.OutOfMemoryError
.
Principles for usage
- Adequate
-Xms
improves start-up performance and reduces unnecessary garbage collection. - Optimal
-Xmx
value prevents lengthy JVM pauses for garbage collection.
Precise allocation of memory using -Xms
and -Xmx
Dimensioning memory with units
- Units
k
,m
,g
represent kilobytes, megabytes, and gigabytes respectively. - Precise memory allocation is possible using these units with both
-Xmx
and-Xms
.
Beyond setting memory limits
- JVM's actual memory consumption includes more than just the heap; such as native interfaces and internals.
- Plan accordingly, as total memory footprint of JVM might exceed
-Xmx
.
Tweaking -Xms
and -Xmx
in Eclipse and other applications
Setting heap size in Eclipse
In Eclipse, -Xms
and -Xmx
are accessible via Run Configurations → VM arguments.
Accessing JVM options
JVM options including -Xms
and -Xmx
can be displayed by running java -X
in the terminal.
Linked
Linked
Was this article helpful?