A question about moving GC

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Mon Jun 12 12:26:09 PDT 2006


Daniel Keep wrote:
> 
> Bruno Medeiros wrote:
>> Walter Bright wrote:
>>> Bruno Medeiros wrote:
>>>> Whoa, I got a bit confused here. Is any reference that is held in the
>>>> stack automatically pinned (i.e., the referred data doesn't move) ?
>>> Yes.
>>>
>>>> If so, why is that, why wouldn't a moving collector move it?
>>> Because then you'd have to track all the register contents instruction
>>> by instruction.
>> :/ I'm lost, I didn't understand that at all. "track all the register
>> contents instruction by instruction" ?
> 
> DISCLAIMER: /me is not an x86 assembler expert.  Take with the requisite
> grain of salt.
> 
> Think about it like this: say you want to dereference a pointer.  Let's
> assume you've got something like this:
> 
> # ubyte* foo = dontPointThatAtMe();
> # ubyte firstFoo;
> 
> Now, you move this into the ESI pointer to dereference it.
> 
> # asm { mov ESI, [foo]; } // move contents to foo into ESI register
> 
> And then HOLD IT!  Moving garbage collector coming through!  Hmm, this
> "foo" thing could be moved to be more efficient; let's move it!  Now, go
> back to your business.
> 
> # asm { mov firstFoo, [ESI]; } // deref pointer in ESI
> 
> What happen?  Someone set up us the access violation!  That damned
> moving GC preempted us and moved our data before we could get to it!
> 

The very same thing can happen with references stored in the heap or the 
static segment (i.e. globals). That is, with *any* reference.


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-learn mailing list