Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain.Frisch@ens.fr
To: Nuutti Kotivuori <naked+caml@naked.iki.fi>
Cc: Caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] Freeing dynamically loaded code
Date: Fri, 12 Dec 2003 22:26:46 +0100 (MET)	[thread overview]
Message-ID: <Pine.SOL.4.44.0312122135110.13180-100000@clipper.ens.fr> (raw)
In-Reply-To: <874qw594ys.fsf@naked.iki.fi>

On Fri, 12 Dec 2003, Nuutti Kotivuori wrote:

> Well, like Xavier Leroy said at the end of the mail - *he* probably
> isn't doing it. That doesn't mean there wouldn't be someone else crazy
> enough to try :-)
>
> And atleast I'm not dropping the investigation just yet.

Thinking again about the technical challenge (put the dynlink'ed code
under GC control), I think the following approach is worth a try.

The question is how to let the GC know that the code block cannot be freed
as long as there is some accessible closure pointing into this block. We
can think of using something similar to InfixTag, but this is a heavy
solution as it requires to modify the GC in many places.

I propose to avoid creating "bad" closures that points to the loaded code.
We simulate a bad closure by a closure to a generic stub. In addition to
the normal environment, we put two additional slots into this closure: a
pointer to the code block and an offset. This closure is fully under the
control of the GC. The stub is made of a single instruction (or maybe two,
see next paragraph), say a new bytecode CALL_DYN, which computes the real
destination from the closure and jumps to it. We also need a new
CLOSURE_DYN bytecode that behaves as CLOSURE but create a faked closure
instead of a bad one. Dynlink changes CLOSURE to CLOSURE_DYN when it loads
a module. We need to take care of GRAB, RESTART and CLOSUREREC similarly.

We also need to make sure that the "active" code blocks (the ones which
have an active stack frame) are accessible by the GC. We have to be
careful since the faked closure may become inacessible even if it
is currently running (because of an in-place modification). So CALL_DYN
should keep its closure on the stack (which contains a pointer to the
code block) and call the real function. The bytecode following CALL_DYN
would just pop the closure after the function returns.

These changes does not affect the GC at all, and are simple additions to
the bytecode interpreter (interp.c). The cost of calling closures to
dynlink'ed modules is increased, but we don't really care since:
1) this is bytecode, so anyway ...
2) non dynlink'ed code is not affected at all


Any comment on this?

  Alain

-------------------
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:[~2003-12-12 21:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-12 19:04 Nuutti Kotivuori
2003-12-12 19:36 ` Alain.Frisch
2003-12-12 20:05   ` Nuutti Kotivuori
2003-12-12 21:26     ` Alain.Frisch [this message]
2003-12-12 21:54       ` Nuutti Kotivuori
2003-12-13  7:25         ` Nuutti Kotivuori
2003-12-13  8:15           ` Alain.Frisch
2003-12-13 20:57             ` Nuutti Kotivuori
2003-12-17  7:17             ` Jacques Garrigue
2003-12-17 23:48               ` Nuutti Kotivuori
2003-12-13  2:04       ` skaller
2003-12-13  6:50         ` Nuutti Kotivuori
2003-12-15  3:11       ` Nuutti Kotivuori
2003-12-17 23:16         ` Nuutti Kotivuori
2003-12-15  9:35 ` Basile Starynkevitch
2003-12-15 11:34   ` Nuutti Kotivuori

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=Pine.SOL.4.44.0312122135110.13180-100000@clipper.ens.fr \
    --to=alain.frisch@ens.fr \
    --cc=caml-list@inria.fr \
    --cc=naked+caml@naked.iki.fi \
    /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