caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stephen Dolan <stephen.dolan@cl.cam.ac.uk>
To: Lindsay Errington <lindsay.errington@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Possible ephemeron bug?
Date: Thu, 20 Dec 2018 09:46:27 +0000	[thread overview]
Message-ID: <CA+mHimNHxZOAc8kUuZ1oB1RxWZ6NLWW9n=OV4rkitUt9cELw=A@mail.gmail.com> (raw)
In-Reply-To: <CAPeKkNi9P2_vGxeYgybpffz7W2S5tMV2oeTsPHv5jOes=_gbGA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]

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

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 2468 bytes --]

  reply	other threads:[~2018-12-20  9:46 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 [this message]
2018-12-20 17:40   ` Lindsay Errington

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='CA+mHimNHxZOAc8kUuZ1oB1RxWZ6NLWW9n=OV4rkitUt9cELw=A@mail.gmail.com' \
    --to=stephen.dolan@cl.cam.ac.uk \
    --cc=caml-list@inria.fr \
    --cc=lindsay.errington@gmail.com \
    /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).