打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Running LuaJIT

Running LuaJIT

LuaJIT has only a single stand-alone executable, called luajit onPOSIX systems or luajit.exe on Windows. It can be used to run simpleLua statements or whole Lua applications from the command line. It has aninteractive mode, too.

Command Line Options

The luajit stand-alone executable is just a slightly modifiedversion of the regular lua stand-alone executable.It supports the same basic options, too. luajit -hprints a short list of the available options. Please have a look at theLua manualfor details.

LuaJIT has some additional options:

-b[options] input output

This option saves or lists bytecode. The following additional optionsare accepted:

  • -l — Only list bytecode.
  • -s — Strip debug info (this is the default).
  • -g — Keep debug info.
  • -n name — Set module name (default: auto-detect from input name)
  • -t type — Set output file type (default: auto-detect from output name).
  • -a arch — Override architecture for object files (default: native).
  • -o os — Override OS for object files (default: native).
  • -e chunk — Use chunk string as input.
  • - (a single minus sign) — Use stdin as input and/or stdout as output.

The output file type is auto-detected from the extension of the outputfile name:

  • c — C source file, exported bytecode data.
  • h — C header file, static bytecode data.
  • obj or o — Object file, exported bytecode data(OS- and architecture-specific).
  • raw or any other extension — Raw bytecode file (portable).

Notes:

  • See also string.dump()for information on bytecode portability and compatibility.
  • A file in raw bytecode format is auto-detected and can be loaded likeany Lua source file. E.g. directly from the command line or withloadfile(), dofile() etc.
  • To statically embed the bytecode of a module in your application,generate an object file and just link it with your application.
  • On most ELF-based systems (e.g. Linux) you need to explicitly export theglobal symbols when linking your application, e.g. with: -Wl,-E
  • require() tries to load embedded bytecode data from exportedsymbols (in *.exe or lua51.dll on Windows) and fromshared libraries in package.cpath.

Typical usage examples:

luajit -b test.lua test.out                 # Save bytecode to test.outluajit -bg test.lua test.out                # Keep debug infoluajit -be "print('hello world')" test.out  # Save cmdline scriptluajit -bl test.lua                         # List to stdoutluajit -bl test.lua test.txt                # List to test.txtluajit -ble "print('hello world')"          # List cmdline scriptluajit -b test.lua test.obj                 # Generate object file# Link test.obj with your application and load it with require("test")

-j cmd[=arg[,arg...]]

This option performs a LuaJIT control command or activates one of theloadable extension modules. The command is first looked up in thejit.* library. If no matching function is found, a modulenamed jit.<cmd> is loaded and the start()function of the module is called with the specified arguments (ifany). The space between -j and cmd is optional.

Here are the available LuaJIT control commands:

  • -jon — Turns the JIT compiler on (default).
  • -joff — Turns the JIT compiler off (only use the interpreter).
  • -jflush — Flushes the whole cache of compiled code.
  • -jv — Shows verbose information about the progress of the JIT compiler.
  • -jdump — Dumps the code and structures used in various compiler stages.

The -jv and -jdump commands are extension moduleswritten in Lua. They are mainly used for debugging the JIT compileritself. For a description of their options and output format, pleaseread the comment block at the start of their source.They can be found in the lib directory of the sourcedistribution or installed under the jit directory. By defaultthis is /usr/local/share/luajit-2.0.2/jit on POSIXsystems.

-O[level]
-O[+]flag   -O-flag
-Oparam=value

This options allows fine-tuned control of the optimizations used bythe JIT compiler. This is mainly intended for debugging LuaJIT itself.Please note that the JIT compiler is extremely fast (we are talkingabout the microsecond to millisecond range). Disabling optimizationsdoesn't have any visible impact on its overhead, but usually generatescode that runs slower.

The first form sets an optimization level — this enables aspecific mix of optimization flags. -O0 turns off alloptimizations and higher numbers enable more optimizations. Omittingthe level (i.e. just -O) sets the default optimization level,which is -O3 in the current version.

The second form adds or removes individual optimization flags.The third form sets a parameter for the VM or the JIT compilerto a specific value.

You can either use this option multiple times (like -Ocse-O-dce -Ohotloop=10) or separate several settings with a comma(like -O+cse,-dce,hotloop=10). The settings are applied fromleft to right and later settings override earlier ones. You can freelymix the three forms, but note that setting an optimization leveloverrides all earlier flags.

Here are the available flags and at what optimization levels theyare enabled:

Flag-O1-O2-O3 
fold???Constant Folding, Simplifications and Reassociation
cse???Common-Subexpression Elimination
dce???Dead-Code Elimination
narrow ??Narrowing of numbers to integers
loop ??Loop Optimizations (code hoisting)
fwd  ?Load Forwarding (L2L) and Store Forwarding (S2L)
dse  ?Dead-Store Elimination
abc  ?Array Bounds Check Elimination
sink  ?Allocation/Store Sinking
fuse  ?Fusion of operands into instructions

Here are the parameters and their default settings:

ParameterDefault 
maxtrace1000Max. number of traces in the cache
maxrecord4000Max. number of recorded IR instructions
maxirconst500Max. number of IR constants of a trace
maxside100Max. number of side traces of a root trace
maxsnap500Max. number of snapshots for a trace
hotloop56Number of iterations to detect a hot loop or hot call
hotexit10Number of taken exits to start a side trace
tryside4Number of attempts to compile a side trace
instunroll4Max. unroll factor for instable loops
loopunroll15Max. unroll factor for loop ops in side traces
callunroll3Max. unroll factor for pseudo-recursive calls
recunroll2Min. unroll factor for true recursion
sizemcode32Size of each machine code area in KBytes (Windows: 64K)
maxmcode512Max. total size of all machine code areas in KBytes
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Understanding JIT compiler (just
Lua、Luajit、Python、Node.js和Java性能测试对比
C/C++中如何使用Luajit脚本
luajit FFI LUA脚本中怎样调用C自己定义的函数
技术的“体位”
What is eLua?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服