Parrot GC Refactor work
09 May 2009I spent a lot of time yesterday and this morning working on the GC API refactor for Parrot, and I've made some pretty good progress so far. One cool result from this work is that I am finding all sorts of places where the GC internal data structures were being manipulated throughout the codebase, some instances of which are very likely to have been causing the problems I experienced over the summer.
That aside, I'm pleased to say that this morning I managed to get the GC almost entirely properly encapsulated. All external-facing GC functions are in the API, and all other functions are kept private. In addition, data structures like
struct Arenas
, struct Small_Object_Pool
and struct Small_Object_Arena
are now only accessible from within the GC subsystem. This prevents the rest of Parrot from monkeying around in these structures, but also makes it easier for alternate GC cores to redefine them as necessary. The API isn't particularly clean or elegant right now, but it is encapsulated and that's a start. It's certainly more then we've had since I've been a Parroteer.The downside to this work is that the number of functions in the GC API has increased pretty substantially, both from creating new functions and by moving old functions into it. Many of the new functions are simple accessors for internal datastructures. I've managed not to have all the new functions listed as "PARROT_EXPORT", which is a win for dynamic link time, so thats good at least. Some of the macros that controlled blocking and unblocking the GC are now redefined as API functions, which is something I've wanted to do for a long time now.
In my last GC post I guessed at which functions would be necessary in the API. Now that I've finished encapsulating it, I can tell you what functions are actually in the API now:
- Function to mark an object as being alive.
- Functions to initialize and deinitialize the GC subsystem.
- Functions to perform mark/sweep and compact actions
- Functions to manipulate pools between interpreters, such as merging pools, moving shared objects between pools, etc.
- Header allocation functions for PMCs, STRINGs, and other Buffer-like objects (ListChunks, Stack_Chunks, etc).
- Header reclamation functions to take unused PMCs, STRINGs, and other Buffer-like objects and add them back to the free list.
- Functions to add extension objects (pmc_ext and Sync) to existing PMCs, and functions to remove them again.
- Memory block allocation functions for allocating buffers of arbitrary sizes, such as storage for STRINGs. Also, functions to deallocate these memory blocks, and functions to resize them.
- Functions to determine if a given pointer is in a particular pool
- Functions to block and unblock various GC phases, and functions to determine if they are blocked currently
- Accessor functions to get information from the Arenas structure.
- Function to mark PMCs that need timely destruction
I'm still not entirely happy with the encapsulation status as it stands now. There are a few places such as the freeze/thaw subsystem where accesses are made to the memory system internals that I really wish weren't being made. But, that's a relatively small issue because most of those routines happen at interpreter destruction time after the GC has already been blocked/finalized.
I want to get my branch merged back into trunk soon. I've hit a good milestone now and I don't want this branch to live for too long lest new problems arise. Probably some small cleanup and documentation work to do first, but it's not far off now.
This entry was originally posted on Blogger and was automatically converted. There may be some broken links and other errors due to the conversion. Please let me know about any serious problems.
Comments
Chris Dolan
5/9/2009 12:49:00 PM
Whiteknight
5/9/2009 3:18:00 PM
Thanks for you hard work! Expert attention like this is very valuable to the whole project.
Thanks! The work isn't done yet though: A bit of trouble popped up when I tried to merge my branch in and I have to spend some time debugging that. Hopefully it isn't too bad.