Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] [PATCH 2/2] test/luajit-tap: Add unsink_64_kptr.test.lua
Date: Thu, 23 May 2019 20:49:03 +0300	[thread overview]
Message-ID: <20190523174903.GG11013@uranus> (raw)
In-Reply-To: <20190523174634.32314-1-gorcunov@gmail.com>

Backport of openrusty/luajit2-test-suite
commit 907c536c210ebe6a147861bb4433d28c0ebfc8cd

To test unsink 64 bit pointers

Part-of #4171
---
 test/luajit-tap/unsink_64_kptr.test.lua | 44 +++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100755 test/luajit-tap/unsink_64_kptr.test.lua

diff --git a/test/luajit-tap/unsink_64_kptr.test.lua b/test/luajit-tap/unsink_64_kptr.test.lua
new file mode 100755
index 000000000..89957637b
--- /dev/null
+++ b/test/luajit-tap/unsink_64_kptr.test.lua
@@ -0,0 +1,44 @@
+#!/usr/bin/env tarantool
+
+tap = require('tap')
+
+test = tap.test("232")
+test:plan(1)
+
+--- From: Thibault Charbonnier <thibaultcha@me.com>
+--- tests: ffi: added a test case unsinking a 64-bit pointer from a constant.
+---
+--- This test case reproduces the issue observed at:
+--- https://github.com/openresty/lua-resty-core/issues/232 and was
+--- contributed by @lukego and myself.
+---
+--- Co-authored-by: Luke Gorrie <lukego@gmail.com>
+---
+local ffi = require("ffi")
+
+local array = ffi.new("struct { int x; } [1]")
+
+-- This test forces the VM to unsink a pointer that was constructed
+-- from a constant. The IR will include a 'cnewi' instruction to
+-- allocate an FFI pointer object, the pointer value will be an IR
+-- constant, the allocation will be sunk, and the allocation will
+-- at some point be "unsunk" due to a reference in the snapshot for
+-- a taken exit.
+
+-- Note: JIT will recognize <array> as a "singleton" and allow its
+-- address to be inlined ("constified") instead of looking up the
+-- upvalue at runtime.
+
+local function fn(i)
+    local struct = array[0]     -- Load pointer that the JIT will constify.
+    if i == 1000 then end       -- Force trace exit when i==1000.
+    struct.x = 0                -- Ensure that 'struct' is live after exit.
+end
+
+-- Loop over the function to make it compile and take a trace exit
+-- during the final iteration.
+for i = 1, 1000 do
+    fn(i)
+end
+
+test:ok("PASS")
-- 
2.20.1

  parent reply	other threads:[~2019-05-23 17:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 17:46 [tarantool-patches] [PATCH 0/2] luajit2: bugfix: fixed a segfault when unsinking 64-bit pointers Cyrill Gorcunov
2019-05-23 17:48 ` [tarantool-patches] [PATCH 1/2] " Cyrill Gorcunov
2019-05-23 17:49 ` Cyrill Gorcunov [this message]
2019-05-23 17:50 ` [tarantool-patches] Re: [PATCH 0/2] luajit2: " Cyrill Gorcunov
2019-05-24 17:38 ` Alexander Turenko
2019-05-24 20:39   ` Cyrill Gorcunov
2019-05-27  7:12 ` Alexander Turenko
2019-05-28  2:02 ` Kirill Yukhin
2019-05-28 12:01   ` Alexander Turenko
2019-05-28 12:11     ` Cyrill Gorcunov
2019-05-28 12:14       ` Alexander Turenko

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=20190523174903.GG11013@uranus \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 2/2] test/luajit-tap: Add unsink_64_kptr.test.lua' \
    /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