[webkit-dev] The JSC Garbage Collector

Sanjoy Das sanjoy at playingwithpointers.com
Tue Oct 4 22:50:30 PDT 2011


I recently started looking through the JavaScriptCore codebase, and
discovered that working on the GC would be a nice way to contribute.

A starting point, I think, would be to implement code that allows
moving objects around.  I was thinking of doing this by adding a third
field to the MethodTable which takes a hashtable mapping addresses of
old objects to their new addresses.  This function should then modify
the structure in question accordingly (to modify the fields to point
to the new memory locations wherever needed).

This way a basic moving and compacting collector (with two spaces)
could be implemented like:

1. Figure out the live objects.
2. Allocate space for them in the other allocation space.  Put the old
and new address pairs in a map.
3. Ask every live (old) object to re-orient itself using the map
generated in (2).
4. Copy the old objects to their designated new locations.

Does this make sense?  I'm still pretty new to the JSC codebase so I'm
not sure about most of what I just said.  Another way is, of course,
to keep references to references, as mentioned in [1].  I found this
approach better since all the heavy lifting happens at GC time, and
does not burden the runtime with a double deref.

Thank you for your time!

[1] http://trac.webkit.org/wiki/JS%20Core%20Garbage%20Collector
Sanjoy Das

More information about the webkit-dev mailing list