[webkit-dev] JavaScriptCore Conservative Garbage Collector

Darin Adler darin at apple.com
Thu Jun 9 21:05:36 PDT 2005


On Jun 9, 2005, at 8:45 PM, Darin Adler wrote:

> On Jun 9, 2005, at 1:35 PM, Justin Haygood wrote:
>
>> What does mark conversatively mean? NSPR doesn't have a way to  
>> access the stack objects of each thread, so I'm in a bit of a  
>> bind. The NSPR threading library does have pretty much everything  
>> else a threading library needs, and is very clean.
>
> Marking conservatively means marking every object that is pointed  
> to by any value on the stack (or in registers). What "conservative"  
> refers to here is that a value on the stack might look like a  
> pointer, but actually be a value of another type that just happens  
> to look like a pointer, or even uninitialized data. Thus an object  
> that's actually garbage might not get collected, hence the  
> collector is "conservative" in keeping it alive.

The Wikipedia page <http://en.wikipedia.org/wiki/Garbage_collection_% 
28computer_science%29> mentions this. Look for "partly conservative"  
in the page.

Some super-great things about the conservative garbage collector are  
that it eliminates: the need for smart pointer wrappers for  
JavaScript objects, the need for a few flags that every object used  
to have (besides the mark bit), ambiguity about when to use smart  
pointer wrappers and when not to, and most if not all subtle rules  
about how to use the JavaScript object pointers properly. It made the  
library faster when we first switched to it, largely because of the  
time not spent doing ref and deref all the time. And it will make  
things even faster when we take further advantage of simplifications  
it made possible.

We can get much better performance for code that doesn't involve  
wrappers. C++ compilers don't do so great at optimizing when there  
are objects that have a single pointer in them -- the fact that the  
this pointer is a pointer to that pointer tends to make them not  
generate code that's as good as simple pointer manipulation.

     -- Darin




More information about the webkit-dev mailing list