LuaJIT的LightUserdata使用问题

LuaJIT提供诱人的虚拟机代码加速,诸多开源软件使用它作为自己的解释器。[read more=”点击阅读更多” less=”收起阅读”]但由于LuaJIT在开发初期并没有一个尝试兼容所有CPU架构的设计框架,导致现在无法使用LightUserData这种简单的数据结构。LuaJIT自身在不断演进的同时,每个依赖它的开源社区都给出自己的规避方案。

那么,什么是LightUserData?

它是Lua中一个用来存储指针的轻量级数据类型。该数据类型在LUAJIT中不支持垃圾回收,它可以用来指向任一userdata数据类型。

lightuserdata通常用来指向lightdata所在地址。参看:https://www.lua.org/pil/28.5.html

API接口:
void lua_pushlightuserdata (lua_State *L, void *p)

文档说明如下:
Pushes a light userdata onto the stack.
Userdata represent C values in Lua. A light userdata represents a pointer. It is a value (like a number): you do not create it, it has no individual metatable, and it is not collected (as it was never created). A light userdata is equal to “any” light userdata with the same C address.

FireFox社区:
解决sparcx64 aarm64上跑firefox
https://bugzilla.mozilla.org/show_bug.cgi?id=1143022
https://bugzilla.mozilla.org/show_bug.cgi?id=1275204

Debian社区:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818616

openResty社区:
https://github.com/openresty/lua-nginx-module/issues/757
https://github.com/openresty/lua-nginx-module/issues/1152

LuaJIT社区中Issue跟踪:
https://github.com/LuaJIT/LuaJIT/issues/156

luaJIT官网版本发布列表:
http://www.luatex.org/svn/tags/0.98.1/source/libs/luajit/LuaJIT-src/doc/changes.html

官网对当前状态中GC64模式不支持>47bit的VA:
luajit-2.0/doc/status.html

做出的说明如下:
• LuaJIT on 64 bit systems provides a limited range of 47 bits for the legacy lightuserdata data type. This is only relevant on x64 systems which use the negative part of the virtual address space in user mode, e.g. Solaris/x64, and on ARM64 systems configured with a 48 bit or 52 bit VA. Avoid using lightuserdata to hold pointers that may point outside of that range, e.g. variables on the stack. In general, avoid this data type for new code and replace it with (much more performant) FFI bindings. FFI cdata pointers can address the full 64 bit range.

luaJIT beta3更新日志:
http://repo.or.cz/luajit-2.0.git/shortlog/refs/tags/v2.1.0-beta3

linaro某位同学的私人proposal:
https://github.com/zhongweiy/LuaJIT/commit/3fa648b6d8b7ecd2d06ce8397089f244564265bb
https://github.com/zhongweiy/LuaJIT/commit/dc3bd1626b4c28da7aa58da30bbd174e73badb65
https://www.freelists.org/post/luajit/fix-lightud-type-for-48bit-virtual-address
https://www.freelists.org/post/luajit/Proposals-for-fixing-light-userdata-issue-on-virtual-address-47-bits-platform
很遗憾的是这位同学临时的patch不能合入,Mike Pall 本人建议涉及到在ARM64上使用lightuserdata的代码全部使用FFI代替。这意味着已有的代码,如果想在ARM64上使用LUAJIT来加速,你不得不写C代码。对于一些大型项目,这将是个灾难。 :)

资料:
Linaro’s  effort to port LuaJIt to AARM64:  Sep 29, 2016

Server Ecosystem: Xen on ARM, from Big Iron to IoT & LuaJIT status on Aarch64 Speakers: Ryan Arnold, Steve Capper, Julien Grall, Zheng Xu
https://www.youtube.com/watch?v=ZTtCHF4FoqM&feature=youtu.be

Linaro&csico 着手解决ARM64生态问题,开始支持LuaJIT
https://collaborate.linaro.org/display/TCWGPUB/LuaJIT+for+ARM64
https://github.com/sindrom91/LuaJIT/commit/d63e0af3978f24e230cccc017ca98ed1653497de

Mike Pall开发arm64版本:
https://github.com/cbaylis/luajit-aarch64
[/read]

发表评论

电子邮件地址不会被公开。 必填项已用*标注