Javac -Xmx to limit VM usage
is there any way to limit maximum virtual memory usage of javac? When running java, I can run it with "-XmxAm" (where A is number of free megabytes) to limit 开发者_C百科it. Is there anything for javac like that? Thanks.
You can give the same runtime options to javac (and most java programs with an own native starter) by using -J
options. By convention, all such options are passed directly to the runtime system. So, in your case, you can invoke
javac -J-Xmx5m -J-Xmx4m <source>
to run javac with very little memory. Of course, as reseter said, it is of limited use this way, since javac may really need some amount of memory to compile. On really big projects, you may want to increase the memory this way, though.
I don't think so. The compiler will need to build a full syntax tree, etc, in order to work, so limiting its memory usage wouldn't be the best of ideas.
For a unix shell, you can use the ulimit command (http://ss64.com/bash/ulimit.html).
bash -c ' ulimit -v 1048576; javac PrettyWoman.java '.
The -v option
is the virtual memory limit to the javac process.
However, it requires a lot of virtual memory, otherwise the following error occurs,
'Error occurred during initialization of VM. Could not reserve enough space for object heap. Could not create the Java virtual machine."
Note: java method - thread.sleep will not be counted in ulimit time limit (real time vs CPU time), so if you are using ulimit along with a java file, the java file can just keep sleeping as it likes.
精彩评论