Donnerstag, 21. November 2013

Trouble with Java heap space. Setting -Xmx twice

Since I'm currently working on Eclipse, I'm using Infinitest as a continuous testing solution. But it seems to have trouble with large projects.

I have a project which requires at least 600 MB of heap space. (It's a language processing tool.) Now, infinitest starts with a maximum of 256 MB, as you can see:
Command: [C:\Programme\Java\jre7\bin\java.exe, -mx256m, org.infinitest.testrunner.TestRunnerProcess, org.infinitest.testrunner.JUnit4Runner, 6155]
Most of my tests fail with an "OutOfMemoryError (Java heap space)", which is not surprising. I tried setting my own limits in infinitest.args, but that resulted in an illegal configuration.
Command: [C:\Programme\Java\jre7\bin\java.exe, -mx256m, -Xms680m, org.infinitest.testrunner.TestRunnerProcess, org.infinitest.testrunner.JUnit4Runner, 6838]
What do I do now?

This took me a while to figure out: It turns out you can reset the memory settings if you simply restate them later in the command line. I didn't find this info anywhere else on the net, but right now it seems like you can set any of those memory settings as often as you like, as long as minimum (ms) and maximum (mx) heap size don't contradict each other.

If you modify the memory settings in infinitest.args, you need to set the maximum heap space as well. I fixed my problem by setting the maximum heap space -Xmx710m. Setting that option twice actually works and resets infinitest's default arguments.
Command: [C:\Programme\Java\jre7\bin\java.exe, -mx256m, -Xmx710m, org.infinitest.testrunner.TestRunnerProcess, org.infinitest.testrunner.JUnit4Runner, 7007]