Re: cdata finalizer called twice

  • From: Peter Colberg <peter@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 18 Nov 2014 21:17:11 -0500

On Tue, Nov 18, 2014 at 02:01:32PM +0100, Mike Pall wrote:
> Peter Colberg wrote:
> > Does the following function return a reference to an unanchored cdata?
> 
> No.
> 
> > Why does that not print '3ULL 3ULL 3ULL', if buf[0] is a reference cdata?
> 
> Scalars have value semantics, not reference semantics.

Thank you for the confirmation.

Then I suppose returning 'uint64_t(buf[0])' is only hiding the
issue by adding an additional allocation plus garbage collection.

Apart from disabling or mangling code that first trigged the issue,
what I did so far for debugging is output the pointer value of each
event object as it is created and then output the pointer value of
each event object as it is finalized, to make sure that the OpenCL
library is not handing out duplicate pointers. This confirmed that
event objects have unique pointer values and indeed are finalized
twice on rare occasion.

What tips would you give to debug the finalization? Could I somehow
hook into LuaJIT without hindering JIT compilation to see when and
why the decision is made to finalize a cdata with a given pointer
value?

I also wonder how the tail calls could affect finalization. Where
could I hook into LuaJIT to see the effect of having or not having
a tail call?

Are there common programming mistakes that cause bugs only if the
compiler is enabled, but disappear with 'luajit -joff'?

Thank you for any pointers in finding the root cause.

Peter

Other related posts: