Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JVM Heap Size

Tags:

java

memory

jvm

I have an application that on launch requests a specific amount of RAM using the following command.

java -Xms512m -Xmx985m -jar someJarfile.jar

This command fails to run on my computer with 8.0GB of RAM because it can not create an object heap of the specified size. If I lower the max range to something below 700MB it works fine.

What is even stranger is that even doing a simple java -Xmx768m -version fails when the -Xmx flag value exceeds 700m. I am trying to run it with Java 1.7Uu67 32-bit(that is what the jar was built with) and even newer versions of Java 1.7 and event Java 1.8. I would understand if the max heap was higher and I was using 32bit, but it is not above the ~1.4GB cap of 32-bit java

Is there a configuration parameter that I am missing somewhere that would be causing this, some sort of software that may be interfering? It does not make sense to me as to why I can not allocate 700MB of RAM on a machine with 8.0GB of RAM. I

I should also note that there are no other processes running that are taking up all of my RAM. It is a fresh install of Windows 7.

like image 399
MZimmerman6 Avatar asked Jan 07 '23 17:01

MZimmerman6


1 Answers

While 700 MB is pretty low, it is not surprising.

The 32-bit Windows XP emulator in Windows works the same way as Windows XP with all it's limitations. It means you lose 2 GB or a potential 4 GB to the OS. This means programs already running use up virtual memory space. Also if your program uses shared libraries or off heap storage like direct memory and memory mapped files this will means you lose virtual memory for the heap. Effectively you are limited to 1.4 GB of virtual memory for your applications no matter how much memory you actually have.

The simple way around this it to use the 64-bit JVM which runs in your 64-bit OS and is also limited but instead to 192 TB of virtual memory on Windows.

like image 143
Peter Lawrey Avatar answered Jan 12 '23 07:01

Peter Lawrey