Reputation: 499
I'm performing a huge calculation and I'm getting a "out of heap space" error. What I'm wondering is if Java does paging automatically, so that maybe my hard drive space can be used when performing this calculation? If it doesn't do it automatically, how do I turn this option on?
Upvotes: 13
Views: 16975
Reputation: 28386
The virtual memory manager of the operating system, not the Java Virtual Machine (JVM), decides when to eject memory pages and write them to the hard disk.
As earlier answers have mentioned, the JVM stores the heap space entirely in resident memory and most JVM implementations allow the user to specify the maximum heap space. For example, the OpenJDK allows you to set the maximum heap size using the -Xmx<size>
option. Run java -X
to see this and other non-standard OpenJDK command-line options.
Upvotes: 4
Reputation: 359816
The Java heap lives in RAM (ignoring virtual memory :). You can change the default initial heap size and maximum heap size with the -Xms
and -Xmx
VM args, respectively.
The old generation, default heap size can be overridden by using the -Xms and -Xmx switches to specify the initial and maximum sizes respectively:
java -Xms <initial size> -Xmx <maximum size> program
For example:
java -Xms128m -Xmx512m application
How much RAM does your machine have? Just what sort of a calculation is this that you think you need more heap than that?
Upvotes: 15
Reputation: 120516
It's determined by the operating system and by special flags.
$ java -X
...
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
...
Upvotes: 0
Reputation: 1500515
The size of the heap can determined however the JVM wants to. For most, it's via the -Xmx command line argument, with varying defaults. Chances are you want something like:
java -Xmx2048M foo.bar.MyProgram
Upvotes: 2