Error occurred during initialization of vm initial heap size

Learn about how to fix Initial heap size set to a larger value than the maximum heap size in java.

In this post, we will how to resolve initial heap size set to a larger value than the maximum heap size in java.

Table of Contents

  • Problem: Initial heap size set to a larger value than the maximum heap size
  • Solution 1: Initial heap size set to a larger value than the maximum heap size
  • Solution 2: Change Xms value in vmoptions file for intellij

This error is related to Xmx and Xms parameters in java and these parameters are used to provide heap memory of the JVM.

-Xms: This specifies initial heap size for JVM
-Xmx: This specifies maximum heap memory size for JVM

This simply means JVM will start with mimimum Xms amount of memory and can take up to xmx amount of memory.

Let’s reproduce this error now.

We will take a simple example about how to print arraylist in java.

package org.arpit.java2blog;

import java.util.ArrayList;

public class PrintArrayListMain {

    public static void main(String[] args) {

        ArrayList<String> countryList=new ArrayList<>();

        countryList.add(«India»);

        countryList.add(«China»);

        countryList.add(«Bhutan»);

        System.out.println(countryList);

    }

}

Let’s compile and run the code.

C:UsersArpitDesktopjavaPrograms>javac PrintArrayListMain.java

C:UsersArpitDesktopjavaPrograms>java -Xms1024m -Xmx512m org/arpit/java2blog/PrintArrayListMain
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

As you can see, we got the error Initial heap size set to a larger value than the maximum heap size.

C:UsersArpitDesktopjavaPrograms>java -Xms2g -Xmx1g org/arpit/java2blog/PrintArrayListMain
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

Solution 1: Initial heap size set to a larger value than the maximum heap size

We are getting this error because Xms(minimum heap size) is greater than Xmx(maximum heap size).

Xms should always be lesser than Xmx to run java program correctly.

Let’s change -Xms to 512m and -Xmx to 1024m now.

C:UsersArpitDesktopjavaPrograms>java -Xms512m -Xmx1024m org/arpit/java2blog/PrintArrayListMain
[India, China, Bhutan]

As you can see, error is resolved now and we got expected output.

That’s all about initial heap size set to a larger value than the maximum heap size in java.

Solution 2: Change Xms value in vmoptions file for intellij

If you are getting this error in intellij, then you should check Xms value in vmoptions file.

On windows:
You should be able to find the file on windows at following path:

C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2020.2.3bin

On Mac:
You should be able to find the file on mac at following path:

~/Library/Preferences/IntelliJIdea2019.2/idea64.vmoptions

On linux:
You should be able to find the file on linux at following path:

~/.IntelliJIdea2019.2/config/idea64.vmoptions

You should change version based on your intellij version in above paths.

Check the value of Xms in idea64.vmoptions file and if it is greater than Xmx or not. If it is greater than Xmx, then we should fix it.

Here is content of idea64.exe.vmoptions file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

server

Xms128m

Xmx512m

XX:ReservedCodeCacheSize=240m

XX:+UseConcMarkSweepGC

XX:SoftRefLRUPolicyMSPerMB=50

ea

XX:CICompilerCount=2

Dsun.io.useCanonPrefixCache=false

Djdk.http.auth.tunneling.disabledSchemes=«»

XX:+HeapDumpOnOutOfMemoryError

XX:OmitStackTraceInFastThrow

Djdk.attach.allowAttachSelf=true

Dkotlinx.coroutines.debug=off

Djdk.module.illegalAccess.silent=true

That’s all about how to fix Initial heap size set to a larger value than the maximum heap size in java.

In this short tutorial, I will be sharing how to solve the error «initial heap size set to a larger value than the maximum heap size». I have divided the post into two parts. In the first part, we will produce the error by passing VM/JVM parameters through the command line. In the second part, we will fix the error.

Read Also: Could not reserve enough space for object heap

What is -Xms and -Xmx

