Features Download
From: Alan Schmitt <alan.schmitt-o/5/jSaJEHk+NdeTPqioyti2O/JbrIOy <at> public.gmane.org>
Subject: Attn: Development Editor, Latest Caml Weekly News
Newsgroups: gmane.comp.lang.ocaml.weekly-news
Date: Tuesday 23rd November 2010 09:17:37 UTC (over 6 years ago)

Here is the latest Caml Weekly News, for the week of November 16 to 23,

1) SMP multithreading
2) ledit release 2.02
3) Looking for stubs for sendmsg/recvmsg
4) OCamlJit 2.0
5) Other Caml News

1) SMP multithreading
Archive: <http://groups.google.com/group/fa.caml/browse_thread/thread/8652e1563fcfdc01#>
** In this very long thread, Wolfgang Draxinger asked and Sylvain Le Gall

> So, what're the developments regarding SMP multithreading OCaml?

There are various development regarding this subject (most recent
- Plasma (MapReduce in OCaml)
- OC4MC (OCaml for MultiCore)
- ocamlp3l
- jocaml 
- ocamlmpi

All these projects try to tackle the challenge of SMP from different
point of view. Maybe you'll find what your answer in one of them.
2) ledit release 2.02
Archive: <http://groups.google.com/group/fa.caml/browse_thread/thread/a3f3d9ee6deb7344#>
** Daniel de Rauglaudre announced:

New release of "ledit" : 2.02.

    Ledit is a line editor to be used before an interactive command,
    allowing you to edit input lines (cut, paste, move cursor forward
    and backward and in history, balance parentheses and so on).
       $ ledit ocaml
       $ ledit ocamldebug
       $ ledit ed
   and so on...

New feature : TAB for 'complete-file-name'

When you type 'tab', ledit tries to complete what is before the cursor
considered as a path, and displays the possible files if there are
several of them, just like common shells do.

Useful when you have forgotten the file name you want to specify.
3) Looking for stubs for sendmsg/recvmsg
Archive: <http://groups.google.com/group/fa.caml/browse_thread/thread/437242c094e335c3#>
** Goswin von Brederlow asked and Jérémie Dimino replied:

> I'm looking for stubs for
>        ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
>        ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
> Specifically I need those to send (among normal messages) an
> Unix.file_descr over a Unix Domain Socket.
> Does anyone know of a module that has them?

The Lwt_unix module has them [1].


  [1] <http://ocsigen.org/lwt/doc/api/Lwt_unix.html#VALrecv_msg>
** Dave Scott also replied:

We have some bindings for those:


external send_fd : Unix.file_descr -> string -> int -> int -> Unix.msg_flag
list -> Unix.file_descr -> int = "stub_unix_send_fd_bytecode"
external recv_fd : Unix.file_descr -> string -> int -> int -> Unix.msg_flag
list -> int * Unix.sockaddr * Unix.file_descr = "stub_unix_recv_fd"

You might prefer to extract the relevant functions from the code -- there's
lot of other misc stuff in that repo which you're probably not interested

We use those functions quite a lot so hopefully they'll work for you.
4) OCamlJit 2.0
Archive: <http://groups.google.com/group/fa.caml/browse_thread/thread/a8b3d15a3cba60f0#>
** Benedikt Meurer announced:

