0

I have a Java program which creates 4 empty byte arrays of MAX_INTEGER - 2 length and then halts on an infinite while loop in the main method.

I have set my Windows Java settings to include params -Xms12g -Xms12g (I have 16gb RAM). Java settings

When running the program in Netbeans IDE with the same params set for the VM, the program executes and I can see in Task Manager that ~8g RAM is being used which is about what I'd expect. Task manager Java

I have compiled the program into a standalone .jar file so that I can run it outside from Powershell but when attempting to run the line: java -jar prog.jar -Xms12g -Xmx12g I am being told I am exceeding the heap space somehow, but I've just seen this not to be the case through an IDE: Powershell error

-XX:MaxPermSize=12g seems to make no difference either, and the IDE's VM doesn't require this param.

What am I missing here?

-

Entire sourcecode for completeness:

package prog;

public class Prog
{
    public static final byte[] arr1 = new byte[Integer.MAX_VALUE - 2];
    public static final byte[] arr2 = new byte[Integer.MAX_VALUE - 2];
    public static final byte[] arr3 = new byte[Integer.MAX_VALUE - 2];
    public static final byte[] arr4 = new byte[Integer.MAX_VALUE - 2];

    public static void main(String[] args)
    {
        while(true);
    }
}
Rogod
  • 188
  • 1
  • 13

1 Answers1

0

So it turns out, the command I needed was:

java -jar -Xmx12g -Xms12g prog.jar

not:

java -jar prog.jar -Xmx12g -Xms12g

as I'd always thought.

I had not realised the first parameters were for the JVM and the 2nd set (after the .jar) were for the .jar

Rogod
  • 188
  • 1
  • 13