emacs-devel
[Top][All Lists]
Advanced

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

Re: Conservative GC isn't safe


From: Ken Raeburn
Subject: Re: Conservative GC isn't safe
Date: Sun, 27 Nov 2016 01:17:54 -0500

On Nov 26, 2016, at 10:03, Stefan Monnier <address@hidden> wrote:
> 
>>> 1) mark_maybe_pointer looks only for exact matches on object start. It's
>>> perfectly legal for the compiler to keep an interior object pointer and
>>> discard the pointer to the object start.
>> Yes, just as it's perfectly legal for the compiler to subtract 42 from every
>> pointer before putting it in a register or storing it into memory. In
>> practice, though, compilers don't do this around calls to the garbage
>> collector. (True, this assumption should be documented better.)
> 
> Indeed.  Hans Boehm's done a fair bit of research in this issue,
> including discussing the underlying assumptions and arguing that
> compilers should (and usually do) guarantee those assumptions.

I’d be surprised if that held reliably when the last use of a Lisp_Object in 
some function extracts an object pointer and then never references the 
Lisp_Object as such ever again.

Lisp_Object foo (Lisp_Object obj)
{
  …
  return mumble (XSYMBOL (obj));
}

It’s got no reason to specifically obfuscate the value, but it may also have no 
reason to keep a copy of the Lisp_Object value around when it’s no longer 
needed.  It’s not so much that the compiler has decided to start using an 
interior pointer on its own, but instead just doing what we told it to do.  If 
“mumble” triggers GC, stack marking may well find only the pointer and not the 
original “obj” value in this function, especially if the compiler optimizes 
away the stack frame of “foo” completely.

If Boehm has found that compilers really do keep references even in cases like 
this (“usually” probably isn’t good enough), I’d be interested in reading up on 
that.

Ken


reply via email to

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