caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nuutti Kotivuori <naked+caml@naked.iki.fi>
To: Alain.Frisch@ens.fr
Cc: Caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] Freeing dynamically loaded code
Date: Sat, 13 Dec 2003 09:25:37 +0200	[thread overview]
Message-ID: <873cbp5gcu.fsf@naked.iki.fi> (raw)
In-Reply-To: <87vfol7lcf.fsf@naked.iki.fi> (Nuutti Kotivuori's message of "Fri, 12 Dec 2003 23:54:56 +0200")

Nuutti Kotivuori wrote:
> Alain Frisch wrote:
>> 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.
>
> Hmm. Quite ingenious. I read through the CLOSURE and CLOSUREREC
> calls and considered modifying those when linking, but never came up
> with a proper solution. That sounds like it.

Ha!

I got it!

There was a problem I was pondering out with that suggestion. And it
was basically that the functions from the dynamically linked module
must appear as normal closures taking the appropriate number of
arguments - and yet would have to be called throug CALL_DYN - which
would mean either patching the code of *all* modules, or having an
intermediate code block which does the call to CALL_DYN. And this
didn't sound nice.

But then I got the idea.

If we are going to be mangling the bytecode anyway, why not mangle it
a bit more?

Let's make sure every closure generated from the library has an extra
local variable in it's environment, pointing to the head of the block
where that closure's code resides. This local variable need not even
be used, as long as it doesn't break the other locals in the function.

So then every closure will carry an extra local variable, and those
are seen by the garbage collector, so the main codefile will exist as
long as any of those closures do.

The bytecode manipulation might not be entirely trivial though, but
certainly seems easier than anything else we've talked about yet.

What do you think? Have I got it all wrong?

-- Naked

-------------------
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-13  7:25 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
2003-12-12 21:54       ` Nuutti Kotivuori
2003-12-13  7:25         ` Nuutti Kotivuori [this message]
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=873cbp5gcu.fsf@naked.iki.fi \
    --to=naked+caml@naked.iki.fi \
    --cc=Alain.Frisch@ens.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).