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 063B46EC40; Mon, 20 Sep 2021 11:34:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 063B46EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1632126846; bh=oYcmzgw29UxlNWHuTLCrmOCCv5qmzAIqdFuLhLuEnlc=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GLvJdt4z3Cdzl9rrMFf8eMLUQnljbW1zbEV+qRm5V7+eo40Vo023yUMFdcHnIA0cl 9Ut3xVN/EA5P/e72ucLuNx8x68aODZ2NqrcwXFBgdMJTkcbbc5sTlJWxqejmlWHpMw Y+kbzmlmIt+mARKgYNJY8XfYgib+yOxUY2rJNIe4= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 079DA6EC40 for ; Mon, 20 Sep 2021 11:34:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 079DA6EC40 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1mSEkV-0005WU-Ur; Mon, 20 Sep 2021 11:34:04 +0300 Date: Mon, 20 Sep 2021 11:32:38 +0300 To: sergos Message-ID: References: <369e050ce6799ca94ac08205fdbedad94b56ff87.1631170629.git.skaplun@tarantool.org> <47908C94-AB2E-4E82-AE4A-ADF6F58AA616@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <47908C94-AB2E-4E82-AE4A-ADF6F58AA616@tarantool.org> X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD91AE02D33A9C88A2FBA0FFC16CEFBFC694531AE86BFF036DF00894C459B0CD1B9A8F2077FBB412ED7F120E15A30B3681A5A8F4BA26F796B49906DE0852CB23FE4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7EC0B1A4921CAE631EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378B49D47CE295E66E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85360C1E9BA1425B2B00DC88120410477117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67393CE827C55B5F775ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A512ABADDB1C4CF84C2304A32172D0C67327CE7C291EA8AB1AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75DD5744CF7ED0C6846D6546786ADF492D5A0AA20F8A030721787CBDA4B9FA07AC2272C4C079A4C8AD93EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3480665FBD8F49180CBDBBF9FBED1C215083EC1EE647939E6D3D94A1ABE1F9836C49B4F05A6FE591501D7E09C32AA3244CF22EAA2CF25BB56982CA609EAA55D5CF3A76366E8A9DE7CAFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojsFc9NKou+3j+dNPVeHjcjg== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB433C8EDDD21CF0B67E5E67F850870FAFD8F465D15A528579AF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [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" 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 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 wrote: > > > > 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 > > > -- Best regards, Sergey Kaplun