Invalid Initial And Maximum Heap Size In JVM - How To Fix
Javarevisited
Learn Java, Programming, Spring, Hibernate throw tutorials, examples, and interview questions
Topics and Categories
- core java
- spring
- hibernate
- collections
- multithreading
- design patterns
- interview questions
- coding
- data structure
- OOP
- java 8
- books
- About Me
- Java Certifications
- JDBC
- jsp-servlet
- JSON
- SQL
- Linux
- Courses
- online resources
- jvm-internals
- REST
- Eclipse
- jQuery
- Java IO
- Java XML
Friday, July 30, 2021
Invalid initial and maximum heap size in JVM - How to Fix I was getting "Invalid initial heap size: -Xms=1024M" while starting JVM and even after changing the maximum heap size from 1024 to 512M it keeps crashing by telling "Invalid initial heap size: -Xms=512m, Could not create the Java virtual machine". I check almost everything starting from checking how much physical memory my machine has to any typo in JVM parameters, only to find out that instead of M, I had put MB there. Java accepts both the small case and the capital case for Kilo, Mega, and Gigs. you can use m or M, g or G, etc but never used MB, GB, or KB. A similar problem can occur with the maximum heap size specified by -Xmx. Also from Java 6 update 18, there is a change in default heap size in JVM.Invalid initial and maximum heap size in JVM
Here is a list of common errors while specifying maximum and minimum heap size in Java : java -Xmx4056M -Xms4056M HelloWorld Issue:Error occurred during initialization of VM , The size of the object heap + VM data exceeds the maximum representable size Cause: the value of either -Xms or -Xmx is higher than or close to the size of physical memory, as my machine has 4GB memory. java -Xmx1056M -Xms2056M HelloWorld Issue:Error occurred during initialization of VM , Incompatible minimum, and maximum heap sizes specified Cause: the value of -Xms is higher than -Xmx java -Xms2056M HelloWorld Issue: Error occurred during initialization of VM , Could not reserve enough space for object heap Cause: Only -Xms was provided and -Xmx was not provided. you will also get this error if you have a typo and instead of -Xmx you have specified -Xms two times, happened to my friend last time. Command: java -Xms1024 M -Xmx1024M HelloWorld Issue: Error occurred during initialization of VM , Too small initial heap Cause: If you had space between 1024 and M then JVM assumes the size of -Xms as 1024 bytes only and prints an error that it's too small for JVM to start.Invalid heap size
Another scenario when the "invalid heap size" issue comes while restarting JVM is when you configure 64 bit JVM to accept the memory of more than 4GB but it's running on a 32-bit data model. This "invalid heap size" occurs particularly in the Solaris box where J2SE installation contains both 32 bit and 64-bit J2SE implementation. On other environments like Windows and Linux, 32 bit and 64 bit JVM are installed separately. 64 bit JVM installed on Solaris machines runs with a 32-bit model if you don't specify either -d32 or -d64, which won't accept a Maximum heap size of 4GB, hence "invalid heap size". You can resolve this issue by running Solaris JVM with option -d64. -d64 command-line option allows JVM to use a 64-bit data model if available. public class HelloWorld{ public static void main(String args[]){ System.out.println("HelloWorld to Java"); } } $ test@nykdev32:~ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode) $ test@nykdev32:~ java -Xmx4096M HelloWorld Invalid maximum heap size: -Xmx4096M The specified size exceeds the maximum representable size. Could not create the Java virtual machine. $ test@nykdev32:~ java -d64 -Xmx4096M HelloWorld HelloWorld to Java If you run the Java program from the command line then you will also get a message that say Could not create the Java virtual machine with each invalid heap error but if you run your program from Eclipse you will not get the message "Could not create the Java virtual machine", instead, you will just see an error message in the console. Regarding default heap size in Java, from Java 6 update 18 there are significant changes in how JVM calculates default heap size in 32 and 64-bit machines and on client and server JVM mode: 1) Initial heap space and maximum heap space is larger for improved performance. 2) The default maximum heap space is 1/2 of the physical memory of size up to 192 bytes and 1/4th of physical memory for a size up to 1G. So for a 1G machine maximum heap size is 256MB 2.maximum heap size will not be used until the program creates enough objects to fill the initial heap space which will be much lesser but at least 8 MB or 1/64th part of Physical memory up to 1G. 3) For Server Java virtual machine default maximum heap space is 1G for 4GB of physical memory on a 32 bit JVM. for 64 bit JVM it's 32G for physical memory of 128GB. Other Java tutorials you may find useful How Garbage collection works in Java How ClassLoader works in Java 10 Garbage Collection Interview question Answer How to remote debug Java program in Eclipse How to increase heap size in Maven and ANT script Labels: core java , debugging , error and exception , JVM Internals 6 comments :
Anonymous said...Hello, I am getting following error, while starting a core Java based Server in a shared Solaris host "Error occurred during initialization of VMCould not reserve enough space for object heap" , Program was running fine few days ago, but when I am restarting it now, it's giving me this error. There is no change in JVM arguments passed to program, I also tried with different heap size (4GB, 2GB, 500MB) , but still same error, please help
Anonymous said...Thanks for this, this saved my day. I am getting below error in Maven, while running mvn install while building a Java project on Eclipse IDE :Error occurred during initialization of VMCould not reserve enough space for object heapError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.Later I realized that I was using JDK 1.7 32-bit virtual machine and configuring Maven's surefire plugin, which is used to run all JUnit test cases with following JVM memory arguments :-Xms800m -Xmx800m -XX:MaxPermSize=500mSince this configuration was actually for 64-bit JVM, it was throwing Invalid Heap Size error. There was two ways to fix that, either moving to 64-bit JDK or reducing memory size to half e.g. -Xms400m -Xmx400m -XX:MaxPermSize=200mFor me second solution works fine. Thanks
Anonymous said...I am getting following error while running my maven build :Error occurred during initialization of VMIncompatible minimum and maximum heap sizes specifiedPlease help
Anonymous said...The particular error listed at the top ("Invalid initial heap size: -Xms=1024M") is caused by having the equals sign, so changing it to just "-Xms1024M" should take care of it, as I just found out from a misconfiguration of my own.
Anonymous said...I am using JDK8, and trying to run a Junit from my eclipse. and I am getting the error as "Invalid Initial heap size: -Xms8192mThe specified size exceeds the maximum representable size"
javin paul said...Hello @anonymous, just check if you are using 32-bit JVM on which max heap size is 4GB since you are giving 8GB its giving the error. Most likely you don't need that much heap so you can reduce it to 1GB and try again and if you do need, switch to 64-bit JVM
Post a Comment
Newer Post Older Post Home Subscribe to: Post Comments ( Atom )Best System Design and Coding Interview Resources
System Design & Interview Prep
- ByteByteGo Lifetime Plan (50% OFF)
- Codemia Lifetime Plan (60% OFF)
- Exponent Annual Plan (70% OFF)
- Educative Premium Plus (55% OFF)
- DesignGurus All Course Bundle (55% OFF)
- Everything Java Interview Bundle (50% OFF)
- 101 Blockchain (50% OFF)
- Vlad Mihalcea's High Performance Bundle (50% OFF)
- Javarevisited Substack Subscription (50% OFF)
- Head First Software Architecture (Book)
Best Online Learning Resources and Platforms
- Coursera Plus (40% OFF)
- Datacamp Black Friday Sale (50% OFF)
- AlgoMonster Lifetime Plan (50% OFF)
- Udemy Black Friday Sale (80% OFF)
- Baeldung Black Friday Sale (33% OFF)
- LabEx Black Friday Sale (50% OFF)
- Codecademy Black Friday Sale (60% OFF)
- Udacity Black Friday Sale (50% OFF)
- ZTM Academy Sale (66% OFF)
- Frontend Masters Black Friday Deal
- Whizlabs Black Friday Deal (70% OFF)
Search This Blog
Preparing for Java and Spring Boot Interview?
- Join My Newsletter .. Its FREE
My Books
- Everything Bundle (Java + Spring Boot + SQL Interview) for a discount
- Grokking the Java Interview
- Grokking the Spring Boot Interview
- Spring Framework Practice Questions
- Grokking the SQL Interview
- Grokking the Java Interview Part 2
- Grokking the Java SE 17 Developer Certification (1Z0-829 Exam)
My Courses
- Spring Professional Certification Practice Test
- Java SE 11 Certification Practice Test
- Azure Fundamentals AZ-900 Practice Test
- Java EE Developer Exam Practice Test
- Java Foundations 1Z0-811 Exam Practice Test
- AWS Cloud Practitioner CLF-C02 Exam Practice Test
- Java SE 17 1Z0-829 Exam Practice Test
- Azure AI-900 Exam Practice Test
- 1Z0-829 Java Certification Topic wise Practice Test
My Newsletter articles
- How to grow financially as Software Engineer?
- Difference between Microservices and Monolithic Architecture
- What is Rate Limiter? How does it work
- Difference between @Component vs @Bean annotations in Spring Framework?
- Top 10 Software Design Concepts Every Developer should know
- How does SSO Single Sign On Authentication Works?
Interview Questions
- core java interview question (183)
- interview questions (110)
- data structure and algorithm (92)
- Coding Interview Question (86)
- spring interview questions (52)
- design patterns (48)
- object oriented programming (42)
- SQL Interview Questions (37)
- thread interview questions (30)
- collections interview questions (26)
- database interview questions (16)
- servlet interview questions (15)
- hibernate interview questions (11)
- Programming interview question (6)
Java Tutorials
- FIX protocol tutorial (16)
- JDBC (35)
- Java Certification OCPJP SCJP (33)
- Java JSON tutorial (23)
- Java Programming Tutorials (21)
- Java multithreading Tutorials (64)
- Java xml tutorial (16)
- date and time tutorial (27)
- java IO tutorial (30)
- java collection tutorial (94)
- jsp-servlet (37)
- online resources (218)
Get New Blog Posts on Your Email
Get new posts by email:
SubscribeFollowers
Categories
- courses (312)
- SQL (78)
- linux (54)
- database (52)
- Eclipse (38)
- REST (34)
- Java Certification OCPJP SCJP (33)
- JVM Internals (27)
- JQuery (26)
- Testing (24)
- Maven (16)
- general (16)
Blog Archive
- ► 2025 (907)
- ► December (20)
- ► November (33)
- ► October (121)
- ► September (39)
- ► August (20)
- ► July (111)
- ► June (106)
- ► May (85)
- ► April (116)
- ► March (32)
- ► February (105)
- ► January (119)
- ► 2024 (185)
- ► December (14)
- ► November (3)
- ► October (35)
- ► September (28)
- ► August (10)
- ► July (20)
- ► June (7)
- ► May (24)
- ► April (30)
- ► March (9)
- ► February (1)
- ► January (4)
- ► 2023 (511)
- ► December (4)
- ► November (4)
- ► October (7)
- ► September (149)
- ► August (20)
- ► July (43)
- ► June (2)
- ► May (151)
- ► April (91)
- ► March (27)
- ► February (8)
- ► January (5)
- ► 2022 (69)
- ► December (1)
- ► September (1)
- ► August (20)
- ► July (20)
- ► June (7)
- ► May (5)
- ► April (4)
- ► March (3)
- ► February (6)
- ► January (2)
Contributors
- SimpleJava
- javin paul
Popular Posts
-
Top 5 Websites to Learn SQL Online for FREE - Best of Lot SQL is one of the most important skills for any programmer be it a Java , C++ , Python , JavaScript , or Ruby developer. Almost 95% of the J... -
How to create HTTP Server in Java - ServerSocket Example Java has very good networking support, allows you to write client-server applications by using TCP Sockets. In this tutorial, we will learn... -
The 2025 Java Developer RoadMap [UPDATED] Hello guys, I have been sharing a lot of roadmaps to become a Web developer , DevOps engineer , and recently React.js developer . One of th... -
Top 5 Udemy + Pluralsight Courses to Learn Vue.js in 2025 - Best of Lot Hello frontend and full-stack developers, if you want to use Vue.js for your next project and looking to learn Vue.js online and looking for... -
Top 10 Java, Spring, and Hibernate Books for Experienced Java Web Developers in 2025 Hello guys, If you are thinking that you have read all the essential books on Java and don't have anything new to read, then hang on. J... -
DesignGurus.io or Bugfree.ai? Which is Better Place to Prepare for System Design Interview in 2026? Hello guys, preparing for coding interviews in 2026 is much more competitive than ever. The tech market is flooded with more qualified can...
-
3 ways to solve java.lang.NoClassDefFoundError in Java J2EE I know how frustrating is to see "Exception in thread "main" java.lang.NoClassDefFoundError" while running your Java ...
-
Top 20 Books Every Java Programmers Should Read [UPDATED] Hello guys, Happy New Year. We are already in New Year and while I am busy making my goals , I am also looking back on what I have done in ... -
Top 5 Courses to Learn Eclipse IDE for Java Programmers in 2025 - Best of Lot Hello guys, If you are in Java development, you may know that Eclipse is one of the most popular IDEs for Java development and millions of ... -
Top 10 Big Data Tutorials, Books, and Courses for Java Developers in 2025 - Best of Lot Hello Java developers, if you are looking to learn Big Data and Hadoop this year and looking for excellent books, courses, and tutorials to...
Subscribe To
Pages
- Privacy Policy
- Terms & Conditions
Từ khóa » G Xmx
-
Java Memory Limit -Xmx Suffix: Upper Vs Lower Case M/M And G/G
-
How To Control Java Heap Size (memory) Allocation (xmx, Xms)
-
-Xmx Option - IBM
-
-X Command-line Options - Oracle Help Center
-
Guide To The Most Important JVM Parameters - Baeldung
-
Xms And Xmx Java
-
Recommended Heap Size - Azul Platform Prime Documentation
-
Java Heap Space (-Xmx) - OVarFlow's Documentation!
-
Effect Of Dietary Supplementation Of Cetobacterium Somerae XMX-1 ...
-
Ff(xMx)Wx (ƒ G CftG), * G ©), - Project Euclid
-
B/G Ratio For (a) Ti50Pt50-xMx (M=Ru And Cu) (b) Ti50-xMxPt50 (M ...
-
Configuration - Spark 2.4.0 Documentation - Apache Spark
-
Pressure Sensors XM, Pressure Sensor XMP, 6 Bar, G 1/4 Female, 2 ...