caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@pobox.com
To: Xavier.Leroy@inria.fr
Cc: caml-list@inria.fr
Subject: out-of-heap data structures
Date: Wed, 27 Sep 2006 21:15:22 -0700 (PDT)	[thread overview]
Message-ID: <20060928041522.CBC0EAC04@Adric.metnet.fnmoc.navy.mil> (raw)


Xavier Leroy wrote:
> There is one caveat: ad-hoc polymorphic primitives (structural
> equality and comparisons, marshaling, hashing) will not work on data
> structures that reside outside of the Caml heap.  The reason is that
> these primitives treat out-of-heap pointers as opaque data.  There is
> a special case (the "Is_atom" test) for pointers that correspond to
> ocamlopt-generated static data, but extending this special case is
> nonobvious.

Actually, MetaOCaml has done such an extension. The extension is
general purpose and backward compatible. Furthermore, no base OCaml
sources were harmed in the process: there is no need to recompile
ocamlopt or the standard library. The linking of the final executable
does require a few extra flags.


The Is_atom test in the ocamlopt-produced executables checks if the
address of the tested value falls within the data segment of the
executable. Alas, if we permit dynamic loading of ocaml-opt compiled
code, static data no longer reside in one segment (within one
continuous range of virtual addresses). Therefore, modifications are
necessary.

Native MetaOCaml (or, to be precise, the dynamic linking part of it)
has carried out such modifications. The Is_atom test now reads

CAMLextern struct DYNlimits caml_static_data_limits; /* in new ndl.c */
#define Is_atom(v) \
  ((((char *)(v) >= caml_static_data_start \
     && (char *)(v) < caml_static_data_end) \
    || ((v) >= Atom(0) && (v) <= Atom(255))\
    || (caml_static_data_limits.used != 0 && \
	within_DYNlimitsP((void *)v,&caml_static_data_limits))))

The change is fully backward-compatible: if no dynamic linking is used
(or if the data segment is indeed contiguous), the field
caml_static_data_limits.used has the value 0 and Is_atom works exactly
as before. The additional cost then is dereferencing of a static
address -- which could be as few as two instructions (test and branch)
on some architectures.

It seems the extension can be used for maintaining `out-of-heap' OCaml
structures. One can have as many such heaps as needed. One merely need
to register the range of these extra-heap addresses.

The code can be found in the directory natdyn of the current MetaOCaml
distribution, specifically files mlvalues.h and ndl.c. The Makefile
contains the necessary voodoo to get the changes take effect.


                 reply	other threads:[~2006-09-28  4:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20060928041522.CBC0EAC04@Adric.metnet.fnmoc.navy.mil \
    --to=oleg@pobox.com \
    --cc=Xavier.Leroy@inria.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).