From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 248CC6EC55; Thu, 9 Sep 2021 10:05:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 248CC6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1631171145; bh=bKU2MTHbNSdCjkl1bxLWnacBNvHxQe+Bg+MVJCAabZE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=zxn2mZ0NA7HTE52MmUeLn0DpTJezvHTL09kxwCVoW/baS+FUJOsfUbGVOeMf5S8F3 7VVw0pzBqaT7bSjWCF+X9D5ja7U9pDai1OGtZ6aMf40l1QkM8xr5/6y5s0YYu8Yq9H ARPH+NeItElIhIxfL2v3fzqBd+VISAaHDFokMz1A= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4D4DB6E467 for ; Thu, 9 Sep 2021 10:04:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4D4DB6E467 Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1mOE73-0000qt-DI; Thu, 09 Sep 2021 10:04:45 +0300 To: Igor Munkin , Sergey Ostanevich Date: Thu, 9 Sep 2021 10:03:18 +0300 Message-Id: <369e050ce6799ca94ac08205fdbedad94b56ff87.1631170629.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD91AE02D33A9C88A2F5A5BD9D2085A59586CBBC9313A5A610100894C459B0CD1B9BF0684EAD4C0E1FFC0E8D1FCBCF18C2B2D88DA3C501BBACF1B7A930F6960833A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AA1605287C7F04D6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CDA1F22AAA442F218638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D845523DE03B13FD733458AA0C8D8E5B6B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCC908CD1B87A134A2A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520B1593CA6EC85F86DBDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5053CAA20BC2363C5490E94FE5376937530 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBF3286B3348795C610B23BCE313F37283FB1CCFE414D10839C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCCE3E035A672CDEE699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3403182E70AE6895E00A55227C5928AB7EE82ABB0741BD0915FD7336B7F4C37E7E4B6F29FC429AFF131D7E09C32AA3244CFBE61AEF07483EDA538A805BB488D81381560E2432555DBB927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojV8xpaxME9p+VCincHqPlag== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4C0F3AA5912430A62386CBAB42192B67CC26059F3965CC99BF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall This patch only performs a code movement of lightuserdata interning to 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