[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need for scm_remember_upto_here_* in guile-2.0
From: |
Chris Vine |
Subject: |
Re: Need for scm_remember_upto_here_* in guile-2.0 |
Date: |
Wed, 23 Sep 2015 10:40:49 +0100 |
On Wed, 23 Sep 2015 10:54:50 +0200
David Kastrup <address@hidden> wrote:
> Chris Vine <address@hidden> writes:
>
> > On Wed, 23 Sep 2015 09:26:27 +0200
> > David Kastrup <address@hidden> wrote:
> >
> >> Also, a pointer to an array (rather than something more opaque like
> >> SCM) is much more likely to be subject to strength reduction and
> >> address arithmetic by the compiler, leading to a situation where
> >> looping through some array does not leave a live pointer in
> >> registers and stack frame in a form recognizable by libgc.
> >
> > However, I haven't understood your point about arrays. If they are
> > allocated with malloc() you need a finaliser and you may need to
> > call scm_remember_upto_here_1() to prevent the smob's finaliser
> > from firing while they are still in use. If they are allocated with
> > scm_gc_malloc() you don't, as I understand it. Were you making a
> > point in addition to that, and if so could you expand on it for me?
>
> The point is that libgc may be less reliable with recognizing a
> typical C/C++ array still being in use than with SCM values because
> the compiler is more likely to mangle array access beyond recognition
> by stack frame inspection.
>
> For example, if you index arrays starting from 1 (or have indexing
> expressions with similar effects), the actual register from which the
> compiler does its indexing may lie strictly outside of the allocated
> area for an array.
>
> A compiler may also choose to convert a loop running from indexes 0 to
> n-1 to one running from -n to -1 in order to have a nicer terminating
> condition. Again, with strength reduction this may lead to the actual
> libgc-recognizable pointer being clear outside of the allocated array.
>
> SCM is defined in a manner where the compiler has far fewer useful
> transformations at its disposal for the normal operations. So the
> likelihood of libgc making mistakes is just lower.
Your trees look excellent, but your pedagogical approach to the wood is
still a mystery to me. So are you saying:
(i) libgc's garbage collector is unreliable with arrays allocated with
scm_gc_malloc() (or scm_gc_malloc_pointerless()), so using those
functions for garbage collected arrays should be avoided, and hand
written memory management for arrays using smob finalisers should be
employed instead,
or
(ii) if you are doing hand written memory management for arrays using
smob finalisers instead of using garbage collected arrays, you should
make liberal use of scm_remember_upto_here_* because libgc is
particularly apt to finalise your smob while the arrays are still in
use?
Chris
- Re: Need for scm_remember_upto_here_* in guile-2.0, (continued)
- Re: Need for scm_remember_upto_here_* in guile-2.0, Ludovic Courtès, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Mark H Weaver, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Ludovic Courtès, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0,
Chris Vine <=
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/23