OCamlJit 2.0 is a new Just-In-Time engine for Objective Caml 3.12.0 on
processors (x86/x86-64). It translates the OCaml byte-code used by the
interpreter (ocamlrun and ocaml) to x86/x86-64 native code on-demand and
the generated native code instead of interpreting the byte-code. It is
designed to run with minimal compilation overhead (translating only what is
being executed, avoiding costly code generation and optimization
while being 100% compatible with the byte-code runtime (including
serialization and hashing of closures, etc.).

OCamlJit 2.0 was specifically designed for desktop processors and is not
really portable to anything else in its current shape, because the target
audience are people using the interactive top-level and the byte-code
interpreter for rapid prototyping/development (which is unlikely to happen
anything else but x86/x86-64). The implementation currently requires a
that adheres to the SysV ABI, which includes Linux, BSD, OS X, but excludes
Win32/Win64 (patches/ideas are welcome). It was tested on Linux/x86
Linux/amd64 (CentOS) and Mac OS X 10.6 (64bit). The x86 implementation
requires SSE2 capable processors (otherwise it falls back to the byte-code
interpreter), so it won't speedup your OCaml programs running on 486 CPUs.

OCamlJit 2.0 runs most benchmarks at 2-6 times faster than the byte-code
interpreter. The interactive top-level benefits twice when used with the
engine: (a) the compiler stages are JIT compiled and (b) the generated
byte-code is JIT compiled. A tech report describing a slightly earlier
prototype and including performance measures of OCamlJit 2.0 on Mac OS X
(64bit) is available at:


The source code is available from the Git repository (master branch) at:


Installation is similar to installation of Objective Caml, just run

./configure -prefix /path/to/ocamljit2 [options]

followed by

make world opt
make install

This will install a fully working Objective Caml 3.12.0 to
where /path/to/ocamljit2/bin/ocamlrun and
/path/to/ocamljit2/lib/libcamlrun_shared.so include the JIT engine in
to the byte-code interpreter (fallback to the byte-code interpreter is
necessary for debugging with ocamldebug). The configure script prints a
indicating whether the JIT engine is enabled or not (if not, it'll be just
regular OCaml 3.12 installation).

Comments are welcome.
** bluestorm asked and Benedikt Meurer replied:

> To those of you who are lazy but still curious, I just read the report,
> here are the answers to the question I had:

Thanks for posting these points, should have done this in my original

> 1. Is that project related to Basile Starynkevitch's venerable OCamlJIT ?
> Yes, OcamlJIT was apparently a major inspiration for this work. The
> design is similar, and in particular the objective of absolute
> with the existing bytecode (even when it may hurts performances) was
> Unfortunately, due to bitrotting and different architectures (OcamlJIT
x86 vs.
> OcamlJIT2 x86_64), there is no direct performance comparison, though the
> reports seems to indicate similar to better performances. Several points
> also improved (better (but still suboptimal) register usage, clever hacks
> speed up mapping between bytecode and native code adresses...).

With the x86 port being close to complete, direct comparison with OcamlJIT
will be possible (dunno if OcamlJIT will work with 3.12 tho). I'll do
appropriate comparisons once everything is in place.

> 2. Does it use LLVM ?
> No, it doesn't, but it's justified. Apparently, an early prototype showed
> LLVM compilation/generation overhead was too high. A (debatable) design
> of OcamlJIT2.0 is to be absolutely faster than ocamlrun, even on *very*
> short-running programs (`ocamlc -help`).

This is indeed debatable, atleast for "ocamlc -help". But this was not the
main concern with LLVM. LLVM overhead is acceptable for long running
computations, but everything else is slowed down noticably. It should also
noted that my LLVM prototype was rather quick&dirty, so it may indeed be
possible to get a LLVM based JIT which is on par with the byte-code
interpreter for common applications. But why would one want to do this?
running computations can be speed up very well using ocamlopt (no need to
perform them using the interactive top-level).

> OCamlJIT2.0 uses its own macro to generate x86_64 assembly directly
> (apparently using a dedicated library wasn't worth it). A drawback of
> strategy is its inherent non-portability.

It used AsmJit before, which is also limited to x86/x86-64; the
non-portability is actually a design decision (as explained in my original
post, portability to non-desktop machines was not a goal for the current
** Alain Frisch suggested:

This looks like a very interesting project!

Does performance really matter that much for rapid prototyping/development?
can imagine other uses of the toplevel where performance matters more, like
theorem provers embedded in the OCaml toplevel.

Anyway, another option to get a more efficient interactive top-level is to
turn to native code.

There is actually already a native top-level in the distribution, even
it is undocumented and unmaintained. You can build it with the "make
target. The implementation is based on the same approach as native dynlink.
The toplevel embeds the native compiler; for each phrase, the toplevel
produces assembly code, calls the assembler and the linker to produce a
dynamic/shared library, and then dynamically load and execute the resulting
code. This gives some latency, but it's not so bad in practice, and you get
the full speed of native code.

A further step to improve this native toplevel is to avoid the call to the
external assembler and linker. To do that, one basically needs to replace
assembly code emitters (emit.mlp/emit_nt.mlp) with native code emitters and
the relocation/dynamic loading by hand, which is quite easy.

As it turns out, LexiFi uses on a daily basis such direct binary code
for x86/amd64 on Windows, and that would be easy to port to other x86/amd64
platforms. The x86 version was developed internally, and the amd64 version
done by Fabrice Le Fessant. There is also some code to wrap the binary code
into COFF objects (and flexdll has a stand-alone mode to produce .cmxs
without an external linker), but that would be useless for a native
The goal was to have a compiler which can be more easily embedded in our
applications and deployed to our customers, without depending on any

If you Benedikt, or someone else, is willing to work on a native top-level
without the need to call an external assembler/linker, we are ready to
the binary code emitters from our code base and share them with the
(with an open-source license to be determined). This requires some
work on our side, so we're going to do it only if there is interest in the

(Another nice side project, for having a good native toplevel, would be to
extend ocamlopt with some control over the trade-off between speed of code
generation, and the performance of the generated code. One way to do it is
force the interference graph to remain not too big, by spilling early, in
order to avoid quadratic behavior in the register allocator.)
5) Other Caml News
** From the ocamlcore planet blog:

Thanks to Alp Mestan, we now include in the Caml Weekly News the links to
recent posts from the ocamlcore planet blog at <http://planet.ocamlcore.org/>.

RegSTAB 1.4.6 released:

ledit 2.02:

OCamlODE 0.6:

Idea for OCaml browser extension:
Old cwn

If you happen to miss a CWN, you can send me a message
([email protected]) and I'll
mail it to you, or go take a look at
the archive (<http://alan.petitepomme.net/cwn/>)
or the RSS feed of the
archives (<http://alan.petitepomme.net/cwn/cwn.rss>).
If you also wish
to receive it every week by mail, you may subscribe online at

CD: 42ms