unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Unordered finalization, SMOBs, finalizers, and mark functions
@ 2015-01-26  9:52 Andy Wingo
  2015-03-04 10:10 ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2015-01-26  9:52 UTC (permalink / raw)
  To: guile-devel

Hi,

Guile currently uses the Boehm-Demers-Weiser collector with "Java-style
finalization", which is to say that finalizers are unordered.  This is
good in the sense that Guile's GC can collect cycles of objects with
finalizers that point to each other.  It also has some understudied
disadvantages or strange behavior.

One disadvantage is that with the default topological finalization
order of BDW-GC, cycles of objects with finalizers are uncollectable.  I
think that BDW-GC will warn to the console when this is the case, in the
default mode, so perhaps it's not that bad.

Another disadvantage is that running the finalizer of object O1 which
links to finalizable object O2 could see O2 after O2's finalizer has
been run, because finalizers are unordered.  This is almost certainly
not what you would expect.

Also, if O1 has a mark function, you could mark O1 when O1 is on the
finalization queue but not yet finalized, and O2 has already been
finalized -- so your mark functions also need to be ready to deal with
unordered finalization.

Keep in mind that in Guile 2.x, finalizers are uncommon.  They are
probably more common in user code than in Guile code, in the form of
SMOB free functions.  This is especially the case in code ported from
earlier Guile versions.

Useful links:

  Finalization
  http://hboehm.info/gc/finalization.html

  Finalizers, Threads, and the Java Memory Model
  http://hboehm.info/misc_slides/java_finalizers.pdf

  Foreign Object Memory Management
  http://www.gnu.org/software/guile/docs/master/guile.html/Foreign-Object-Memory-Management.html#Foreign-Object-Memory-Management

Open question: should Guile configure the BDW GC in a different way?
Topological finalization is desirable for all the reasons Boehm links in
that first article.  Should it allow the user to configure it?  I
believe it is currently unordered due to issues with guardians, but I
don't recall correctly.

Thoughts?

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unordered finalization, SMOBs, finalizers, and mark functions
  2015-01-26  9:52 Unordered finalization, SMOBs, finalizers, and mark functions Andy Wingo
@ 2015-03-04 10:10 ` Ludovic Courtès
  2015-03-09 21:05   ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2015-03-04 10:10 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

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

Andy Wingo <wingo@pobox.com> skribis:

> Open question: should Guile configure the BDW GC in a different way?
> Topological finalization is desirable for all the reasons Boehm links in
> that first article.  Should it allow the user to configure it?  I
> believe it is currently unordered due to issues with guardians, but I
> don't recall correctly.

Right, I initially wanted to enable it but it turned out to be a can of
worms.

I’ve just run the test suite with this patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 347 bytes --]

diff --git a/libguile/gc.c b/libguile/gc.c
index 097cb3d..78999c2 100644
--- a/libguile/gc.c
+++ b/libguile/gc.c
@@ -609,6 +609,7 @@ scm_storage_prehistory ()
   target_free_space_divisor = free_space_divisor;
   GC_set_free_space_divisor (free_space_divisor);
   GC_set_finalize_on_demand (1);
+  GC_set_java_finalization (1);
 
   GC_INIT ();
 

[-- Attachment #3: Type: text/plain, Size: 578 bytes --]


And it actually passes.  I suspect that only means we don’t have good
tests for all these things, and those we have typically throw
'unresolved when they get an unexpected result.

As you note, the problem may be with user code more than with Guile’s
own uses.  It seems hard to assess the effect of such a change on “real
applications.”

In short, I think it would take a lot of investigation and testing to
convince ourselves that this is a reasonable change.

WDYT?

Ludo’.

[0] http://lists.gnu.org/archive/html/guile-devel/2008-11/msg00009.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Unordered finalization, SMOBs, finalizers, and mark functions
  2015-03-04 10:10 ` Ludovic Courtès
@ 2015-03-09 21:05   ` Andy Wingo
  2015-03-10  7:59     ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2015-03-09 21:05 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Wed 04 Mar 2015 11:10, ludo@gnu.org (Ludovic Courtès) writes:

> diff --git a/libguile/gc.c b/libguile/gc.c
> index 097cb3d..78999c2 100644
> --- a/libguile/gc.c
> +++ b/libguile/gc.c
> @@ -609,6 +609,7 @@ scm_storage_prehistory ()
>    target_free_space_divisor = free_space_divisor;
>    GC_set_free_space_divisor (free_space_divisor);
>    GC_set_finalize_on_demand (1);
> +  GC_set_java_finalization (1);
>  
>    GC_INIT ();

This is the wrong patch :)  As you can see in scm_init_guardians() we
actually already call this, and the novelty would be to have not-java
finalization.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unordered finalization, SMOBs, finalizers, and mark functions
  2015-03-09 21:05   ` Andy Wingo
@ 2015-03-10  7:59     ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2015-03-10  7:59 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

Andy Wingo <wingo@pobox.com> skribis:

> On Wed 04 Mar 2015 11:10, ludo@gnu.org (Ludovic Courtès) writes:
>
>> diff --git a/libguile/gc.c b/libguile/gc.c
>> index 097cb3d..78999c2 100644
>> --- a/libguile/gc.c
>> +++ b/libguile/gc.c
>> @@ -609,6 +609,7 @@ scm_storage_prehistory ()
>>    target_free_space_divisor = free_space_divisor;
>>    GC_set_free_space_divisor (free_space_divisor);
>>    GC_set_finalize_on_demand (1);
>> +  GC_set_java_finalization (1);
>>  
>>    GC_INIT ();
>
> This is the wrong patch :)  As you can see in scm_init_guardians() we
> actually already call this, and the novelty would be to have not-java
> finalization.

Oops, sorry for the confusion.  Well anyway, that’s the thing to do:
test and see what wrecks havoc.

Ludo’.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-10  7:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-26  9:52 Unordered finalization, SMOBs, finalizers, and mark functions Andy Wingo
2015-03-04 10:10 ` Ludovic Courtès
2015-03-09 21:05   ` Andy Wingo
2015-03-10  7:59     ` Ludovic Courtès

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 read-only IMAP folder(s) and NNTP newsgroup(s).