caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>
To: Eray Ozkural <examachine@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Compiling Ocaml sources to c sources
Date: Thu, 16 Sep 2010 13:11:29 +0200	[thread overview]
Message-ID: <AANLkTikhPppf+_6n4o_Jn2psuvx2vfm6avexThCnq4Bw@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikxUs8wLC6aEV77kdH8_5vqHkXz8d-Vhf9hz39L@mail.gmail.com>

You could use Boehm's garbage-collector for such a project, indeed,
that's what is done in Bigloo, to compile Scheme programs to C. Since
Boehm's GC is conservative, it would probably work well in such a
system, with or without compiler optimizations, but the GC itself
would probably be much slower than OCaml's GC on monothreaded code. On
the contrary, OCaml's GC is not conservative, so it really needs to
know what is a pointer to OCaml data, and also to be warned when
pointers to OCaml data are erased (what caml_modify does). If you
leave the C compiler perform all its optimizations, you might end up
with pointers to OCaml data that are not where they should be
(typically, it can duplicate a variable to parallelize some
computations when there are no dependencies between them, and the GC
will only scan one of them). So, you have to limit the C compiler to
only "safe" optimizations from that point of view. By the way, there
are almost no optimizations performed in the Ocaml compiler on
bytecode, most of the interesting ones are only performed in the
native compiler. I think the philosophy behind this choice is that you
want to compile very fast to bytecode (so, no time for optimization),
and only use the native code compiler at the end for efficient code.

--Fabrice

On Thu, Sep 16, 2010 at 12:46 PM, Eray Ozkural <examachine@gmail.com> wrote:
> Yes, I've seen how wired the GC is in the ocaml sources. I had used the
> Boehm GC in a compiler project (not for the generated code but the
> compiler),
> do you mean that one would have to disable most optimizations in the ocaml
> bytecode
> compiler to make such a hypothetical bytecode-to-C compiler work with a C
> GC, or am I missing something crucial? It's great to be able to learn from
> actual
> ocaml compiler writers, BTW, your comments are much appreciated.
> Regards,
> On Thu, Sep 16, 2010 at 12:05 PM, Fabrice Le Fessant
> <fabrice.le_fessant@inria.fr> wrote:
>>
>> The problem is still the same: even if the code is compiled by a C
>> compiler, there is still the need for the garbage collector. If you
>> don't provide your own conservative GC (for which you would have to
>> reimplement all the native functions of OCaml), then you need to use
>> OCaml GC, and you would have to disable most optimizations to be sure
>> that the GC knows where to find live references. At the end, you would
>> get almost no performance improvement, compared to just appending the
>> assembly code for each bytecode instruction (see Piumarta's work in
>> PLDI'98).
>>
>> --Fabrice
>>
>> Eray Ozkural wrote, On 09/16/2010 02:38 AM:
>> > Well, what I would do is to apply a fully optimizing compiler from a
>> > proper hardware abstraction layer, whether it is JIT is irrelevant, but
>> > I do not see why the system would not start doing this as soon as the
>> > code is loaded in some place (and not when it starts to run). What is
>> > certain is that some simple transformation will not speed things up
>> > much.
>>


  reply	other threads:[~2010-09-16 11:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 12:09 Vincent Gripon
2010-09-14 12:16 ` [Caml-list] Compiling Ocaml sources to c sources [NC] Rabih CHAAR
2010-09-14 12:35 ` [Caml-list] Compiling Ocaml sources to c sources David MENTRE
2010-09-15 13:18   ` Vincent Gripon
2010-09-15 19:59     ` Basile Starynkevitch
2010-09-15 22:16       ` Vincent Gripon
2010-09-14 12:43 ` Basile Starynkevitch
2010-09-15 12:59   ` Vincent Gripon
2010-09-15 17:36   ` Jon Harrop
2010-09-15 18:17     ` Eray Ozkural
2010-09-15 20:37       ` Jon Harrop
2010-09-16  0:38         ` Eray Ozkural
2010-09-16  9:05           ` Fabrice Le Fessant
2010-09-16 10:46             ` Eray Ozkural
2010-09-16 11:11               ` Fabrice Le Fessant [this message]
2010-09-14 12:47 ` Thomas Gazagnaire
2010-09-14 12:48   ` Grant Rettke
2010-09-15 13:04   ` Vincent Gripon
2010-09-15 19:57     ` Basile Starynkevitch

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=AANLkTikhPppf+_6n4o_Jn2psuvx2vfm6avexThCnq4Bw@mail.gmail.com \
    --to=fabrice.le_fessant@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=examachine@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;
as well as URLs for NNTP newsgroup(s).