Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI.
@ 2022-05-06  4:53 Sergey Kaplun via Tarantool-patches
  2022-06-21 13:44 ` sergos via Tarantool-patches
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2022-05-06  4:53 UTC (permalink / raw)
  To: Sergey Ostanevich, Igor Munkin; +Cc: tarantool-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI.
  2022-05-06  4:53 [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI Sergey Kaplun via Tarantool-patches
@ 2022-06-21 13:44 ` sergos via Tarantool-patches
  2022-06-29  8:02 ` Igor Munkin via Tarantool-patches
  2022-06-30 12:11 ` Igor Munkin via Tarantool-patches
  2 siblings, 0 replies; 4+ messages in thread
From: sergos via Tarantool-patches @ 2022-06-21 13:44 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Hi!

Thanks for the patch!

LGTM 

Sergos


> On 6 May 2022, at 07:53, Sergey Kaplun <skaplun@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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI.
  2022-05-06  4:53 [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI Sergey Kaplun via Tarantool-patches
  2022-06-21 13:44 ` sergos via Tarantool-patches
@ 2022-06-29  8:02 ` Igor Munkin via Tarantool-patches
  2022-06-30 12:11 ` Igor Munkin via Tarantool-patches
  2 siblings, 0 replies; 4+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2022-06-29  8:02 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for the patch! LGTM, with a little tweak for commit message:
| FFI: Handle zero-fill of struct-of-NYI.
|
| (cherry picked from ad65934fa08a65bfb0eb9528731a4394842cc173)
|
| Trace recording is aborted with NYI reason for the case of a struct with
| aggregate allocation. The general solution is way too complex due to
| heterogeneous initialization of the structure. However, zero-fill case
| requires nothing but "memset"-like initialization of GCcdata payload.
|
| As a result of this patch workaround for the zero-fill structures is
| introduced.
|
| Sergey Kaplun:
| * added the description and the test for the problem
|
| Part of tarantool/tarantool#6548
| Related to tarantool/tarantool#4630
| Related to tarantool/tarantool#5885

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI.
  2022-05-06  4:53 [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI Sergey Kaplun via Tarantool-patches
  2022-06-21 13:44 ` sergos via Tarantool-patches
  2022-06-29  8:02 ` Igor Munkin via Tarantool-patches
@ 2022-06-30 12:11 ` Igor Munkin via Tarantool-patches
  2 siblings, 0 replies; 4+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2022-06-30 12:11 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

I've checked the patch into all long-term branches in tarantool/luajit
and bumped a new version in master, 2.10 and 1.10.

On 06.05.22, Sergey Kaplun 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
> 

<snipped>

> -- 
> 2.34.1
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-30 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06  4:53 [Tarantool-patches] [PATCH luajit] FFI: Handle zero-fill of struct-of-NYI Sergey Kaplun via Tarantool-patches
2022-06-21 13:44 ` sergos via Tarantool-patches
2022-06-29  8:02 ` Igor Munkin via Tarantool-patches
2022-06-30 12:11 ` Igor Munkin via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox