From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id EDBD16EC59; Tue, 9 Mar 2021 20:55:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EDBD16EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1615312516; bh=5eRAKe/OUWFRA++IOuC6tv2Ee3avLIuEJVJvcB9HlHs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=J3OgGarqz3gXvqQVL0iimyyY7A6ru59r2X5MIoXTfoRvc2Jm5j0Me7UAvTW3KTo+x TO21q7+m+h0h4sWa/CTyrL1lX9CfJhDQrlLvdRPmilautwLaPlgOAFTmj8tIFcKvEN uhSqqBd0MG9BaFWlcGeTHWtH+1HKycronn8FuR0g= Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 46B0E6EC59 for ; Tue, 9 Mar 2021 20:55:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 46B0E6EC59 Received: by smtp50.i.mail.ru with esmtpa (envelope-from ) id 1lJgZd-0000FK-2V; Tue, 09 Mar 2021 20:55:13 +0300 To: Sergey Ostanevich , Igor Munkin Date: Tue, 9 Mar 2021 20:54:22 +0300 Message-Id: <20210309175422.25432-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D3134714A9BDB69B6D9CBB8C4C1E2C2453F3F16C3D6F3AC500894C459B0CD1B9D97BD4E82C5C559F4F5C4D27C2C613D4A0A5A71D0F62CC0D68A59ACE1A350C76 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE787D390A33DAA1DB5EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637680B37D8C6EC627A8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC230CB4B11EA24BF7F0F01F7F4E74DD9DA9EB57D61653FE0E389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0ECC8AC47CD0EDEFF8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B64854413538E1713FCC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FCB07C9E286C61B7F975ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E7352B32DCB92A8600C6C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C1F4A82545730C76187F3B7267FFCEDBF7D4DA2F30AB775BA9C2B6934AE262D3EE7EAB7254005DCED3FA81F2A1B9C552D1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B06CE7B4E551862B828E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349DAEDEF7DE8FDCFAC1256DA5DAC265470671FAC3E76E8A7929D2F724DA58F0EC533EAF88CB59F7D51D7E09C32AA3244C7D30C967964B782DD0D65A283C6D7824F2F5F14F68F1805B927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojsR8tyFmO15PMtqLgmqjgyQ== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB48D9DF3B8D1C91D6DACDC241113A5094D0FF2D94DDA5A807DF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] memprof: report stack resizing as internal event X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Resizing of the Lua stack is not reported as internal allocation. Moreover, it may lead to crash inside Lua or FF frames. Profiler performs reallocation first and after reports corresponding event. When the stack is resized for local function arguments, the link to previous frame is invalid in the cause of reallocation. Therefore, assertion in `debug_framepc()` failes, because of invalid function reference at previous frame. Resolves tarantool/tarantool#5842 Follows up tarantool/tarantool#5442 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-5842-memprof-core-on-resizestack Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-5842-memprof-core-on-resizestack Issue: https://github.com/tarantool/tarantool/issues/5842 src/lj_state.c | 6 ++++++ .../misclib-memprof-lapi.test.lua | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lj_state.c b/src/lj_state.c index 1ed79a5..ea9abd4 100644 --- a/src/lj_state.c +++ b/src/lj_state.c @@ -64,7 +64,11 @@ static void resizestack(lua_State *L, MSize n) MSize oldsize = L->stacksize; MSize realsize = n + 1 + LJ_STACK_EXTRA; GCobj *up; + int32_t old_vmstate = G(L)->vmstate; + lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1); + + setvmstate(G(L), INTERP); st = (TValue *)lj_mem_realloc(L, tvref(L->stack), (MSize)(oldsize*sizeof(TValue)), (MSize)(realsize*sizeof(TValue))); @@ -80,6 +84,8 @@ static void resizestack(lua_State *L, MSize n) L->top = (TValue *)((char *)L->top + delta); for (up = gcref(L->openupval); up != NULL; up = gcnext(up)) setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta)); + + G(L)->vmstate = old_vmstate; } /* Relimit stack after error, in case the limit was overdrawn. */ diff --git a/test/tarantool-tests/misclib-memprof-lapi.test.lua b/test/tarantool-tests/misclib-memprof-lapi.test.lua index 1c36c8a..93cc348 100644 --- a/test/tarantool-tests/misclib-memprof-lapi.test.lua +++ b/test/tarantool-tests/misclib-memprof-lapi.test.lua @@ -125,5 +125,23 @@ test:ok(check_alloc_report(alloc, 25, 18, 100)) -- Collect all previous allocated objects. test:ok(free.INTERNAL.num == 102) +-- Test for https://github.com/tarantool/tarantool/issues/5842. +-- We do not interested in report itself. +misc.memprof.start("/dev/null") +-- We need to cause stack resize for local variables at function +-- call. Let's create a new coroutine (all slots are free). +-- It has 1 slot for dummy frame + 39 free slots + 5 extra slots +-- (so-called red zone) + 2 * LJ_FR2 slots. So 50 local variables +-- is enough. +local payload_str = "" +for i = 1, 50 do + payload_str = payload_str..("local v%d = %d\n"):format(i, i) +end +local f, errmsg = loadstring(payload_str) +assert(f, errmsg) +local co = coroutine.create(f) +coroutine.resume(co) +misc.memprof.stop() + jit.on() os.exit(test:check() and 0 or 1) -- 2.28.0