[Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code.
sergos
sergos at tarantool.org
Mon Sep 20 12:37:53 MSK 2021
Thanks!
LGTM.
Sergos
> On 20 Sep 2021, at 11:32, Sergey Kaplun <skaplun at tarantool.org> wrote:
>
> Hi, Sergos!
>
> Thanks for the review!
>
> On 15.09.21, sergos wrote:
>> Hi! Thanks for the patch!
>>
>> I would put something in description about the fact it’s pulled in just
>> to ease following the upstream - in particular, the following 3/3 is done
>> in this very moved code.
>>
>> LGTM with above.
>
> Updated the commit message to the following:
> ===================================================================
> Reorganize lightuserdata interning code.
>
> This patch only performs a code movement of lightuserdata interning to
> <lj_udata.c> file and does nothing else. This patch is backported to
> simplify syncing with the upstream.
>
> Sergey Kaplun:
> * added the description for the patch
>
> Needed for tarantool/tarantool#5629
> ===================================================================
>
> Branch is force pushed.
>
>>
>> Sergos
>>
>>
>>> On 9 Sep 2021, at 10:03, Sergey Kaplun <skaplun at tarantool.org> wrote:
>>>
>>> From: Mike Pall <mike>
>>>
>>> This patch only performs a code movement of lightuserdata interning to
>>> <lj_udata.c> file and does nothing else.
>>>
>>> Sergey Kaplun:
>>> * added the description for the patch
>>>
>>> Needed for tarantool/tarantool#5629
>>> ---
>>> src/lj_api.c | 30 ++----------------------------
>>> src/lj_udata.c | 27 +++++++++++++++++++++++++++
>>> src/lj_udata.h | 3 +++
>>> 3 files changed, 32 insertions(+), 28 deletions(-)
>>>
>>> diff --git a/src/lj_api.c b/src/lj_api.c
>>> index c7a0b327..b6655e5a 100644
>>> --- a/src/lj_api.c
>>> +++ b/src/lj_api.c
>>> @@ -716,36 +716,10 @@ LUA_API void lua_pushboolean(lua_State *L, int b)
>>> incr_top(L);
>>> }
>>>
>>> -#if LJ_64
>>> -static void *lightud_intern(lua_State *L, void *p)
>>> -{
>>> - global_State *g = G(L);
>>> - uint64_t u = (uint64_t)p;
>>> - uint32_t up = lightudup(u);
>>> - uint32_t *segmap = mref(g->gc.lightudseg, uint32_t);
>>> - MSize segnum = g->gc.lightudnum;
>>> - if (segmap) {
>>> - MSize seg;
>>> - for (seg = 0; seg <= segnum; seg++)
>>> - if (segmap[seg] == up) /* Fast path. */
>>> - return (void *)(((uint64_t)seg << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
>>> - segnum++;
>>> - }
>>> - if (!((segnum-1) & segnum) && segnum != 1) {
>>> - if (segnum >= (1 << LJ_LIGHTUD_BITS_SEG)) lj_err_msg(L, LJ_ERR_BADLU);
>>> - lj_mem_reallocvec(L, segmap, segnum, segnum ? 2*segnum : 2u, uint32_t);
>>> - setmref(g->gc.lightudseg, segmap);
>>> - }
>>> - g->gc.lightudnum = segnum;
>>> - segmap[segnum] = up;
>>> - return (void *)(((uint64_t)segnum << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
>>> -}
>>> -#endif
>>> -
>>> LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
>>> {
>>> #if LJ_64
>>> - p = lightud_intern(L, p);
>>> + p = lj_lightud_intern(L, p);
>>> #endif
>>> setrawlightudV(L->top, p);
>>> incr_top(L);
>>> @@ -1197,7 +1171,7 @@ static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)
>>> setfuncV(L, top++, fn);
>>> if (LJ_FR2) setnilV(top++);
>>> #if LJ_64
>>> - ud = lightud_intern(L, ud);
>>> + ud = lj_lightud_intern(L, ud);
>>> #endif
>>> setrawlightudV(top++, ud);
>>> cframe_nres(L->cframe) = 1+0; /* Zero results. */
>>> diff --git a/src/lj_udata.c b/src/lj_udata.c
>>> index 70c722a3..6808b1bc 100644
>>> --- a/src/lj_udata.c
>>> +++ b/src/lj_udata.c
>>> @@ -8,6 +8,7 @@
>>>
>>> #include "lj_obj.h"
>>> #include "lj_gc.h"
>>> +#include "lj_err.h"
>>> #include "lj_udata.h"
>>>
>>> GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)
>>> @@ -34,3 +35,29 @@ void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)
>>> lj_mem_free(g, ud, sizeudata(ud));
>>> }
>>>
>>> +#if LJ_64
>>> +void *lj_lightud_intern(lua_State *L, void *p)
>>> +{
>>> + global_State *g = G(L);
>>> + uint64_t u = (uint64_t)p;
>>> + uint32_t up = lightudup(u);
>>> + uint32_t *segmap = mref(g->gc.lightudseg, uint32_t);
>>> + MSize segnum = g->gc.lightudnum;
>>> + if (segmap) {
>>> + MSize seg;
>>> + for (seg = 0; seg <= segnum; seg++)
>>> + if (segmap[seg] == up) /* Fast path. */
>>> + return (void *)(((uint64_t)seg << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
>>> + segnum++;
>>> + }
>>> + if (!((segnum-1) & segnum) && segnum != 1) {
>>> + if (segnum >= (1 << LJ_LIGHTUD_BITS_SEG)) lj_err_msg(L, LJ_ERR_BADLU);
>>> + lj_mem_reallocvec(L, segmap, segnum, segnum ? 2*segnum : 2u, uint32_t);
>>> + setmref(g->gc.lightudseg, segmap);
>>> + }
>>> + g->gc.lightudnum = segnum;
>>> + segmap[segnum] = up;
>>> + return (void *)(((uint64_t)segnum << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
>>> +}
>>> +#endif
>>> +
>>> diff --git a/src/lj_udata.h b/src/lj_udata.h
>>> index f271a42d..d97936d4 100644
>>> --- a/src/lj_udata.h
>>> +++ b/src/lj_udata.h
>>> @@ -10,5 +10,8 @@
>>>
>>> LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);
>>> LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);
>>> +#if LJ_64
>>> +LJ_FUNC void * LJ_FASTCALL lj_lightud_intern(lua_State *L, void *p);
>>> +#endif
>>>
>>> #endif
>>> --
>>> 2.31.0
>>>
>>
>
> --
> Best regards,
> Sergey Kaplun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20210920/faee0a4b/attachment.htm>
More information about the Tarantool-patches
mailing list