-Xmx is hurting the usability of Java

DZone 's Guide to

-Xmx is hurting the usability of Java

· Java Zone ·
Free Resource

How would it feel if every time you opened a program or a website it asked you how much memory it could use?

Or even worse it by itself decided some maximum memory value for you which is far lower than the amount of ram on your system. How would you then feel if that said program or website threw an error in your face complaining about memory, all this while you had more than enough ram on your system for it to use?

What Java does

Apparently that is exactly how Java programs behave or rather the JVM implementations compel java programs to behave. 

  1. Either you specify an -Xmx value and try to guess memory usage before hand, or 
  2. Depending on the vendor, version or implementation the JVM will choose its own maximum heap size (which is almost always lower than the total ram on your machine).

What it should Do

Now I am sure there are good technical reasons why this is the case. However I will cite the age old programming quote:

First make it correct, then make it fast.

In this case going Out Of Memory on a system which does have enough memory is plain incorrect. Any program on a system can due to unforeseen circumstances might temporarily require more memory than its user thought it would. It could be that disk IO became slow or there were suddenly a traffic spike for a few minutes, etc. Operating Systems found a way around this a long time ago using virtual memory and disk swapping. Sure swapping causes your program to go slow but it doesn't outright crash it.

I have 24gb of ram on my machine (since ram is super cheap nowdays). I should never see an OutOfMemoryException. Yet time and again I see it pop up in Java programs, even when they were using a mere fraction of my 24 gigs of ram.

Real World Experience

We have so many cases of people using Chronon on 64 bit machines and getting Out Of Memory Exceptions.  We keep getting queries like "but my machine has 4 gigs of ram" and we always have to say "but did you allow the jvm to use it? whats your -Xmx value?". 

Since the performance of Chronon is greatly impacted by memory, with our Time Traveling Debugger Eclipse plugin, during installation we bump up the -Xmx value of Eclipse. Although all this does is allow Eclipse to use the extra memory if needed, due to the common misconception out there, people think just by setting a higher -Xmx value Eclipse is magically using more memory than before.


All said and done, I think the need to specify a max heap or randomly choosing a heap size less than the system memory highly impacts the usability of Java programs in a 64 bit world, and leads to confusion with people who get Out Of Memory errors even though they have plenty of memory. The performance gains are not worth the errors and confusion.


From http://eblog.chrononsystems.com/xmx-is-hurting-the-usability-of-java


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}