Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: sergos <sergos@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code.
Date: Mon, 20 Sep 2021 11:32:38 +0300
Message-ID: <YUhHJvZgPdMtCI1/@root> (raw)
In-Reply-To: <47908C94-AB2E-4E82-AE4A-ADF6F58AA616@tarantool.org>

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@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

  reply	other threads:[~2021-09-20  8:34 UTC|newest]

Thread overview: 13+ 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
2021-09-09  7:03 ` [Tarantool-patches] [PATCH luajit 2/3] Reorganize lightuserdata interning code Sergey Kaplun via Tarantool-patches
2021-09-15 15:30   ` sergos via Tarantool-patches
2021-09-20  8:32     ` Sergey Kaplun via Tarantool-patches [this message]
2021-09-20  9:37       ` sergos 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

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=YUhHJvZgPdMtCI1/@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergos@tarantool.org \
    --cc=skaplun@tarantool.org \
    /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

Tarantool development patches archive

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lists.tarantool.org/tarantool-patches/0 tarantool-patches/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tarantool-patches tarantool-patches/ https://lists.tarantool.org/tarantool-patches \
		tarantool-patches@dev.tarantool.org.
	public-inbox-index tarantool-patches

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git