I wonder if one of you knows the answer to the below.
When you start a JVM, you can specify the maximum amount of memory it will use (i.e. that will be available to the application it will run). On Win32 systems, this amount of memory has to be in a single block. In other words, the JVM will use an amount of memory less than or equal to the value you specify at startup.
Is there any way to find-out what this value actually is?
Does anybody know if there are Java libraries that can defrag the system memory? I need the maximum I can get so I would like to defrag the RAM before launching my application. I plan to use a seperate JVM to do that so my launch sequence will look something like the below.
1) Start small JVM + App to defrag RAM and report the amount available
2) Launch big JVM + Main App
Any comments are much appreciated.
To find out how much memory is available to your application, use
public long Runtime.getRuntime().totalMemory()
Like you said, JVM only gets access to the block of memory it had been handed by the OS. It would therefore very much surprise me if the OS allowed you to defragment the RAM (that would require the JVM to have access to ALL RAM, wouldnt it). You'd have to use some native utility.