-Xms: In java, Xms is the minimum heap size that is allocated at initialization of JVM.
-Xmx: Xmx represents the maximum heap size JVM can use.

1. Producing the Error

Suppose we have below HelloWorld java program:

  public class HelloWorld
       public static void main( String args[] ) {
            System.out.println("Simple Java Program");       
       }
  }

Compile the above HelloWorld java program in command line/terminal:

javac HelloWorld.java

1. Run the above program by passing a single JVM parameter:

Passing -Xms

java -Xms512m HelloWorld

The above command will print the following output:

Simple Java Program

2. Run the HelloWorld program by passing multiple JVM parameters:

Passing -Xms and -Xmx  

java -Xms512m -Xmx1024m HelloWorld

After running the above command, you will get the following output:

Simple Java Program

If the value of Xms(minimum heap size) is greater than the value of Xmx(maximum heap size) than it will produce this error as shown below:

java -Xms2g -Xmx1g HelloWorld

Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

Currently, the value of Xms(minimum heap size) is 2 gigabytes and Xmx(maximum heap size) is 1 gigabyte. 

2. [Fixed] Initial heap size set to a larger value than the maximum heap size

To get rid of this error, the value of Xmx(maximum heap size) should always be greater than or equal to Xms(minimum heap size).

Run the HelloWorld program with the value of Xms(minimum heap size) set to 1 gigabyte and Xmx(maximum heap size) set to 2 gigabytes.

java -Xms1g -Xmx2g HelloWorld

Simple Java Program

That’s all for today, please mention in comments in case you have any questions related to the initial heap size set to a larger value than the maximum heap size error.

This thread was marked as Locked by user-6840779.


  • Search


    • Search all Forums


    • Search this Forum


    • Search this Thread


  • Tools


    • Jump to Forum


  • #1

    May 24, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    I know this is really familiar and old thread to you, but my case is kinda hard for me. I have been reading other peoples problems with this and by reading your solutions, they haven’t helped me yet. And since i can’t find any other help online, this is my last resort.

    My desktop has 16gb of ram, so i’m not supposed to have a lack of ram. But when i try to use -Xmx4024M or above, I get this message:

    Invalid initial heap size: -Xms5024M
    The specified size exceeds the maximum representable size.
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.

    So what i decided to do was lower the -Xms to 4024 or below. That problem seemed to be gone(?). But when I try to run it with 4024M or above, I get this message:

    Desktopserver>java -Xmx1024M -Xms4024M -jar server.jar nogui
    Error occurred during initialization of VM
    Initial heap size set to a larger value than the maximum heap size

    I have read that this was fixed by re-installing 64bit java. But i have re-installed java Twice and i rebooted too. But there was no fix around. After more research i found out about _JAVA_OPTIONS and i tried to exact thing they did, yet it still didn’t work. I have been researching help for over 4 hours. Any help is helpful. Thanks


  • #2

    May 25, 2019


    Tails1


    • View User Profile


    • View Posts


    • Send Message



    View Tails1's Profile

    • Enderdragon Slayer
    • Join Date:

      11/20/2012
    • Posts:

      14,806
    • Member Details

    Remove those java options and post the results after executing the following command in a command prompt: java -version


  • #3

    May 25, 2019

    Once you’re done with the post above and ensured you are indeed running java at 64bit.

    Control Panel > System and Security > System > Advanced System Settings > Environment Variables

    Under «System Variables» their should be a Variable named «_JAVA_OPTIONS» value you can change to what ever you want your max memory usage for a JVM. For example: -xmx8192m under the value column.

    I’m not a programmer by any means and someone might be able to tell you if this is right or wrong. But if you are running this command

    java -Xmx1024M -Xms4024M -jar server.jar nogui

    I can’t see it actually working properly if you don’t have the Java options variable configured. Because this statement is telling the JVM it can start with 4024m of RAM but its max is set at 1024m. So in my understanding even if it booted up it would be capped at 1024m. Not 100% sure though just what I make out of it.


  • #4

    May 25, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    So i got this one:

    C:Windowssystem32>java -version
    java version «1.8.0_211»
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) Client VM (build 25.211-b12, mixed mode, sharing)


  • #5

    May 25, 2019


    FirEmerald


    • View User Profile


    • View Posts


    • Send Message



    View FirEmerald's Profile

    • A Space Odyssey
    • Location:

      The planet Earth… maybe.
    • Join Date:

      6/23/2014
    • Posts:

      2,014
    • Minecraft:

      FirEmerald
    • Member Details

    You are not running 64-bit java. try uninstalling the 32-bit java before installing the 64-bit java, or you can look up online how to change the environment variables to point to 64-bit java.


  • #6

    May 25, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    How can i delete the 32-bit java? Earlier i have tried to delete it manually but it seems that im doing something wrong.

    Last edited by aapo0a: May 25, 2019


  • #7


    May 25, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    Alright so i deleted java manually Again and now i downloaded offline (64bit) version and i still get the same results. Seems i have still haven’t deleted the 32-bit java. So now im getting this:

    C:Windowssystem32>java -version
    java version «1.8.0_211»
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

    edit: What does that mixed mode mean? Does it mean that 32-bit and 64-bit are mixed or something?

    Last edited by aapo0a: May 25, 2019


  • #9

    May 25, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    I deleted every single Java version and file i could find from my computer and i tried installing 64-bit java, but I still get the same

    Desktopserver>java -Xmx1024M -Xms4024M -jar server.jar nogui
    Error occurred during initialization of VM
    Initial heap size set to a larger value than the maximum heap size

    Is it possible that some Java files are hidden or what do i do next?


  • #11

    May 25, 2019


    aapo0a


    • View User Profile


    • View Posts


    • Send Message



    View aapo0a's Profile

    • Out of the Water
    • Join Date:

      5/25/2019
    • Posts:

      7
    • Member Details

    Its the same as above:

    C:Windowssystem32>java -version
    java version «1.8.0_211»
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

  • To post a comment, please login.

