简体   繁体   中英

Invalid initial heap size. Could not create the Java virtual machine

I've faced the next problem: I'm trying to start Tomcat manually via startup.bat, but it seems not to show any results, then I've tried to run shutdown.bat and the console shows next:

 D:\apache-tomcat-7.0.35\bin>startup.bat
Using CATALINA_BASE:   "D:\apache-tomcat-7.0.35"
Using CATALINA_HOME:   "D:\apache-tomcat-7.0.35"
Using CATALINA_TMPDIR: "D:\apache-tomcat-7.0.35\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.6.0_31"
Using CLASSPATH:       "D:\apache-tomcat-7.0.35\bin\bootstrap.jar;D:\apache-tomcat-7.0.35\bin\tomcat-juli.jar"
D:\apache-tomcat-7.0.35\bin>shutdown.bat
Using CATALINA_BASE:   "D:\apache-tomcat-7.0.35"
Using CATALINA_HOME:   "D:\apache-tomcat-7.0.35"
Using CATALINA_TMPDIR: "D:\apache-tomcat-7.0.35\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.6.0_31"
Using CLASSPATH:       "D:\apache-tomcat-7.0.35\bin\bootstrap.jar;D:\apache-tomcat-7.0.35\bin\tomcat-juli.jar"
Invalid initial heap size: -Xms256m -Xmx512m -XX:MaxPermSize=256m
Could not create the Java virtual machine.

catalina.bat is original, also I've checked all pathes and opts(ie JAVA_HOME, JRE_HOME, CATALINA_BASE, CATALINA_HOME, CATALINA_TMPDIR). tomcat version is 7.0.35 java v 1.6

This is your problem Invalid initial heap size: -Xms256m -Xmx512m -XX:MaxPermSize=256m

Some systems ( May be windows JRE) understands Xms and Xmx values given in small letters. here 256m and 512m denotes 256MB and 512MB respectively .

Some machine(JDK 1.7 on Ubuntu ) doesn't understand small m for MB . So when I changed Xms256m -Xmx512m , to => Xms256 M -Xmx512 M , it started working .

PS -> I got this error while installing IntelliJ on Ubuntu 15 ( JDK 1.7) , I edited /bin/idea.vmoptions file of intelliJ and It started working.

Here is a list of error you can get for wrongly setting Xmx and Xms values -

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: 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

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 than JVM assumes the size of -Xms as 1024 bytes only and print error that it's too small for JVM to start

This problem happened to me while trying to run Cassandra.

Uninstalling Java 32-bit and installing Java 64-bit solved this problem for me.

got the correct parameters(JAVA_OPTS) from here . I've set them in setenv.bat.

I got the same error when initializing h2o for deep learning in R. Removed space between the set minimum memory size:

h2o.init(min_mem_size = "10 G") I got error:

Error occurred during initialization of VM Too small initial heap

After removing space between 10 and G it worked:

h2o.init(min_mem_size = "10G")

The problem : You try to initial the minimum and maximum heap size of your application though appears that you're having some syntax issue. You need to set it properly. Pay attention that you minimum and maximum size points are supported related to your machine memory that your application is running.

From Oracle Documentation :

-Xms
The -Xms option sets the initial and minimum Java heap size.
The Java heap (the “heap”) is the part of the memory where blocks of memory
are allocated to objects and freed during garbage collection.

Note:   -Xms does not limit the total amount of memory that the JVM can use.
Format: -Xms<size>[g|G|m|M|k|K]


-Xmx
This option sets the maximum Java heap size.
The Java heap (the “heap”) is the part of the memory where blocks of memory 
are allocated to objects and freed during garbage collection.
Depending upon the kind of operating system you are running,
the maximum value you can set for the Java heap can vary.

Note:   -Xmx does not limit the total amount of memory that the JVM can use.
Operation
Format: -Xmx<size>[g|G|m|M|k|K]

Examples :

On java cli java -Xs:64m -Xmx:1g -jar app.jar

On docker-compose.yml example (different syntax):

version: '3'
services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    user: jenkins
    environment:
      - JAVA_OPTS=-Xms512m -Xmx2048m 
    ports:
      - "0.0.0.0:8080:8080"

And in my case reason was to have -Xms option before -javaagent . Executing it in right order java -javaagent:xxx -Xms256m did the trick.

You may get this issue even after physical memory available in the system. On most 32-bit java version the maximum heap size will range from 1.4G to 1.6G. For more details Please got through on this link

If you have to initialise JVM more than 1.4G to 1.6G of heap memory then you should install 64 bit java version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM