summaryrefslogtreecommitdiff
path: root/pod/luajit-2.1/running.pod
blob: 89af53e753b777afdb72b63b942e221cb9018996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
=pod

LuaJIT

=head1 Running LuaJIT

=over

=item * LuaJIT

=over

=item * Download E<rchevron>

=item * Installation

=item * Running

=back

=item * Extensions

=over

=item * FFI Library

=over

=item * FFI Tutorial

=item * ffi.* API

=item * FFI Semantics

=back

=item * jit.* Library

=item * Lua/C API

=item * Profiler

=back

=item * Status

=over

=item * Changes

=back

=item * FAQ

=item * Performance E<rchevron>

=item * Wiki E<rchevron>

=item * Mailing List E<rchevron>

=back

LuaJIT has only a single stand-alone executable, called C<luajit> on
POSIX systems or C<luajit.exe> on Windows. It can be used to run simple
Lua statements or whole Lua applications from the command line. It has
an interactive mode, too.

=head2 Command Line Options

The C<luajit> stand-alone executable is just a slightly modified
version of the regular C<lua> stand-alone executable. It supports the
same basic options, too. C<luajit -h> prints a short list of the
available options. Please have a look at the E<rchevron> Lua manual for
details.

LuaJIT has some additional options:

=head2 C<-b[options] input output>

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

=over

=item * C<-l> E<mdash> Only list bytecode.

=item * C<-s> E<mdash> Strip debug info (this is the default).

=item * C<-g> E<mdash> Keep debug info.

=item * C<-n name> E<mdash> Set module name (default: auto-detect from
input name)

=item * C<-t type> E<mdash> Set output file type (default: auto-detect
from output name).

=item * C<-a arch> E<mdash> Override architecture for object files
(default: native).

=item * C<-o os> E<mdash> Override OS for object files (default:
native).

=item * C<-e chunk> E<mdash> Use chunk string as input.

=item * C<-> (a single minus sign) E<mdash> Use stdin as input and/or
stdout as output.

=back

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

=over

=item * C<c> E<mdash> C source file, exported bytecode data.

=item * C<h> E<mdash> C header file, static bytecode data.

=item * C<obj> or C<o> E<mdash> Object file, exported bytecode data
(OS- and architecture-specific).

=item * C<raw> or any other extension E<mdash> Raw bytecode file
(portable).

=back

Notes:

=over

=item * See also string.dump() for information on bytecode portability
and compatibility.

=item * A file in raw bytecode format is auto-detected and can be
loaded like any Lua source file. E.g. directly from the command line or
with C<loadfile()>, C<dofile()> etc.

=item * To statically embed the bytecode of a module in your
application, generate an object file and just link it with your
application.

=item * On most ELF-based systems (e.g. Linux) you need to explicitly
export the global symbols when linking your application, e.g. with:
C<-Wl,-E>

=item * C<require()> tries to load embedded bytecode data from exported
symbols (in C<*.exe> or C<lua51.dll> on Windows) and from shared
libraries in C<package.cpath>.

=back

Typical usage examples:

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

=head2 C<-j cmd[=arg[,arg...]]>

This option performs a LuaJIT control command or activates one of the
loadable extension modules. The command is first looked up in the
C<jit.*> library. If no matching function is found, a module named
C<jit.E<lt>cmdE<gt>> is loaded and the C<start()> function of the
module is called with the specified arguments (if any). The space
between C<-j> and C<cmd> is optional.

Here are the available LuaJIT control commands:

=over

=item * C<-jon> E<mdash> Turns the JIT compiler on (default).

=item * C<-joff> E<mdash> Turns the JIT compiler off (only use the
interpreter).

=item * C<-jflush> E<mdash> Flushes the whole cache of compiled code.

=item * C<-jv> E<mdash> Shows verbose information about the progress of
the JIT compiler.

=item * C<-jdump> E<mdash> Dumps the code and structures used in
various compiler stages.

=item * C<-jp> E<mdash> Start the integrated profiler.

=back

The C<-jv> and C<-jdump> commands are extension modules written in Lua.
They are mainly used for debugging the JIT compiler itself. For a
description of their options and output format, please read the comment
block at the start of their source. They can be found in the C<lib>
directory of the source distribution or installed under the C<jit>
directory. By default this is C</usr/local/share/luajit-2.0.5/jit> on
POSIX systems.

=head2 C<-O[level]>

C<-O[+]flag> C<-O-flag>

C<-Oparam=value>

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

The first form sets an optimization level E<mdash> this enables a
specific mix of optimization flags. C<-O0> turns off all optimizations
and higher numbers enable more optimizations. Omitting the level (i.e.
just C<-O>) sets the default optimization level, which is C<-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 compiler to a
specific value.

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

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

Flag

-O1

-O2

-O3

fold

E<bull>

E<bull>

E<bull>

Constant Folding, Simplifications and Reassociation

cse

E<bull>

E<bull>

E<bull>

Common-Subexpression Elimination

dce

E<bull>

E<bull>

E<bull>

Dead-Code Elimination

narrow

E<bull>

E<bull>

Narrowing of numbers to integers

loop

E<bull>

E<bull>

Loop Optimizations (code hoisting)

fwd

E<bull>

Load Forwarding (L2L) and Store Forwarding (S2L)

dse

E<bull>

Dead-Store Elimination

abc

E<bull>

Array Bounds Check Elimination

sink

E<bull>

Allocation/Store Sinking

fuse

E<bull>

Fusion of operands into instructions

Here are the parameters and their default settings:

Parameter

Default

maxtrace

1000

Max. number of traces in the cache

maxrecord

4000

Max. number of recorded IR instructions

maxirconst

500

Max. number of IR constants of a trace

maxside

100

Max. number of side traces of a root trace

maxsnap

500

Max. number of snapshots for a trace

hotloop

56

Number of iterations to detect a hot loop or hot call

hotexit

10

Number of taken exits to start a side trace

tryside

4

Number of attempts to compile a side trace

instunroll

4

Max. unroll factor for instable loops

loopunroll

15

Max. unroll factor for loop ops in side traces

callunroll

3

Max. unroll factor for pseudo-recursive calls

recunroll

2

Min. unroll factor for true recursion

sizemcode

32

Size of each machine code area in KBytes (Windows: 64K)

maxmcode

512

Max. total size of all machine code areas in KBytes

----

Copyright E<copy> 2005-2017 Mike Pall E<middot> Contact

=cut

#Pod::HTML2Pod conversion notes:
#From file running.html
# 13720 bytes of input
#Mon May 14 13:19:16 2018 agentzh
# No a_name switch not specified, so will not try to render <a name='...'>
# No a_href switch not specified, so will not try to render <a href='...'>