Posts Quoted:

Reply

Clear All Quotes


Я в общем-то решил попробовать создать сервер Minecraft. Не собираюсь делать супер-мега проект, однако мне нравится процесс. Сам я не силен в этом, посему решил обратится за помощью на этот форум. Суть проблемы заключается вот в чем: я не могу запустить сервер, ибо какие-то проблемы с памятью в Java, однако я уже неоднократно и выделял память, и переустанавливал саму Java, ничем мне это не помогло. 5f649fa5a1ef3922503473.jpeg

Вот сам текс: Picked up _JAVA_OPTIONS: -Xmx512m
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
Press any key to continue . . .


  • Вопрос задан

    более двух лет назад

  • 387 просмотров

Пригласить эксперта

Раз уж лезете задавать вручную ограничения, то надо и минимум указывать.
-Xms256m -Xmx2048m

256 — начальная.
2048 — всего.

У вас начальную jvm выбирает сама и не может, потому как вы предел сами указали.

И да, 512 это мало. Нужно размер кучи под 4 гб выдавать, т.е. так:
ms512
mx4096


  • Показать ещё
    Загружается…

09 февр. 2023, в 17:37

5000 руб./за проект

09 февр. 2023, в 17:35

50000 руб./за проект

09 февр. 2023, в 17:25

3800 руб./за проект

Минуточку внимания

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

Invalid initial and maximum heap size in JVMAnother 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

Понравилась статья? Поделить с друзьями:
  • Error occurred during initialization of vm could not reserve enough space for 3145728kb object heap
  • Error occurred during initialization of vm could not reserve enough space for 3072000kb object heap
  • Error occurred during initialization of vm could not reserve enough space for 2097152kb object heap
  • Error occurred during initialization of vm could not reserve enough space for 2072576kb object heap
  • Error occurred during initialization of vm could not reserve enough space for 2048000kb object heap