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 the possible options are:
|command-line switch||default value||meaning|
||whether to assume absence of backtrace use|
||whether to remove debug statements|
||whether to assume absence of dynamic linking|
||whether to remove support for runtime lock|
||whether to remove support for signals|
||whether to remove remove initialization of unused globals|
||whether to assume unique context (note 1)|
||whether to use unsafe containers (note 2)|
note 1: meaning that there should be only one OCaml-Java program executing in the JVM
note 2: 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 of ocamljava at link time).