Re: Garbage collection and optimization

Paolo Bonzini <bonzini@gnu.org>
Thu, 08 Nov 2007 09:59:28 -0000

          From comp.compilers

Related articles
Garbage collection and optimization rayiner@gmail.com (Rayiner Hashem) (2007-11-05)
Re: Garbage collection and optimization bonzini@gnu.org (Paolo Bonzini) (2007-11-08)
| List of all articles for this month |

From: Paolo Bonzini <bonzini@gnu.org>
Newsgroups: comp.compilers
Date: Thu, 08 Nov 2007 09:59:28 -0000
Organization: Compilers Central
References: 07-11-020
Keywords: GC, parallel

> cons* alloc_cons(cons* car, cons* cdr) {
> if((alloc_ptr + sizeof(cons)) > alloc_limit)
> make_more_space();
>
> cons* obj = (cons*)alloc_ptr;
> obj->car = car; /* one */
> obj->cdr = cdr; /* two */
> alloc_ptr += sizeof(cons); /* three */
> return obj;
> }
>
> If the GC interrupts before 'one' or after 'three', we're fine. 'car'
> and 'cons' will remain live since their values will be used later.
> However, what happens when the GC interrupts between 'one' and 'two'?
>
> What solutions to this problem are used in practice?


You have a special root set for objects being constructed. In one
design the GC will keep them alive but not scan them; or you
initialize the object fields to "null" at the moment you initialize
them. In both cases you "bump the pointer" before you start to fill
the object fields.


In the former case, all three of "obj", "car", "cdr" will have to be
in the special root set. In the latter, only "obj" will have to be
put there.


So it will be something like:


    /* caller must have put car and cdr on root set, telling GC to scan
them */
    /* do the following two atomically! */
    cons* obj = (cons*)((alloc_ptr += sizeof(cons)) - sizeof(cons));
    put obj on root set, it will not be scanned
    obj->car = car; /* one */
    obj->cdr = cdr; /* two */


or


    /* caller must have put car and cdr on root set */
    /* GC makes sure that memory at alloc_ptr is filled with nulls */
    /* do the following two atomically! */
    cons* obj = (cons*)((alloc_ptr += sizeof(cons)) - sizeof(cons));
    put obj on root set
    obj->car = car; /* one */
    obj->cdr = cdr; /* two */


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.