[Vm-dev] GC | Strong or weak reference to arguments on stack?

Marcel Taeumel marcel.taeumel at hpi.de
Thu Aug 19 07:01:37 UTC 2021


Hi Eliot --

The issue is that a weak reference inside the FFICallback instance (from "FFI-Callbacks", not Alien) becomes "nil" with strong references still being there on the stack due to the stack frame.

I think I found my mistake.

Okay, the call starts with this:
   lib qsort: array compare: [:a :b | (a - b) sign].

Before making the FFI call in #qsort:with:with:with:, I create an instance of FFICallback (being an alias for byte[48], the thunk) via #compare:through:. 

BUT I recently moved "pointer unpacking" for single atomics from #evaluateDynamic: to #compare:through:. So, the original block is wrapped as follows:
   [:arg1 :arg2 | evaluable value: arg1 value value: arg2 value]

Now "evaluable" is closured from being an argument into the new block.

This new block never sits on in a stack frame as argument.
This new block only has a weak reference inside FFICallback.
This new block can easily get GC'ed during the callbacks.

Ha. Damn. And I finally need to write that generator to materialize fast versions of #evaluateDynamic: according to the signatures.

Thanks for reading. :-D

Best,
Marcel
Am 18.08.2021 17:59:15 schrieb Eliot Miranda <eliot.miranda at gmail.com>:
Hi Marcel,

On Aug 18, 2021, at 5:25 AM, Marcel Taeumel <marcel.taeumel at hpi.de> wrote:



Hi all!

I kind of thought that objects sitting as arguments on active stack frames form strong references.

Indeed they must.

Yet, I have a kind of flaky callback test that raises doubts about this assumption.

Here is an example:
  lib qsort: array compare: [:a :b | (a - b) sign].

The block being nil inside the callback could imply that the lookup from thunk address to block yielded nil and be nothing to do with the stack no?


Maybe it is some interference with GC and FFI callbacks ... Hmm... Anyway, sometimes, the block closure is already "nil" inside the callback when its time to evaluate... But mostly it works fine. :-)

I can’t see what you’ve posted below.  If displays as a white region.  Can you post the stack?  What’s the actual error message? If you look down the stack where does the nil block originate?




Mysterious ;-)


Best,
Marcel

Eliot
_,,,^..^,,,_ (phone)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20210819/78500df8/attachment.html>


More information about the Vm-dev mailing list