lua-users home
lua-l archive

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


On 17 March 2018 at 06:51, 云风 <cloudwu@gmail.com> wrote:
>
>> 在 2017年12月16日,上午9:11,Dibyendu Majumdar <mobile@majumdar.org.uk> 写道:
>>
>>> On 16 December 2017 at 01:05, Italo Maia <italo.maia@gmail.com> wrote:
>>> What would a lua hook be?
>>>
>>
>> Apologies I should have been clearer about this. Before a bytecode is
>> executed Lua checks if it needs to invoke a hook. This check has some
>> overhead especially when computed gotos are enabled, as you can
>> imagine at every jump there is an 'if .. ' check.
>
> So, maybe we can write two version luaV_execute ? With and without hook?
>

Yes you can; in LuaJIT I believe each opcode gets decorated by a
wrapper that forwards to the base opcode; this is possible by
modifying the jump table at runtime. In C you cannot do that.

Note that Roberto has tried to minimise the impact of the hook by
using a local variable (trap) to avoid checking the hook - nonetheless
this code gets replicated in every computed goto branch; and is not
only wasteful but also negatively affects optimisation I would guess.

Regards
Dibyendu