From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: STARYNKEVITCH Basile <Basile.Starynkevitch@cea.fr>, caml-list@inria.fr
Subject: Re: mixing Ocaml with another GC-ed language
Date: Tue, 29 Feb 2000 11:24:06 +0100 [thread overview]
Message-ID: <20000229112406.23618@pauillac.inria.fr> (raw)
In-Reply-To: <14518.34203.741447.637489@gargle.gargle.HOWL>; from STARYNKEVITCH Basile on Fri, Feb 25, 2000 at 02:37:31PM +0100
> It is not really plain C++ because I did code a (precise, mostly
> copying, generational) garbage collector which is used in the
> project. So Ocaml code will be called from (and will probably upcall
> to) C++ code using my GC. So I do know my GC quite well (and studied
> Ocaml's GC a bit also). My GC also support finalized objects, which it
> does not move (so their address remain fixed).
>
> Does any people have concrete experience mixing Ocaml with another
> GC-ed language (e.g. Java or Common Lisp) inside the same program?
I can't say I have concrete experience, but I believe the following
should work.
So, we have two garbage-collected languages A and B, each managing its
own heap. Assume both A and B support 1- finalized objects, and
2- explicit registration of GC roots.
Then, to make an A object available to B, register the A pointer as a
GC root for A (so that A doesn't reclaim it), allocate in B a proxy
block containing the A pointer, and put a finalization function on the
proxy block that un-registers the A pointer with A's GC when the proxy
block is finalized.
In this approach, A objects are viewed from B as an abstract type:
B can't do anything with them except call A functions to operate on
them. Allowing B to operate directly on A objects (e.g. read and
write an array) is very language-dependent and generally hard; better
go through foreign function calls.
> I do have my precise ideas on the problem (essentially, avoid mixing
> pointers from both worlds, either by copying data or by using my
> finalized C++ GCed objects which are not moved by my GC).
Copying is another option (that's what stubs generated by CamlIDL do,
for instance). You get the benefit of having a concrete view on the
data structure in both languages. But copying can be expensive on
large structures, and also loses sharing for mutable objects.
> The custom tag object (introduced in Ocaml3, see the Ocaml CVS
> webserver) might also be helpful.
Right. It's a generalization of OCaml's finalized objects, allowing
you to attach to a Caml memory block not only a finalization function,
but also an equality function, a hashing function, and serialization /
deserialization functions (called by output_value and input_value).
- Xavier Leroy
next prev parent reply other threads:[~2000-03-01 16:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-02-25 13:37 STARYNKEVITCH Basile
2000-02-29 10:24 ` Xavier Leroy [this message]
2000-03-01 3:48 ` Nice feature Max Skaller
2000-03-01 3:52 ` Interpreter vs hardware threads Max Skaller
2000-03-01 18:55 ` Michael Hicks
2000-03-01 20:02 ` Stefan Monnier
2000-03-02 18:18 ` William Chesters
2000-03-03 16:59 ` John Max Skaller
2000-03-06 17:35 ` Xavier Leroy
2000-03-06 23:11 ` John Max Skaller
2000-03-07 13:19 ` Julian Assange
2000-03-08 20:12 ` Xavier Leroy
2000-03-19 6:10 ` Julian Assange
2000-03-08 23:30 ` Max Skaller
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=20000229112406.23618@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=Basile.Starynkevitch@cea.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