caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "forum@x9c.fr" <forum@x9c.fr>
To: caml users <caml-list@inria.fr>
Cc: forum@x9c.fr
Subject: Re: [Caml-list] [ANN] OCaml-Java project: 1.4 release
Date: Wed, 12 May 2010 07:51:35 +0200	[thread overview]
Message-ID: <22B48086-35DF-433A-A5FE-5A2E809ADB2C@x9c.fr> (raw)
In-Reply-To: <AEE09054-E05B-406D-A547-F0561A639454@gmail.com>


Le 11 mai 2010 à 21:23, Warren Harris a écrit :

> I'm curious whether there are any notes / pointers regarding the completeness of the ocaml-java implementation (couldn't find this on the web site). I'm wondering about the feasibility of using it for a moderately large ocaml project I've been working on which uses Lwt to perform async I/O. I assume that for this to work with ocaml-java, the lowest levels of Lwt would need to be adapted to use NIO or threads in order to run on a JVM. Also my application is written in a pure functional style, and relies heavily on closures, currying, recursion and the ability for the compiler to do tail call optimization. I'm concerned that this will not translate well to Java.

Here is some information about the OCaml-Java project
(both current 1.4 release and future 2.0 release).

Regarding compatibility with the original implementation of OCaml:
  - ocamljava is able to compile working versions of ocamlc, ocamllex, menhir and itself,
    giving some confidence in its language-compatibility level;
  - all the libraries bundled with the original implementation have been translated and
    tested through some unit testing (but thread libraries tests are only lightweight, labltk
    support is based on the swank project [1], and unix is only partially supported);
  - document [2] gives per-primitive compatibility information;
  - the last page of [3] lists the differences between ocamlc/ocamlopt and ocamljava compilers;
  - third-party libraries (such as Lwt) should be supported out-of-the-box as long as they do
    neither rely on exotic features (remember: "Obj.magic is not part of the OCaml language"),
    nor on C code (unless you can translate it to Java code).

Regarding performances in current version:
  - closures are based upon Java reflection (will be based upon JDK 7's method handles,
    avoiding access checks on each call);
  - only "explicit self" tail calls are optimized ("self" meaning same function, and "explicit"
    meaning "not through a closure");
  - performances are terrible and memory consumption is excessive.
Bottom line: the current version should be regarded as a proof-of-concept.

However, I have spent recent vacation on the upcoming 2.0 version, with some positive
results. The runtime has been partially rewritten, reducing memory consumption and
increasing performances. The Java equivalent of "ocamlrun" is now within an order of
magnitude from the original tool on all tested programs, and only about 4 times slower on some
(e. g. "nbody" from the language shootout [4]). This seems to indicate that -when updated-
the ocamljava compiler should be able to at least match ocamlc performances.
Notice that is a conservative statement / objective if you consider that Scala is on par with
ocamlopt on some benchmarks (but the Scala language has been designed from the bottom
up to be run on the JVM).

A final word about tail call optimization. As previously said, only "explicit self" calls are
optimized (as far as I know, this is also true for mature compilers like Scala or Clojure).
This will not change in future versions, unless Sun / Oracle adds support for tail calls in the JVM [5] [6].
I know that some people will regard a compiler for a functional language with no general
tail call optimization as "broken", but it is clear that OCaml-Java will not perform program
transformations (such as trampolining) to enable tail call optimization in every cases.
My understanding may be incorrect, but it seems that such transformations result in obfuscated
code (hindering HotSpot JIT compilation) and unpredictable performances.


Some points above may need to be elaborated, but this very message is already quite long...
Anyway, feel free to ask for further information.

Regards,

Xavier Clerc

[1] http://www.onemoonscientific.com/swank/summary.html
[2] http://cadmium.x9c.fr/distrib/cadmium-compatibility.pdf
[3] http://cafesterol.x9c.fr/distrib/cafesterol.pdf
[4] http://shootout.alioth.debian.org/
[5] http://openjdk.java.net/projects/mlvm/subprojects.html#TailCalls
[6] http://wikis.sun.com/display/mlvm/TailCalls

      reply	other threads:[~2010-05-12  5:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-06 20:10 forum
2010-05-11 19:23 ` [Caml-list] " Warren Harris
2010-05-12  5:51   ` forum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22B48086-35DF-433A-A5FE-5A2E809ADB2C@x9c.fr \
    --to=forum@x9c.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).