The ocamljava compiler is quite conservative in order to compile and link programs in such a way that they can be used in very different settings. As an example, it is perfectly safe to have several ocamljava-compiled programs executing in the very same JVM, which can be useful when compiling to applets or servlets. However, this comes at a price, and the ocamljar tool allows to get rid of costly indirections when the user knows for example that there will be only one ocamljava-compiled program in the JVM.

The developer could specify optimization directives to the ocamljava compiler, but it would imply to recompile many files (including those from the standard library, and even from the runtime support). This explains why it has been decided to apply such optimization on linked programs.

The optimizer is invoked through a command line such as the following one:

ocamljar <options> input-file.jar output-file.jar
where possible options are:
command-line switchdefault valuemeaning
-no-backtrace <bool>truewhether to assume absence of backtrace use
-no-debug <bool>truewhether to remove debug statements
-no-dynlink <bool>truewhether to assume absence of dynamic linking
-no-runtime-lock <bool>truewhether to remove support for runtime lock
-no-signals <bool>truewhether to remove support for signals
-no-unused-global <bool>truewhether to remove remove initialization of unused globals
-one-context <bool>truewhether to assume unique context (meaning that there should be only one OCaml-Java program executing in the JVM)
-unsafe <bool>falsewhether to use unsafe containers (allowing to avoid array bound checks performed by the JVM for container classes representing OCaml values)

Warning! when using the unsafe containers, it is necessary to run the code with enhanced privileges, through java -Xbootclasspath/p:output-file.jar pack.ocamljavaMain (where the default pack may have been changed by using the -java-package command-line switch from ocamljava at link time).