[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trampolines




	If I understand the problem the ideal solution would be a thread-local second stack.

	Of course thread locality would satisfy the need to be thread-safe.  I'm not sure how portable thread-local storage is, although I know there are efforts to incorporate a "thread" storage class to C/C++ (a non-standard extension "thread" storage class at least is available in the circa 1997 run-time library I'm using).  In any case this ability should be available on all major platforms by now.  It's supposed to be very quick to access TLS under win32 (a few instructions to get the pointer), but I've never measured it; not sure about *NIX TLS access speed.

	As for avoiding a 'maxlen', the stack nature would allow any number of args to be pushed onto it by the trampoline function.  The whole stack could just be a malloc'd block that gets realloc'd when it runs out of space (this would invalidate any pointers into the block, so frames should be referred to via offsets, or equivalent solution).

	Using a stack also avoids the "air" memory waste of a stack full of maxlen-sized arrays.

	It would be nice if the language supported using the other end of the stack space as a second stack, which would grow in the other direction, towards the standard stack.  This would be trivial to use to implement trampolines in assembly and would not require doing any surgery on the call stack.  Also pointers to second stack frames would never be invalidated.


At 04:43 PM 2003.05.12 +0300, Lauri Alanko wrote:
>On Sun, May 11, 2003 at 09:21:44PM -0700, Michael Vanier wrote:
>> You can fake tail calls as well, using a method known as trampolining.
>
>Incidentally, perhaps someone on this list could enlighten me on a
>problem that's been nagging me for ages. If you want real
>multi-parameter functions (not heap-allocated tuples), where do you
>store the parameters to the next function call while trampolining? Heap
>is out, global storage isn't re-entrant or thread-safe, pre-allocated
>"sufficiently large" space in the trampoline is wasteful if it isn't
>wholly used, and space that's been allocated from the stack right
>_before_ jumping back to the trampoline cannot be safely used.
>
>Details here: http://google.com/groups?selm=clcm-19991007-0030%40plethora.net
>
>Comments welcome.
>
>
>Lauri Alanko
>la@iki.fi
>
>