4

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.

3
  • 1
    Have you tried a 64bit VM? Commented Aug 20, 2015 at 21:39
  • 1
    Try to use a java x64 version Commented Aug 20, 2015 at 21:39
  • 1
    Java requires a large contiguous area of virtual memory for the heap, which 32 bit Windows struggles with. Commented Aug 20, 2015 at 21:45

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I had no idea that when you are running a 32-bit version of a piece of software that it has to emulate 32-bit windows and then that imparts limitations
@MZimmerman6 it has to do this to ensure maximum compatibility.
3

You should try using a 64 bit Java Runtime. It is probably the case that there is no 985 MB large one-piece memory chunk free within the 32-bit address space of your computer (the 32 bit address space 4GB). When you use a 64 bit Java Runtime, Java can allocate the memory within the 64 bit address space, in which the free memory is much more likely to be available.

It doesn't matter that your JAR file was built using a 32 bit version.

3 Comments

@MZimmerman6 it is the short answer, I have given the longer answer why you really shouldn't be using 32-bit unless you have no choice. Legacy 32-bit DLLs being one reason.
@PeterLawrey See the problem is I do not know if there are any 32-bit things in that .jar file. It does not seem to want to run with 64-bit
What error messages do you get when trying to run the JAR on a 64bit JVM?
2

The answer to your question may lie in the fact that Windows tries and fails to find a contiguous block of memory that is large enough: see http://javarevisited.blogspot.nl/2013/04/what-is-maximum-heap-size-for-32-bit-64-JVM-Java-memory.html. (Though this suggests that other processes are hogging memory, which seems to be contradicted by your last remark.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.