[Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI.

sergos sergos at tarantool.org
Tue Jun 21 16:44:04 MSK 2022


Hi!

Thanks for the patch!

LGTM 

Sergos


> On 6 May 2022, at 07:53, Sergey Kaplun <skaplun at tarantool.org> wrote:
> 
> From: Mike Pall <mike>
> 
> Trace recording is NYI for the case of a struct with aggregate
> allocation.
> 
> This patch adds workaround for the zero-fill struct-of-NYI case.
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Related to tarantool/tarantool#4630
> Related to tarantool/tarantool#5885
> ---
> 
> Issues:
> * https://github.com/LuaJIT/LuaJIT/issues/672
> * https://github.com/tarantool/tarantool/issues/4630
> * https://github.com/tarantool/tarantool/issues/5885
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-672-cdata-allocation-recording-full-ci
> Tarantool PR: https://github.com/tarantool/tarantool/pull/7114
> 
> src/lj_crecord.c                              | 20 ++++++++++++-
> ...lj-672-cdata-allocation-recording.test.lua | 28 +++++++++++++++++++
> 2 files changed, 47 insertions(+), 1 deletion(-)
> create mode 100644 test/tarantool-tests/lj-672-cdata-allocation-recording.test.lua
> 
> diff --git a/src/lj_crecord.c b/src/lj_crecord.c
> index 59186dab..0d7b71f0 100644
> --- a/src/lj_crecord.c
> +++ b/src/lj_crecord.c
> @@ -1021,8 +1021,26 @@ static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
> 	crec_ct_tv(J, dc, dp, sp, sval);
>       }
>     } else if (ctype_isstruct(d->info)) {
> -      CTypeID fid = d->sib;
> +      CTypeID fid;
>       MSize i = 1;
> +      if (!J->base[1]) {  /* Handle zero-fill of struct-of-NYI. */
> +	fid = d->sib;
> +	while (fid) {
> +	  CType *df = ctype_get(cts, fid);
> +	  fid = df->sib;
> +	  if (ctype_isfield(df->info)) {
> +	    CType *dc;
> +	    if (!gcref(df->name)) continue;  /* Ignore unnamed fields. */
> +	    dc = ctype_rawchild(cts, df);  /* Field type. */
> +	    if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) ||
> +		  ctype_isenum(dc->info)))
> +	      goto special;
> +	  } else if (!ctype_isconstval(df->info)) {
> +	    goto special;
> +	  }
> +	}
> +      }
> +      fid = d->sib;
>       while (fid) {
> 	CType *df = ctype_get(cts, fid);
> 	fid = df->sib;
> diff --git a/test/tarantool-tests/lj-672-cdata-allocation-recording.test.lua b/test/tarantool-tests/lj-672-cdata-allocation-recording.test.lua
> new file mode 100644
> index 00000000..28ad61e5
> --- /dev/null
> +++ b/test/tarantool-tests/lj-672-cdata-allocation-recording.test.lua
> @@ -0,0 +1,28 @@
> +-- Disabled on *BSD due to #4819.
> +require('utils').skipcond(jit.os == 'BSD', 'Disabled due to #4819')
> +
> +local ffi = require('ffi')
> +local traceinfo = require('jit.util').traceinfo
> +
> +local tap = require('tap')
> +local test = tap.test('lj-672-cdata-allocation-recording')
> +test:plan(1)
> +
> +-- Structure with array.
> +ffi.cdef('struct my_struct {int a; char d[8];}')
> +
> +-- Be sure that we have no other traces.
> +jit.off()
> +jit.flush()
> +jit.on()
> +
> +jit.opt.start("hotloop=1")
> +local r
> +for i = 1, 4 do
> +  r = ffi.new('struct my_struct')
> +  r.a = i
> +end
> +
> +test:ok(traceinfo(1), 'new trace created')
> +
> +os.exit(test:check() and 0 or 1)
> -- 
> 2.34.1
> 



More information about the Tarantool-patches mailing list