From: Basile STARYNKEVITCH <basile@starynkevitch.net>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocaml, llvm and generating code at runtime
Date: Fri, 01 Jan 2010 18:39:15 +0100 [thread overview]
Message-ID: <4B3E3343.2060809@starynkevitch.net> (raw)
In-Reply-To: <405ED4B9-9B3C-4BAA-9C79-C18BB8FDDB4D@gmail.com>
Joel Reymont wrote:
> Does anybody have example code that shows how to generate OCaml bindings at runtime with LLVM?
>
> My goal is to compile an AST into code that uses OCaml functions within the same binary that's doing the compiling.
>
> I don't think it can be done with OCaml since it requires a standalone assembler, linker, etc.
You could generate some (Ocaml) source code, compile it (using ocamlopt -shared), and then dynamically load the just
generated shared module using Dynlink.loadfile. IIRC, the "experimental" ocamlnat binary did that.
> Correct me if I'm wrong, though. Mine is a web-based compiler with potentially many concurrent sessions. Running gas,
ld, etc. seems a much heavier and less scalable approach that generating code at runtime.
Indeed, forking an ocamlopt & then loading the shared module is more heavy, and you have a slight latency issue: if the
generated code is not big (i.e. less than a thousand lines of Ocaml code), it could take a few seconds (or tenths of
seconds).
LLVM is rumored to be a bit faster, but is also rumored to be slow as a pure JIT (just in time) code generated (w.r.t.
to other non Ocaml implementations - eg SBCL or CLISP common lisp). Polyml http://polyml.org/ is also supposed to be a
JIT-ed SML implementation (it is SML not Ocaml). A few years ago, metaocaml existed, but seems dead today.
However, inside a web server, you also have another issue: garbage collection (or simply disposal) of generated code.
And this happens even with LLVM. You probably should dispose explicitly & manually of session data and generated code.
Ten years ago, SML/NJ was supposed to also garbage-collect code. Ocaml don't do that, and today's Ocaml Dynlink module
don't have any unloading code (it would be unsafe).
A possible work-around could be to restart your web compiling server once in a while (e.g. twice a day).
Happy new year to everyone!
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
next prev parent reply other threads:[~2010-01-01 17:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-01 16:45 Joel Reymont
2010-01-01 17:39 ` Basile STARYNKEVITCH [this message]
2010-01-01 19:08 ` [Caml-list] " Jon Harrop
2010-01-01 20:23 ` Basile STARYNKEVITCH
2010-01-01 22:29 ` Jon Harrop
2010-01-01 22:33 ` Yoann Padioleau
2010-01-02 0:06 ` Jon Harrop
2010-01-01 19:31 ` Jon Harrop
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=4B3E3343.2060809@starynkevitch.net \
--to=basile@starynkevitch.net \
--cc=caml-list@yquem.inria.fr \
--cc=joelr1@gmail.com \
/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