From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Igor Munkin <imun@tarantool.org>,
Sergey Ostanevich <sergos@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code.
Date: Thu, 9 Sep 2021 10:03:18 +0300 [thread overview]
Message-ID: <369e050ce6799ca94ac08205fdbedad94b56ff87.1631170629.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1631170629.git.skaplun@tarantool.org>
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
next prev parent reply other threads:[~2021-09-09 7:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 7:03 [Tarantool-patches] [PATCH luajit 0/3] Follow-up fixes for full 64-bit lightuserdata interning Sergey Kaplun via Tarantool-patches
2021-09-09 7:03 ` [Tarantool-patches] [PATCH luajit 1/3] test: fix path storage for non-concatable objects Sergey Kaplun via Tarantool-patches
2021-09-15 15:30 ` sergos via Tarantool-patches
2021-09-20 8:28 ` Sergey Kaplun via Tarantool-patches
2021-09-20 9:37 ` sergos via Tarantool-patches
2022-06-28 15:41 ` Igor Munkin via Tarantool-patches
2021-09-09 7:03 ` Sergey Kaplun via Tarantool-patches [this message]
2021-09-15 15:30 ` [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code sergos via Tarantool-patches
2021-09-20 8:32 ` Sergey Kaplun via Tarantool-patches
2021-09-20 9:37 ` sergos via Tarantool-patches
2022-06-28 15:42 ` Igor Munkin via Tarantool-patches
2021-09-09 7:03 ` [Tarantool-patches] [PATCH luajit 3/3] Avoid conflict between 64 bit lightuserdata and ITERN key Sergey Kaplun via Tarantool-patches
2021-09-15 15:31 ` sergos via Tarantool-patches
2021-09-20 8:38 ` Sergey Kaplun via Tarantool-patches
2021-09-20 9:37 ` sergos via Tarantool-patches
2022-06-29 20:20 ` Igor Munkin via Tarantool-patches
2022-06-30 12:11 ` [Tarantool-patches] [PATCH luajit 0/3] Follow-up fixes for full 64-bit lightuserdata interning Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=369e050ce6799ca94ac08205fdbedad94b56ff87.1631170629.git.skaplun@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imun@tarantool.org \
--cc=sergos@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox