From: Lindsay Errington <lindsay.errington@gmail.com>
To: Stephen Dolan <stephen.dolan@cl.cam.ac.uk>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Possible ephemeron bug?
Date: Thu, 20 Dec 2018 09:40:56 -0800 [thread overview]
Message-ID: <CAPeKkNg07g1q=j_UY3k+PJxMRPR2w0Y88U6gknjr92UjmRJXaQ@mail.gmail.com> (raw)
In-Reply-To: <CA+mHimNHxZOAc8kUuZ1oB1RxWZ6NLWW9n=OV4rkitUt9cELw=A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]
Great answer! Thanks to you both.
I have a followup ephemeron question which I'll post with a different
subject.
On Thu, Dec 20, 2018 at 1:46 AM Stephen Dolan <stephen.dolan@cl.cam.ac.uk>
wrote:
> On Thu, 20 Dec 2018 at 00:30, Lindsay Errington <
> lindsay.errington@gmail.com> wrote:
>
>> If however, I use the standalone bytecode compiler or the native compiler
>> (4.07.1), then the entries are not nullified. Is this a bug or is there
>> another way to persuade the garbage collector to clobber the entries?
>>
>
> Thanks for the detailed example!
>
> The issue is with the test code at the end:
>
> let (root,map) =
> let map = [] in
> let (k0,map) = intern 0 (str 1) map in
> let (k1,map) = intern 1 (Link k0) map in
> let (k2,map) = intern 2 (Link k1) map in
> (k2,map);;
>
> Fmt.printf "root=%a, map=@[<v>%a@]@." pp_key root pp_map map;;
>
> let map = upd root (str 2) map;;
>
> Fmt.printf "root=%a map1=@[<v>%a@]@." pp_key root pp_map map;;
>
> Both the bytecode and native code compilers take any value bound to a
> global to be reachable forever, even if that global is later shadowed by
> another global of the same name. The ephemerons don't get cleared, because
> the original map is still alive.
>
> You can change the code to avoid putting the original map in a global
> constant:
>
> let (root, map) =
> let map = [] in
> let (k0,map) = intern 0 (str 1) map in
> let (k1,map) = intern 1 (Link k0) map in
> let (k2,map) = intern 2 (Link k1) map in
> Fmt.printf "root=%a, map=@[<v>%a@]@." pp_key k2 pp_map map;
> let map = upd k2 (str 2) map in
> (k2, map);;
>
> Fmt.printf "root=%a map1=@[<v>%a@]@." pp_key root pp_map map;;
>
> With this version, the original map becomes unreachable, so the GC can
> clear the ephemerons.
>
> Stephen
>
[-- Attachment #2: Type: text/html, Size: 3837 bytes --]
prev parent reply other threads:[~2018-12-20 17:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 0:29 Lindsay Errington
2018-12-20 9:46 ` Stephen Dolan
2018-12-20 17:40 ` Lindsay Errington [this message]
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='CAPeKkNg07g1q=j_UY3k+PJxMRPR2w0Y88U6gknjr92UjmRJXaQ@mail.gmail.com' \
--to=lindsay.errington@gmail.com \
--cc=caml-list@inria.fr \
--cc=stephen.dolan@cl.cam.ac.uk \
/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