Jump to content

LuaJIT

From Wikipedia, the free encyclopedia
LuaJIT
Original author(s)Mike Pall
Stable release
2.0.5 (later v2.1.ROLLING is also updated, e.g. in 2023) / May 1, 2017;7 years ago(2017-05-01)
Repositorygithub/LuaJIT/LuaJIT
Written inC,Lua
Operating systemUnix-like,MacOS,Windows,iOS,Android,PlayStation
Platformx86,X86-64,PowerPC,ARM,MIPS[1]
TypeJust-in-time compiler
LicenseMIT License[2]
Websiteluajit.org

LuaJITis atracing just-in-time compilerfor theLuaprogramming language. Mike Pall, a primary maintainer of the project had resigned in 2015, resorting only to occasional patching to the future 2.1 version.[3]

History

[edit]

The LuaJIT project was started in 2005 by developer Mike Pall, released under the MIT open source license.[4]

The second major release of the compiler, 2.0.0, featured major performance increases.[5]

The latest release, 2.0.5 is released in 2017. However, Mike Pall, the creator and maintainer recommends using the tip of the v2.1 branch, and does not believe in releases.[6]

Notable users

[edit]
  • CERN,for their Methodical Accelerator Design 'next-generation' software for describing and simulating particle accelerators[7]
  • OpenResty,a fork ofnginxwith Lua scripting[8]
  • Neovim, a text editor based on vim that allows the use of Lua for plugins and configuration[9]
  • Kong, a web API gateway[10]
  • Cloudflare,who use LuaJIT in theirweb application firewallservice[11]

Performance

[edit]

LuaJIT is often the fastest Lua runtime.[12]LuaJIT has also been named the fastest implementation of a dynamic programming language.[13][14]

LuaJIT includes aForeign Function Interfacecompatible withCdata structures. Its use is encouraged for numerical computation.[15]

Tracing

[edit]

LuaJIT is atracing just-in-time compiler.LuaJIT chooses loops and function calls as trace anchors to begin recording possiblehot paths.Function calls will require twice as many invocations to begin recording as a loop. Once LuaJIT begins recording, all control flow, including jumps and calls, are inlined to form a linear trace. All executed bytecode instructions are stored and incrementally converted into LuaJIT'sstatic single-assignmentintermediate representation.LuaJIT's trace compiler is often capable ofinliningand removingdispatchesfrom object orientation,operators,andtype modifications.[16]

Internal representation

[edit]

LuaJIT uses two types of internal representation. Astack-based bytecodeis used for theinterpreter,and astatic single-assignmentform is used for the just-in-time compiler. The interpreter bytecode is frequently patched by the JIT compiler, often to begin executing a compiled trace or to mark a segment of bytecode for causing too many trace aborts.[14]

-- Loop with if-statement

localx=0

fori=1,1e4do
x=x+11
ifi%10==0then-- if-statement
x=x+22
end
x=x+33
end
---- TRACE 1 start Ex.lua:5
---- TRACE 1 IR
0001 int SLOAD #2 CI
0002 > num SLOAD #1 T
0003 num ADD 0002 +11
0004 int MOD 0001 +10
0005 > int NE 0004 +0
0006 + num ADD 0003 +33
0007 + int ADD 0001 +1
0008 > int LE 0007 +10000
0009 ------ LOOP ------------
0010 num ADD 0006 +11
0011 int MOD 0007 +10
0012 > int NE 0011 +0
0013 + num ADD 0010 +33
0014 + int ADD 0007 +1
0015 > int LE 0014 +10000
0016 int PHI 0007 0014
0017 num PHI 0006 0013
---- TRACE 1 stop -> loop
---- TRACE 2 start 1/4 Ex.lua:8
---- TRACE 2 IR
0001 num SLOAD #1 PI
0002 int SLOAD #2 PI
0003 num ADD 0001 +22
0004 num ADD 0003 +33
0005 int ADD 0002 +1
0006 > int LE 0005 +10000
0007 num CONV 0005 num.int
---- TRACE 2 stop -> 1

Extensions

[edit]

LuaJIT adds several extensions to its base implementation, Lua 5.1, most of which do not break compatibility.[17]

  • "BitOp" for binary operations on unsigned 32-bit integers (these operations are also compiled by the just-in-time compiler)[18]
  • "CoCo", which allows the VM to be fully resumable across all contexts[19]
  • Aforeign function interface[20]
  • Portable bytecode (regardless of architecture, word size, or endianness, not version)[21]

DynASM

[edit]
DynASM
Developer(s)Mike Pall
Repository
Written inLua,C[22]
Platformx86,X86-64,PowerPC,ARM,MIPS
TypePreprocessor,Linker
LicenseMIT License[2]
Websiteluajit.org/dynasm.html

DynASM is a lightweightpreprocessorfor C that provides its own flavor ofinline assembler,independent of the C compiler. DynASM replaces assembly code in C files with runtime writes to a 'code buffer', such that a developer may generate and then evoke code at runtime from a C program. It was created for LuaJIT 1.0.0 to make developing the just-in-time compiler easier.[citation needed]

DynASM includes a bare-bones Cheader filewhich is used at compile time for logic the preprocessor generates. The actual preprocessor is written in Lua.

References

[edit]
  1. ^"LuaJIT".LuaJIT.Retrieved25 February2022.
  2. ^ab"LuaJIT/COPYRIGHT at v2.1 · LuaJIT/LuaJIT".GitHub.7 January 2022.
  3. ^"[ANN] Looking for new LuaJIT maintainers - luajit - FreeLists".freelists.org.Retrieved2023-03-29.
  4. ^"The LuaJIT Project".luajit.org.Retrieved2023-06-17.
  5. ^Pall, Mike."Re: [ANN] llvm-lua 1.0".lua-users.org.Retrieved25 February2022.
  6. ^"Project status - Issue #665 - LuaJIT/LuaJIT".GitHub.Retrieved3 February2023.
  7. ^Deniau, Laurent."Lua(Jit) for computing accelerator beam physics".CERN Document Server.CERN.Retrieved25 February2022.
  8. ^"OpenResty® - Official Site".openresty.org.
  9. ^"Lua - Neovim docs".neovim.io.Retrieved2024-05-07.
  10. ^"Kong/kong".GitHub.Kong. 25 February 2022.Retrieved25 February2022.
  11. ^"Helping to make Luajit faster".blog.cloudflare.19 October 2017.Retrieved25 February2022.
  12. ^"LuaJIT Performance".
  13. ^"Laurence Tratt: The Impact of Meta-Tracing on VM Design and Implementation".tratt.net.Retrieved2 March2022.
  14. ^abd'Andrea, Laurent (2019).Behavioural Analysis of Tracing JIT Compiler Embedded in the Methodical Accelerator Design Software(Thesis). CERN.Retrieved31 July2022.
  15. ^Pall, Mike."Tuning numerical computations for LuaJIT (was Re: [ANN] Sci-1.0-beta1) - luajit - FreeLists".freelists.org.
  16. ^Rottenkolber, Max. "Later Binding: Just-in-Time Compilation of a Younger Dynamic Programming Language." ELS. 2020
  17. ^"Extensions".LuaJIT.Retrieved25 February2022.
  18. ^"BitOp Semantics".LuaJIT.Retrieved25 February2022.
  19. ^"Coco - True C Coroutines".LuaJIT.Retrieved25 February2022.
  20. ^"FFI Library".LuaJIT.Retrieved25 February2022.
  21. ^"Extensions".luajit.org.Retrieved2022-08-25.
  22. ^"DynASM Features".DynASM.Retrieved25 February2022.