What is sjavac, who is it for and how do I use it?
What exactly is the sjavac tool?
The sjavac
tool is an (allegedly smart) wrapper around javac
, developed at Oracle and intended to provide the following features:
- incremental compiles - recompile only what's necessary
- parallel compilation - utilize more than one core during compilation
- keep compiler in a hot VM - reuse a JIT'ed javac instance for consecutive invocations
When recompiling a set of source files, javac looks at the timestamps of the .java and .class files to determine what to keep and what to recompile. This is incredibly crude and can be devastating for large code bases. In addition to the timestamps sjavac inspects the public API of the dependencies to judge which files need to be recompiled.
Sjavac also attempts to split up the compilation into multiple invocations of javac. In other words, it brings a high level of parallelism to the build process.
Finally, the sjavac tool is split in a client part and a server part which allows you to leave sjavac running in the background, JIT'ed and ready for use in consecutive calls.
Who is it intended for?
People who are working on large projects and frequently recompiles the code base during development are encouraged to try out sjavac
. (Be aware however that the tool is currently under development and there are still open issues.)
How do I use it?
The tool is not yet shipped with the OpenJDK, so you'll have to get it from the OpenJDK jdk9/dev repository. Also, there is no launcher in place yet, so you invoke it with java com.sun.tools.sjavac.Main
.