Initialize uv->immutable for upvalues of loaded chunks.
[luajit-2.0.git] / doc / running.html
blob49e2d177fc4e9ab74b07466adb2afa230c76b31d
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-2016, 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;
15 tr.opthead td {
16 font-weight: bold;
18 td.flag_name {
19 width: 4em;
21 td.flag_level {
22 width: 2em;
23 text-align: center;
25 td.param_name {
26 width: 6em;
28 td.param_default {
29 width: 4em;
30 text-align: right;
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="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
46 </li><li>
47 <a href="install.html">Installation</a>
48 </li><li>
49 <a class="current" href="running.html">Running</a>
50 </li></ul>
51 </li><li>
52 <a href="extensions.html">Extensions</a>
53 <ul><li>
54 <a href="ext_ffi.html">FFI Library</a>
55 <ul><li>
56 <a href="ext_ffi_tutorial.html">FFI Tutorial</a>
57 </li><li>
58 <a href="ext_ffi_api.html">ffi.* API</a>
59 </li><li>
60 <a href="ext_ffi_semantics.html">FFI Semantics</a>
61 </li></ul>
62 </li><li>
63 <a href="ext_jit.html">jit.* Library</a>
64 </li><li>
65 <a href="ext_c_api.html">Lua/C API</a>
66 </li></ul>
67 </li><li>
68 <a href="status.html">Status</a>
69 <ul><li>
70 <a href="changes.html">Changes</a>
71 </li></ul>
72 </li><li>
73 <a href="faq.html">FAQ</a>
74 </li><li>
75 <a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
76 </li><li>
77 <a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
78 </li><li>
79 <a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
80 </li></ul>
81 </div>
82 <div id="main">
83 <p>
84 LuaJIT has only a single stand-alone executable, called <tt>luajit</tt> on
85 POSIX systems or <tt>luajit.exe</tt> on Windows. It can be used to run simple
86 Lua statements or whole Lua applications from the command line. It has an
87 interactive mode, too.
88 </p>
90 <h2 id="options">Command Line Options</h2>
91 <p>
92 The <tt>luajit</tt> stand-alone executable is just a slightly modified
93 version of the regular <tt>lua</tt> stand-alone executable.
94 It supports the same basic options, too. <tt>luajit&nbsp;-h</tt>
95 prints a short list of the available options. Please have a look at the
96 <a href="http://www.lua.org/manual/5.1/manual.html#6"><span class="ext">&raquo;</span>&nbsp;Lua manual</a>
97 for details.
98 </p>
99 <p>
100 LuaJIT has some additional options:
101 </p>
103 <h3 id="opt_b"><tt>-b[options] input output</tt></h3>
105 This option saves or lists bytecode. The following additional options
106 are accepted:
107 </p>
108 <ul>
109 <li><tt>-l</tt> &mdash; Only list bytecode.</li>
110 <li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>
111 <li><tt>-g</tt> &mdash; Keep debug info.</li>
112 <li><tt>-n name</tt> &mdash; Set module name (default: auto-detect from input name)</li>
113 <li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>
114 <li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>
115 <li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li>
116 <li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>
117 <li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>
118 </ul>
120 The output file type is auto-detected from the extension of the output
121 file name:
122 </p>
123 <ul>
124 <li><tt>c</tt> &mdash; C source file, exported bytecode data.</li>
125 <li><tt>h</tt> &mdash; C header file, static bytecode data.</li>
126 <li><tt>obj</tt> or <tt>o</tt> &mdash; Object file, exported bytecode data
127 (OS- and architecture-specific).</li>
128 <li><tt>raw</tt> or any other extension &mdash; Raw bytecode file (portable).
129 </ul>
131 Notes:
132 </p>
133 <ul>
134 <li>See also <a href="extensions.html#string_dump">string.dump()</a>
135 for information on bytecode portability and compatibility.</li>
136 <li>A file in raw bytecode format is auto-detected and can be loaded like
137 any Lua source file. E.g. directly from the command line or with
138 <tt>loadfile()</tt>, <tt>dofile()</tt> etc.</li>
139 <li>To statically embed the bytecode of a module in your application,
140 generate an object file and just link it with your application.</li>
141 <li>On most ELF-based systems (e.g. Linux) you need to explicitly export the
142 global symbols when linking your application, e.g. with: <tt>-Wl,-E</tt></li>
143 <li><tt>require()</tt> tries to load embedded bytecode data from exported
144 symbols (in <tt>*.exe</tt> or <tt>lua51.dll</tt> on Windows) and from
145 shared libraries in <tt>package.cpath</tt>.</li>
146 </ul>
148 Typical usage examples:
149 </p>
150 <pre class="code">
151 luajit -b test.lua test.out # Save bytecode to test.out
152 luajit -bg test.lua test.out # Keep debug info
153 luajit -be "print('hello world')" test.out # Save cmdline script
155 luajit -bl test.lua # List to stdout
156 luajit -bl test.lua test.txt # List to test.txt
157 luajit -ble "print('hello world')" # List cmdline script
159 luajit -b test.lua test.obj # Generate object file
160 # Link test.obj with your application and load it with require("test")
161 </pre>
163 <h3 id="opt_j"><tt>-j cmd[=arg[,arg...]]</tt></h3>
165 This option performs a LuaJIT control command or activates one of the
166 loadable extension modules. The command is first looked up in the
167 <tt>jit.*</tt> library. If no matching function is found, a module
168 named <tt>jit.&lt;cmd&gt;</tt> is loaded and the <tt>start()</tt>
169 function of the module is called with the specified arguments (if
170 any). The space between <tt>-j</tt> and <tt>cmd</tt> is optional.
171 </p>
173 Here are the available LuaJIT control commands:
174 </p>
175 <ul>
176 <li id="j_on"><tt>-jon</tt> &mdash; Turns the JIT compiler on (default).</li>
177 <li id="j_off"><tt>-joff</tt> &mdash; Turns the JIT compiler off (only use the interpreter).</li>
178 <li id="j_flush"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>
179 <li id="j_v"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>
180 <li id="j_dump"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>
181 </ul>
183 The <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules
184 written in Lua. They are mainly used for debugging the JIT compiler
185 itself. For a description of their options and output format, please
186 read the comment block at the start of their source.
187 They can be found in the <tt>lib</tt> directory of the source
188 distribution or installed under the <tt>jit</tt> directory. By default
189 this is <tt>/usr/local/share/luajit-2.0.4/jit</tt> on POSIX
190 systems.
191 </p>
193 <h3 id="opt_O"><tt>-O[level]</tt><br>
194 <tt>-O[+]flag</tt>&nbsp;&nbsp;&nbsp;<tt>-O-flag</tt><br>
195 <tt>-Oparam=value</tt></h3>
197 This options allows fine-tuned control of the optimizations used by
198 the JIT compiler. This is mainly intended for debugging LuaJIT itself.
199 Please note that the JIT compiler is extremely fast (we are talking
200 about the microsecond to millisecond range). Disabling optimizations
201 doesn't have any visible impact on its overhead, but usually generates
202 code that runs slower.
203 </p>
205 The first form sets an optimization level &mdash; this enables a
206 specific mix of optimization flags. <tt>-O0</tt> turns off all
207 optimizations and higher numbers enable more optimizations. Omitting
208 the level (i.e. just <tt>-O</tt>) sets the default optimization level,
209 which is <tt>-O3</tt> in the current version.
210 </p>
212 The second form adds or removes individual optimization flags.
213 The third form sets a parameter for the VM or the JIT compiler
214 to a specific value.
215 </p>
217 You can either use this option multiple times (like <tt>-Ocse
218 -O-dce -Ohotloop=10</tt>) or separate several settings with a comma
219 (like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from
220 left to right and later settings override earlier ones. You can freely
221 mix the three forms, but note that setting an optimization level
222 overrides all earlier flags.
223 </p>
225 Here are the available flags and at what optimization levels they
226 are enabled:
227 </p>
228 <table class="opt">
229 <tr class="opthead">
230 <td class="flag_name">Flag</td>
231 <td class="flag_level">-O1</td>
232 <td class="flag_level">-O2</td>
233 <td class="flag_level">-O3</td>
234 <td class="flag_desc">&nbsp;</td>
235 </tr>
236 <tr class="odd separate">
237 <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>
238 <tr class="even">
239 <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>
240 <tr class="odd">
241 <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>
242 <tr class="even">
243 <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>
244 <tr class="odd">
245 <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>
246 <tr class="even">
247 <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>
248 <tr class="odd">
249 <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>
250 <tr class="even">
251 <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>
252 <tr class="odd">
253 <td class="flag_name">sink</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Allocation/Store Sinking</td></tr>
254 <tr class="even">
255 <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>
256 </table>
258 Here are the parameters and their default settings:
259 </p>
260 <table class="opt">
261 <tr class="opthead">
262 <td class="param_name">Parameter</td>
263 <td class="param_default">Default</td>
264 <td class="param_desc">&nbsp;</td>
265 </tr>
266 <tr class="odd separate">
267 <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>
268 <tr class="even">
269 <td class="param_name">maxrecord</td><td class="param_default">4000</td><td class="param_desc">Max. number of recorded IR instructions</td></tr>
270 <tr class="odd">
271 <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>
272 <tr class="even">
273 <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>
274 <tr class="odd">
275 <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>
276 <tr class="even separate">
277 <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>
278 <tr class="odd">
279 <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>
280 <tr class="even">
281 <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>
282 <tr class="odd separate">
283 <td class="param_name">instunroll</td><td class="param_default">4</td><td class="param_desc">Max. unroll factor for instable loops</td></tr>
284 <tr class="even">
285 <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>
286 <tr class="odd">
287 <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>
288 <tr class="even">
289 <td class="param_name">recunroll</td><td class="param_default">2</td><td class="param_desc">Min. unroll factor for true recursion</td></tr>
290 <tr class="odd separate">
291 <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>
292 <tr class="even">
293 <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>
294 </table>
295 <br class="flush">
296 </div>
297 <div id="foot">
298 <hr class="hide">
299 Copyright &copy; 2005-2016 Mike Pall
300 <span class="noprint">
301 &middot;
302 <a href="contact.html">Contact</a>
303 </span>
304 </div>
305 </body>
306 </html>