running.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Running LuaJIT</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta name="Author" content="Mike Pall">
  7. <meta name="Copyright" content="Copyright (C) 2005-2011, Mike Pall">
  8. <meta name="Language" content="en">
  9. <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
  10. <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
  11. <style type="text/css">
  12. table.opt {
  13. line-height: 1.2;
  14. }
  15. tr.opthead td {
  16. font-weight: bold;
  17. }
  18. td.flag_name {
  19. width: 4em;
  20. }
  21. td.flag_level {
  22. width: 2em;
  23. text-align: center;
  24. }
  25. td.param_name {
  26. width: 6em;
  27. }
  28. td.param_default {
  29. width: 4em;
  30. text-align: right;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div id="site">
  36. <a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
  37. </div>
  38. <div id="head">
  39. <h1>Running LuaJIT</h1>
  40. </div>
  41. <div id="nav">
  42. <ul><li>
  43. <a href="luajit.html">LuaJIT</a>
  44. <ul><li>
  45. <a href="install.html">Installation</a>
  46. </li><li>
  47. <a class="current" href="running.html">Running</a>
  48. </li></ul>
  49. </li><li>
  50. <a href="extensions.html">Extensions</a>
  51. <ul><li>
  52. <a href="ext_ffi.html">FFI Library</a>
  53. <ul><li>
  54. <a href="ext_ffi_tutorial.html">FFI Tutorial</a>
  55. </li><li>
  56. <a href="ext_ffi_api.html">ffi.* API</a>
  57. </li><li>
  58. <a href="ext_ffi_semantics.html">FFI Semantics</a>
  59. </li></ul>
  60. </li><li>
  61. <a href="ext_jit.html">jit.* Library</a>
  62. </li><li>
  63. <a href="ext_c_api.html">Lua/C API</a>
  64. </li></ul>
  65. </li><li>
  66. <a href="status.html">Status</a>
  67. <ul><li>
  68. <a href="changes.html">Changes</a>
  69. </li></ul>
  70. </li><li>
  71. <a href="faq.html">FAQ</a>
  72. </li><li>
  73. <a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
  74. </li><li>
  75. <a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
  76. </li></ul>
  77. </div>
  78. <div id="main">
  79. <p>
  80. LuaJIT has only a single stand-alone executable, called <tt>luajit</tt> on
  81. POSIX systems or <tt>luajit.exe</tt> on Windows. It can be used to run simple
  82. Lua statements or whole Lua applications from the command line. It has an
  83. interactive mode, too.
  84. </p>
  85. <p class="indent" style="color: #c00000;">
  86. Note: the beta test releases only install under the versioned name on
  87. POSIX systems (to avoid overwriting a previous version). You either need
  88. to type <tt>luajit-2.0.0-beta8</tt> to start it or create a symlink
  89. with a command like this:
  90. </p>
  91. <pre class="code" style="color: #c00000;">
  92. sudo ln -sf luajit-2.0.0-beta8&nbsp;/usr/local/bin/luajit
  93. </pre>
  94. <p>
  95. Unlike previous versions <b>optimization is turned on by default</b> in
  96. LuaJIT 2.0!<br>It's no longer necessary to use <tt>luajit&nbsp;-O</tt>.
  97. </p>
  98. <h2 id="options">Command Line Options</h2>
  99. <p>
  100. The <tt>luajit</tt> stand-alone executable is just a slightly modified
  101. version of the regular <tt>lua</tt> stand-alone executable.
  102. It supports the same basic options, too. <tt>luajit&nbsp;-h</tt>
  103. prints a short list of the available options. Please have a look at the
  104. <a href="http://www.lua.org/manual/5.1/manual.html#6"><span class="ext">&raquo;</span>&nbsp;Lua manual</a>
  105. for details.
  106. </p>
  107. <p>
  108. LuaJIT has some additional options:
  109. </p>
  110. <h3 id="opt_b"><tt>-b[options] input output</tt></h3>
  111. <p>
  112. This option saves or lists bytecode. The following additional options
  113. are accepted:
  114. </p>
  115. <ul>
  116. <li><tt>-l</tt> &mdash; Only list bytecode.</li>
  117. <li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>
  118. <li><tt>-g</tt> &mdash; Keep debug info.</li>
  119. <li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>
  120. <li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>
  121. </ul>
  122. <p>
  123. Typical usage examples:
  124. </p>
  125. <pre class="code">
  126. luajit -b test.lua test.out # Save to test.out
  127. luajit -bg test.lua test.out # Keep debug info
  128. luajit -be "print('hello world')" test.out # Save cmdline script
  129. luajit -bl test.lua # List to stdout
  130. luajit -bl test.lua test.txt # List to test.txt
  131. luajit -ble "print('hello world')" # List cmdline script
  132. </pre>
  133. <p>
  134. Note: A file in bytecode format is auto-detected and can be loaded like
  135. any Lua source file. E.g. directly from the command line or with
  136. <tt>loadfile()</tt>, <tt>dofile()</tt> etc. See also
  137. <a href="extensions.html#string_dump">string.dump()</a> for information
  138. on bytecode portability and compatibility.
  139. </p>
  140. <h3 id="opt_j"><tt>-j cmd[=arg[,arg...]]</tt></h3>
  141. <p>
  142. This option performs a LuaJIT control command or activates one of the
  143. loadable extension modules. The command is first looked up in the
  144. <tt>jit.*</tt> library. If no matching function is found, a module
  145. named <tt>jit.&lt;cmd&gt;</tt> is loaded and the <tt>start()</tt>
  146. function of the module is called with the specified arguments (if
  147. any). The space between <tt>-j</tt> and <tt>cmd</tt> is optional.
  148. </p>
  149. <p>
  150. Here are the available LuaJIT control commands:
  151. </p>
  152. <ul>
  153. <li id="j_on"><tt>-jon</tt> &mdash; Turns the JIT compiler on (default).</li>
  154. <li id="j_off"><tt>-joff</tt> &mdash; Turns the JIT compiler off (only use the interpreter).</li>
  155. <li id="j_flush"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>
  156. <li id="j_v"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>
  157. <li id="j_dump"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>
  158. </ul>
  159. <p>
  160. The <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules
  161. written in Lua. They are mainly used for debugging the JIT compiler
  162. itself. For a description of their options and output format, please
  163. read the comment block at the start of their source.
  164. They can be found in the <tt>lib</tt> directory of the source
  165. distribution or installed under the <tt>jit</tt> directory. By default
  166. this is <tt>/usr/local/share/luajit-2.0.0-beta8/jit</tt> on POSIX
  167. systems.
  168. </p>
  169. <h3 id="opt_O"><tt>-O[level]</tt><br>
  170. <tt>-O[+]flag</tt>&nbsp;&nbsp;&nbsp;<tt>-O-flag</tt><br>
  171. <tt>-Oparam=value</tt></h3>
  172. <p>
  173. This options allows fine-tuned control of the optimizations used by
  174. the JIT compiler. This is mainly intended for debugging LuaJIT itself.
  175. Please note that the JIT compiler is extremely fast (we are talking
  176. about the microsecond to millisecond range). Disabling optimizations
  177. doesn't have any visible impact on its overhead, but usually generates
  178. code that runs slower.
  179. </p>
  180. <p>
  181. The first form sets an optimization level &mdash; this enables a
  182. specific mix of optimization flags. <tt>-O0</tt> turns off all
  183. optimizations and higher numbers enable more optimizations. Omitting
  184. the level (i.e. just <tt>-O</tt>) sets the default optimization level,
  185. which is <tt>-O3</tt> in the current version.
  186. </p>
  187. <p>
  188. The second form adds or removes individual optimization flags.
  189. The third form sets a parameter for the VM or the JIT compiler
  190. to a specific value.
  191. </p>
  192. <p>
  193. You can either use this option multiple times (like <tt>-Ocse
  194. -O-dce -Ohotloop=10</tt>) or separate several settings with a comma
  195. (like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from
  196. left to right and later settings override earlier ones. You can freely
  197. mix the three forms, but note that setting an optimization level
  198. overrides all earlier flags.
  199. </p>
  200. <p>
  201. Here are the available flags and at what optimization levels they
  202. are enabled:
  203. </p>
  204. <table class="opt">
  205. <tr class="opthead">
  206. <td class="flag_name">Flag</td>
  207. <td class="flag_level">-O1</td>
  208. <td class="flag_level">-O2</td>
  209. <td class="flag_level">-O3</td>
  210. <td class="flag_desc">&nbsp;</td>
  211. </tr>
  212. <tr class="odd separate">
  213. <td class="flag_name">fold</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Constant Folding, Simplifications and Reassociation</td></tr>
  214. <tr class="even">
  215. <td class="flag_name">cse</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Common-Subexpression Elimination</td></tr>
  216. <tr class="odd">
  217. <td class="flag_name">dce</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Dead-Code Elimination</td></tr>
  218. <tr class="even">
  219. <td class="flag_name">narrow</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Narrowing of numbers to integers</td></tr>
  220. <tr class="odd">
  221. <td class="flag_name">loop</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Loop Optimizations (code hoisting)</td></tr>
  222. <tr class="even">
  223. <td class="flag_name">fwd</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Load Forwarding (L2L) and Store Forwarding (S2L)</td></tr>
  224. <tr class="odd">
  225. <td class="flag_name">dse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Dead-Store Elimination</td></tr>
  226. <tr class="even">
  227. <td class="flag_name">abc</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Array Bounds Check Elimination</td></tr>
  228. <tr class="odd">
  229. <td class="flag_name">fuse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Fusion of operands into instructions</td></tr>
  230. </table>
  231. <p>
  232. Here are the parameters and their default settings:
  233. </p>
  234. <table class="opt">
  235. <tr class="opthead">
  236. <td class="param_name">Parameter</td>
  237. <td class="param_default">Default</td>
  238. <td class="param_desc">&nbsp;</td>
  239. </tr>
  240. <tr class="odd separate">
  241. <td class="param_name">maxtrace</td><td class="param_default">1000</td><td class="param_desc">Max. number of traces in the cache</td></tr>
  242. <tr class="even">
  243. <td class="param_name">maxrecord</td><td class="param_default">4000</td><td class="param_desc">Max. number of recorded IR instructions</td></tr>
  244. <tr class="odd">
  245. <td class="param_name">maxirconst</td><td class="param_default">500</td><td class="param_desc">Max. number of IR constants of a trace</td></tr>
  246. <tr class="even">
  247. <td class="param_name">maxside</td><td class="param_default">100</td><td class="param_desc">Max. number of side traces of a root trace</td></tr>
  248. <tr class="odd">
  249. <td class="param_name">maxsnap</td><td class="param_default">500</td><td class="param_desc">Max. number of snapshots for a trace</td></tr>
  250. <tr class="even separate">
  251. <td class="param_name">hotloop</td><td class="param_default">56</td><td class="param_desc">Number of iterations to detect a hot loop or hot call</td></tr>
  252. <tr class="odd">
  253. <td class="param_name">hotexit</td><td class="param_default">10</td><td class="param_desc">Number of taken exits to start a side trace</td></tr>
  254. <tr class="even">
  255. <td class="param_name">tryside</td><td class="param_default">4</td><td class="param_desc">Number of attempts to compile a side trace</td></tr>
  256. <tr class="odd separate">
  257. <td class="param_name">instunroll</td><td class="param_default">4</td><td class="param_desc">Max. unroll factor for instable loops</td></tr>
  258. <tr class="even">
  259. <td class="param_name">loopunroll</td><td class="param_default">15</td><td class="param_desc">Max. unroll factor for loop ops in side traces</td></tr>
  260. <tr class="odd">
  261. <td class="param_name">callunroll</td><td class="param_default">3</td><td class="param_desc">Max. unroll factor for pseudo-recursive calls</td></tr>
  262. <tr class="even">
  263. <td class="param_name">recunroll</td><td class="param_default">2</td><td class="param_desc">Min. unroll factor for true recursion</td></tr>
  264. <tr class="odd separate">
  265. <td class="param_name">sizemcode</td><td class="param_default">32</td><td class="param_desc">Size of each machine code area in KBytes (Windows: 64K)</td></tr>
  266. <tr class="even">
  267. <td class="param_name">maxmcode</td><td class="param_default">512</td><td class="param_desc">Max. total size of all machine code areas in KBytes</td></tr>
  268. </table>
  269. <br class="flush">
  270. </div>
  271. <div id="foot">
  272. <hr class="hide">
  273. Copyright &copy; 2005-2011 Mike Pall
  274. <span class="noprint">
  275. &middot;
  276. <a href="contact.html">Contact</a>
  277. </span>
  278. </div>
  279. </body>
  280. </html>