guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC + Java finalization


From: Jonas Hahnfeld
Subject: Re: GC + Java finalization
Date: Sat, 03 Jul 2021 19:26:00 +0200
User-agent: Evolution 3.40.2

Am Samstag, dem 03.07.2021 um 19:14 +0200 schrieb Maxime Devos:
> Jonas Hahnfeld via Developers list for Guile, the GNU extensibility library 
> schreef op za 03-07-2021 om 14:05 [+0200]:
> > Hi Guile devs,
> > 
> 
> Hi, I'm not really a Guile dev but I'll respond anyway.
> 
> > I'm hacking on GNU LilyPond and recently wondered if Guile could run
> > without Java finalization that prevents collection of chains of
> > unreachable objects.
> 
> Do you have an example where this is a problem?
> I.e., did you encounter ‘chains of unreachable objects’ that were
> uncollectable, and so, where?

Sorry, I should have been clearer: Chains don't become uncollectable,
but a chain of N objects takes N collections to be completely reclaimed
(because Java finalization prepares for the possibility that a free
function makes an object live again, as Guile does for guardians). This
leads to unnecessary waste on the heap, and more work for the collector
(even though I haven't been able to measure so far).

> 
> > I found that the functionality is only needed once
> > the first guardian is created, so it's possible to delay enabling the
> > mode until then. This required some fixes to free functions that
> > assumed dependent objects to be freed only later (see first two
> > patches).
> > The third patch delays ensuring Java finalization to scm_make_guardian,
> > but doesn't disable it explicitly (it's on by default in bdwgc). This
> > could now be done right after GC_INIT(), but it's not clear (at least
> > to me) whether client applications actually rely it, so I think it's
> > better if that's not done in Guile itself.
> > 
> > Please consider applying, the fixes potentially also to stable-2.2.
> > 
> > Thanks
> > Jonas
> 
> I would need to look more closely at how ‘Java-style’ finalisation
> works. Some comments anyway:
> 
> (first patch)
> 
> > * test-suite/standalone/test-smob-mark.c
> >   (init_smob_type): Correct size of smob type.
> >   (free_x): Clear smob data instead of local variable.
> >   (test_scm_smob_mark): Put smobs in array to ensure marking.
> > 
> > -      fprintf (stderr, "FAIL: SMOB mark function called for each SMOB\n");
> > +      // Print pointer so it cannot be collected before.
> > +      fprintf (stderr, "FAIL: SMOB mark function called for each SMOB 
> > (smobs = %p)\n", smobs);
> >        exit (EXIT_FAILURE);
> 
> Normally scm_remember_upto_here is used for that.

I think I tried, but it wasn't available. Or I mistyped, not sure.

> Also, I believe "/* */"-style comments are used customarily used in Guile
> instead of "//"-style comments.
> 
> > static void
> > init_smob_type ()
> > {
> > -  x_tag = scm_make_smob_type ("x", sizeof (x_t));
> > +  x_tag = scm_make_smob_type ("x", sizeof (x_t *));
> 
> This change seems to be a fix independent of the ‘do we want Java-style 
> finalization’
> question.

Yes, that's why it's a separate patch.

> 
> (third patch)
> 
> Note that guardians are used in (ice-9 popen).
> They are also used by some guile libraries (e.g. guile-fibers),
> so you can't use (ice-9 popen) or any library using guardians
> if Java-style finalization is undesirable.

Yes, I'm aware and that's why any constructed guardian force-enables
Java finalization. But applications might not use it, and at least for
LilyPond I'm sure it's not used.

Jonas

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]