caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile.starynkevitch@inria.fr>
To: Brian Hurt <bhurt@spnz.org>, caml-list@inria.fr
Subject: Re: [Caml-list] Real Time Ocaml
Date: Fri, 16 Apr 2004 09:55:43 +0200	[thread overview]
Message-ID: <20040416075542.GA1500@bourg.inria.fr> (raw)
In-Reply-To: <Pine.LNX.4.44.0404151342490.6919-100000@localhost.localdomain>

On Thu, Apr 15, 2004 at 01:44:36PM -0500, Brian Hurt wrote:
> On Wed, 14 Apr 2004, Kenneth Knowles wrote:
> 
> > On Wed, Apr 14, 2004 at 07:07:39PM +0200, Basile STARYNKEVITCH wrote:
> > >    I am coding is an experimental,
> > >    unsopported, JIT version of it - see my home page at INRIA on
> > >    http://cristal.inria.fr/~bstarynk 
> > 
> > The correct URL appears to be http://cristal.inria.fr/~starynke/

Yes, sorry for the typo.


> Question: are you guys experiencing any problems with the cost of 
> allocation?  I can't get a straight answer from the Java people- many 
> experienced Java programmers still claim that allocation is highly 
> expensive and avoid if it all possible, while others claim allocation is 
> cheap (like in Ocaml).

Allocation in Java is more expensive than in Ocaml, partly because the
Java VM should be able to run concurrently several threads which
"simultanously" allocate Java objects (and more generally because of
all the synchronisation issues, and the rather heavy object model in
Java).

Allocation in Ocaml (in particular when you do not use Ocaml objects)
is very quick because it justs allocate some (usually small) memory
chunk; in the common case, it justs increment a pointer. For example
the MAKEBLOCK2 bytecode is interpreted as below (this is a CPP
expansion of ocaml/byterun/interp.c)

{
    tag_t tag = *pc++;
    value block;
      caml_young_ptr -= (((((2) + 1)) * sizeof (value)));     /*1*/
      if (caml_young_ptr < caml_young_limit) { /* 2 */
        caml_young_ptr += (((((2) + 1)) * sizeof (value))); {
          sp -= 2;
          sp[0] = accu;
          sp[1] = env;
          caml_extern_sp = sp;
        };
        caml_minor_collection (); {
          accu = sp[0];
          env = sp[1];
          sp += 2;
        };
        caml_young_ptr -= (((((2) + 1)) * sizeof (value)));
      }
      (*((header_t *) (caml_young_ptr))) = /*3*/
        (((header_t)
          (((header_t) ((2)) << 10) + ((3 << 8)) + (tag_t) ((tag)))));
      (block) = ((value) (((header_t *) (caml_young_ptr)) + 1));;
    (((value *) (block))[0]) = accu; /* 4 */
    (((value *) (block))[1]) = sp[0];
    sp += 1;
    accu = block;
    goto *(void *) (((char *) 0) + *pc++);
  }

In the usual case, the caml_young_ptr < caml_young_limit test fails,
and what is happenning is a decrement of caml_young_ptr (at 1), a
failed compare (at 2), and the filling of the header (at 3) and of the
two tuple values (at 4)


Regarding the original "real-time Ocaml" thread, I still did not
understood what are exactly the real-time needs of the original poster
(I guess he just wants to code a sophisticated Web server), and I
suspect that they are not really hard real-time, and that running the
actual Ocaml runtime system, with some good configuration of the Gc
(ie using the Gc module, see
http://caml.inria.fr/ocaml/htmlman/libref/Gc.html in particular the
Gc.set function) is really enough.

I do not think that re-coding the Ocaml runtime system for hard
real-time performance is really realistic (it is doable, but it is a
big task, requiring significant expertise), and I suspect that the
resulting system would be slower than today's Ocaml, and will perform
worse. Real-time garbage collection is tricky and costly (perhaps even
needing some kind of read barrier). If you recode the Ocaml GC, you
either have to recode the bytecode interpreter or heavily change some
tricky parts of the ocamlopt native code generator.

Regards

-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - Inria Rocquencourt
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-04-16  7:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-14 16:12 Erol Akarsu
2004-04-14 17:07 ` Basile STARYNKEVITCH
2004-04-15  6:51   ` Kenneth Knowles
2004-04-15 18:44     ` Brian Hurt
2004-04-16  7:55       ` Basile Starynkevitch [this message]
2004-04-16 12:33         ` Erol Akarsu
2004-04-16 15:12           ` skaller
2004-04-20  0:20         ` Brian Hurt
2004-04-20  0:31           ` Karl Zilles
2004-04-20  1:50             ` skaller
2004-04-14 18:21 ` Jon Harrop
2004-04-15  8:17 ` Hendrik Tews
2004-04-15 22:33   ` Erol Akarsu
2004-04-20  8:04     ` Hendrik Tews
2004-04-20 13:44       ` Eric Dahlman

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=20040416075542.GA1500@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=bhurt@spnz.org \
    --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).