[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: emergency garbage collector
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 15 Feb 2012 16:59:05 -0200
> Thanks. But I have to isolate the emergency gc and integrate it. Is there
> any documentation about it somewhere, that gives me more insight on the
> files/code changes that this would involve?
No. The main problem is that, with the emergency gc, every single memory
allocation can trigger a complete gc. That means that every single block
of memory must be rooted somewhere before Lua can allocate the next
block (otherwise the first bock may be collected while Lua allocates the
second). That means the changes are somewhat spread all over places
where Lua creates objects, which are plenty.
As an example, in 5.1 there was this function:
Table *luaH_new (lua_State *L, int narray, int nhash)
that created a table with certain sizes. But this function does not know
where to root the table head while creating the arrays. So, in 5.2,
you must call
Table *luaH_new (lua_State *L)
that creates the header with empty arrays, anchor that header somewhere
(e.g., in the top of the stack), and then call luaH_resize to set the
proper sizes for the arrays. Therefore, most places that create tables
have to be fixed.
To make things worse, it is tricky to properly test the code, as a
bug will only appear when there is an emergency collector in a
specific allocation in the code.