Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 it. Is there anything for javac like that? Thanks.

like image 208
Garret Raziel Avatar asked Mar 05 '11 11:03

Garret Raziel


People also ask

What does javac command do?

Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.

What is the difference between Java and javac?

Technically, javac is the program that translates Java code into bytecode (. class file) - an intermediate format which is understandable by the Java Virtual Machine (JVM). And java is the program that starts the JVM, which in turn, loads the . class file, verifies the bytecode and executes it.

What is Java Sourcepath?

If you set the -sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files.

What is javac source and target?

You use the -source option to specify the java version used for compilation and you use the -target option to specify the lowest java version to support. eg. If I specify a target of 1.4, then my program will not be able to run on java 1.3 or lower. see the following javac documentation for more info.


2 Answers

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.

like image 76
Paŭlo Ebermann Avatar answered Oct 20 '22 07:10

Paŭlo Ebermann


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.

like image 33
mbatchkarov Avatar answered Oct 20 '22 07:10

mbatchkarov