OCaml-Java: optimizer


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
-no-backtrace bool true whether to assume absence of backtrace use
-no-debug bool true whether to remove debug statements
-no-dynlink bool true whether to assume absence of dynamic linking
-no-runtime-lock bool true whether to remove support for runtime lock
-no-signals bool true whether to remove support for signals
-no-unused-global bool true whether to remove remove initialization of unused globals
-one-context bool true whether to assume unique context (note 1)
-unsafe bool false 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