[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is this possible? (garbage collect and weak tables)
- From: Mike Pall <mikelu-0911@...>
- Date: Fri, 6 Nov 2009 14:18:13 +0100
Alex Davies wrote:
> I wonder if LuaJit 2.x would incorrectly optimise the temp variable away
> =/? I'm guessing not, as the gc only runs in interpreted mode, but still
The GC check is performed for compiled code, too. But only at
specific points: at the start of a trace and before each loop
iteration. And only if there's actually anything between these
points which could change the GC thresholds, i.e. an allocation.
Any collectable object that is live at these points is synced to
the stack. Since these points are carefully chosen, this usually
only happens for loop-carried GC objects or side traces with
inherited GC objects. For linear control-flow, like in the
example, the GC doesn't run at the critical spot in compiled code.
So it wouldn't need to sync the temp to the stack.
But you still need to keep the strong reference for semantic
correctness and for the interpreter. And you should copy the
strong reference to the weak reference, not the other way round.