aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/contact.html2
-rw-r--r--doc/ext_c_api.html2
-rw-r--r--doc/ext_ffi.html2
-rw-r--r--doc/ext_ffi_api.html10
-rw-r--r--doc/ext_ffi_semantics.html29
-rw-r--r--doc/ext_ffi_tutorial.html2
-rw-r--r--doc/ext_jit.html4
-rw-r--r--doc/ext_profiler.html359
-rw-r--r--doc/extensions.html104
-rw-r--r--doc/faq.html2
-rw-r--r--doc/install.html155
-rw-r--r--doc/luajit.html8
-rw-r--r--doc/running.html3
-rw-r--r--doc/status.html13
14 files changed, 620 insertions, 75 deletions
diff --git a/doc/contact.html b/doc/contact.html
index b5e390a7..3173b2a5 100644
--- a/doc/contact.html
+++ b/doc/contact.html
@@ -40,6 +40,8 @@
40<a href="ext_jit.html">jit.* Library</a> 40<a href="ext_jit.html">jit.* Library</a>
41</li><li> 41</li><li>
42<a href="ext_c_api.html">Lua/C API</a> 42<a href="ext_c_api.html">Lua/C API</a>
43</li><li>
44<a href="ext_profiler.html">Profiler</a>
43</li></ul> 45</li></ul>
44</li><li> 46</li><li>
45<a href="status.html">Status</a> 47<a href="status.html">Status</a>
diff --git a/doc/ext_c_api.html b/doc/ext_c_api.html
index 18558995..c841b1dc 100644
--- a/doc/ext_c_api.html
+++ b/doc/ext_c_api.html
@@ -40,6 +40,8 @@
40<a href="ext_jit.html">jit.* Library</a> 40<a href="ext_jit.html">jit.* Library</a>
41</li><li> 41</li><li>
42<a class="current" href="ext_c_api.html">Lua/C API</a> 42<a class="current" href="ext_c_api.html">Lua/C API</a>
43</li><li>
44<a href="ext_profiler.html">Profiler</a>
43</li></ul> 45</li></ul>
44</li><li> 46</li><li>
45<a href="status.html">Status</a> 47<a href="status.html">Status</a>
diff --git a/doc/ext_ffi.html b/doc/ext_ffi.html
index 6b846c41..0be54411 100644
--- a/doc/ext_ffi.html
+++ b/doc/ext_ffi.html
@@ -40,6 +40,8 @@
40<a href="ext_jit.html">jit.* Library</a> 40<a href="ext_jit.html">jit.* Library</a>
41</li><li> 41</li><li>
42<a href="ext_c_api.html">Lua/C API</a> 42<a href="ext_c_api.html">Lua/C API</a>
43</li><li>
44<a href="ext_profiler.html">Profiler</a>
43</li></ul> 45</li></ul>
44</li><li> 46</li><li>
45<a href="status.html">Status</a> 47<a href="status.html">Status</a>
diff --git a/doc/ext_ffi_api.html b/doc/ext_ffi_api.html
index 9772aa5d..9c815f8b 100644
--- a/doc/ext_ffi_api.html
+++ b/doc/ext_ffi_api.html
@@ -45,6 +45,8 @@ td.abiparam { font-weight: bold; width: 6em; }
45<a href="ext_jit.html">jit.* Library</a> 45<a href="ext_jit.html">jit.* Library</a>
46</li><li> 46</li><li>
47<a href="ext_c_api.html">Lua/C API</a> 47<a href="ext_c_api.html">Lua/C API</a>
48</li><li>
49<a href="ext_profiler.html">Profiler</a>
48</li></ul> 50</li></ul>
49</li><li> 51</li><li>
50<a href="status.html">Status</a> 52<a href="status.html">Status</a>
@@ -460,6 +462,10 @@ otherwise. The following parameters are currently defined:
460<td class="abiparam">eabi</td><td class="abidesc">EABI variant of the standard ABI</td></tr> 462<td class="abiparam">eabi</td><td class="abidesc">EABI variant of the standard ABI</td></tr>
461<tr class="odd"> 463<tr class="odd">
462<td class="abiparam">win</td><td class="abidesc">Windows variant of the standard ABI</td></tr> 464<td class="abiparam">win</td><td class="abidesc">Windows variant of the standard ABI</td></tr>
465<tr class="even">
466<td class="abiparam">uwp</td><td class="abidesc">Universal Windows Platform</td></tr>
467<tr class="odd">
468<td class="abiparam">gc64</td><td class="abidesc">64 bit GC references</td></tr>
463</table> 469</table>
464 470
465<h3 id="ffi_os"><tt>ffi.os</tt></h3> 471<h3 id="ffi_os"><tt>ffi.os</tt></h3>
@@ -536,8 +542,8 @@ corresponding ctype.
536The parser for Lua source code treats numeric literals with the 542The parser for Lua source code treats numeric literals with the
537suffixes <tt>LL</tt> or <tt>ULL</tt> as signed or unsigned 64&nbsp;bit 543suffixes <tt>LL</tt> or <tt>ULL</tt> as signed or unsigned 64&nbsp;bit
538integers. Case doesn't matter, but uppercase is recommended for 544integers. Case doesn't matter, but uppercase is recommended for
539readability. It handles both decimal (<tt>42LL</tt>) and hexadecimal 545readability. It handles decimal (<tt>42LL</tt>), hexadecimal
540(<tt>0x2aLL</tt>) literals. 546(<tt>0x2aLL</tt>) and binary (<tt>0b101010LL</tt>) literals.
541</p> 547</p>
542<p> 548<p>
543The imaginary part of complex numbers can be specified by suffixing 549The imaginary part of complex numbers can be specified by suffixing
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html
index ce6313d7..3444b8fb 100644
--- a/doc/ext_ffi_semantics.html
+++ b/doc/ext_ffi_semantics.html
@@ -45,6 +45,8 @@ td.convop { font-style: italic; width: 40%; }
45<a href="ext_jit.html">jit.* Library</a> 45<a href="ext_jit.html">jit.* Library</a>
46</li><li> 46</li><li>
47<a href="ext_c_api.html">Lua/C API</a> 47<a href="ext_c_api.html">Lua/C API</a>
48</li><li>
49<a href="ext_profiler.html">Profiler</a>
48</li></ul> 50</li></ul>
49</li><li> 51</li><li>
50<a href="status.html">Status</a> 52<a href="status.html">Status</a>
@@ -177,6 +179,8 @@ a <tt>typedef</tt>, except re-declarations will be ignored):
177<tt>uint16_t</tt>, <tt>uint32_t</tt>, <tt>uint64_t</tt>, 179<tt>uint16_t</tt>, <tt>uint32_t</tt>, <tt>uint64_t</tt>,
178<tt>intptr_t</tt>, <tt>uintptr_t</tt>.</li> 180<tt>intptr_t</tt>, <tt>uintptr_t</tt>.</li>
179 181
182<li>From <tt>&lt;unistd.h&gt;</tt> (POSIX): <tt>ssize_t</tt>.</li>
183
180</ul> 184</ul>
181<p> 185<p>
182You're encouraged to use these types in preference to 186You're encouraged to use these types in preference to
@@ -724,6 +728,22 @@ You'll have to explicitly convert a 64&nbsp;bit integer to a Lua
724number (e.g. for regular floating-point calculations) with 728number (e.g. for regular floating-point calculations) with
725<tt>tonumber()</tt>. But note this may incur a precision loss.</li> 729<tt>tonumber()</tt>. But note this may incur a precision loss.</li>
726 730
731<li><b>64&nbsp;bit bitwise operations</b>: the rules for 64&nbsp;bit
732arithmetic operators apply analogously.<br>
733
734Unlike the other <tt>bit.*</tt> operations, <tt>bit.tobit()</tt>
735converts a cdata number via <tt>int64_t</tt> to <tt>int32_t</tt> and
736returns a Lua number.<br>
737
738For <tt>bit.band()</tt>, <tt>bit.bor()</tt> and <tt>bit.bxor()</tt>, the
739conversion to <tt>int64_t</tt> or <tt>uint64_t</tt> applies to
740<em>all</em> arguments, if <em>any</em> argument is a cdata number.<br>
741
742For all other operations, only the first argument is used to determine
743the output type. This implies that a cdata number as a shift count for
744shifts and rotates is accepted, but that alone does <em>not</em> cause
745a cdata number output.
746
727</ul> 747</ul>
728 748
729<h3 id="cdata_comp">Comparisons of cdata objects</h3> 749<h3 id="cdata_comp">Comparisons of cdata objects</h3>
@@ -1195,14 +1215,12 @@ The following operations are currently not compiled and may exhibit
1195suboptimal performance, especially when used in inner loops: 1215suboptimal performance, especially when used in inner loops:
1196</p> 1216</p>
1197<ul> 1217<ul>
1198<li>Bitfield accesses and initializations.</li>
1199<li>Vector operations.</li> 1218<li>Vector operations.</li>
1200<li>Table initializers.</li> 1219<li>Table initializers.</li>
1201<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li> 1220<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>
1202<li>Allocations of variable-length arrays or structs.</li> 1221<li>Non-default initialization of VLA/VLS or large C&nbsp;types
1203<li>Allocations of C&nbsp;types with a size &gt; 128&nbsp;bytes or an 1222(&gt; 128&nbsp;bytes or &gt; 16 array elements.</li>
1204alignment &gt; 8&nbsp;bytes.</li> 1223<li>Bitfield initializations.</li>
1205<li>Conversions from lightuserdata to <tt>void&nbsp;*</tt>.</li>
1206<li>Pointer differences for element sizes that are not a power of 1224<li>Pointer differences for element sizes that are not a power of
1207two.</li> 1225two.</li>
1208<li>Calls to C&nbsp;functions with aggregates passed or returned by 1226<li>Calls to C&nbsp;functions with aggregates passed or returned by
@@ -1218,7 +1236,6 @@ value.</li>
1218Other missing features: 1236Other missing features:
1219</p> 1237</p>
1220<ul> 1238<ul>
1221<li>Bit operations for 64&nbsp;bit types.</li>
1222<li>Arithmetic for <tt>complex</tt> numbers.</li> 1239<li>Arithmetic for <tt>complex</tt> numbers.</li>
1223<li>Passing structs by value to vararg C&nbsp;functions.</li> 1240<li>Passing structs by value to vararg C&nbsp;functions.</li>
1224<li><a href="extensions.html#exceptions">C++ exception interoperability</a> 1241<li><a href="extensions.html#exceptions">C++ exception interoperability</a>
diff --git a/doc/ext_ffi_tutorial.html b/doc/ext_ffi_tutorial.html
index ae376b1f..aab9c234 100644
--- a/doc/ext_ffi_tutorial.html
+++ b/doc/ext_ffi_tutorial.html
@@ -47,6 +47,8 @@ td.idiomlua b { font-weight: normal; color: #2142bf; }
47<a href="ext_jit.html">jit.* Library</a> 47<a href="ext_jit.html">jit.* Library</a>
48</li><li> 48</li><li>
49<a href="ext_c_api.html">Lua/C API</a> 49<a href="ext_c_api.html">Lua/C API</a>
50</li><li>
51<a href="ext_profiler.html">Profiler</a>
50</li></ul> 52</li></ul>
51</li><li> 53</li><li>
52<a href="status.html">Status</a> 54<a href="status.html">Status</a>
diff --git a/doc/ext_jit.html b/doc/ext_jit.html
index c9fcb9cc..5075a405 100644
--- a/doc/ext_jit.html
+++ b/doc/ext_jit.html
@@ -40,6 +40,8 @@
40<a class="current" href="ext_jit.html">jit.* Library</a> 40<a class="current" href="ext_jit.html">jit.* Library</a>
41</li><li> 41</li><li>
42<a href="ext_c_api.html">Lua/C API</a> 42<a href="ext_c_api.html">Lua/C API</a>
43</li><li>
44<a href="ext_profiler.html">Profiler</a>
43</li></ul> 45</li></ul>
44</li><li> 46</li><li>
45<a href="status.html">Status</a> 47<a href="status.html">Status</a>
@@ -145,7 +147,7 @@ Contains the target OS name:
145<h3 id="jit_arch"><tt>jit.arch</tt></h3> 147<h3 id="jit_arch"><tt>jit.arch</tt></h3>
146<p> 148<p>
147Contains the target architecture name: 149Contains the target architecture name:
148"x86", "x64", "arm", "ppc", "ppcspe", or "mips". 150"x86", "x64", "arm", "arm64", "ppc", "mips" or "mips64".
149</p> 151</p>
150 152
151<h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2> 153<h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>
diff --git a/doc/ext_profiler.html b/doc/ext_profiler.html
new file mode 100644
index 00000000..f1937ba5
--- /dev/null
+++ b/doc/ext_profiler.html
@@ -0,0 +1,359 @@
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4<title>Profiler</title>
5<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6<meta name="Copyright" content="Copyright (C) 2005-2020">
7<meta name="Language" content="en">
8<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
9<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
10</head>
11<body>
12<div id="site">
13<a href="https://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
14</div>
15<div id="head">
16<h1>Profiler</h1>
17</div>
18<div id="nav">
19<ul><li>
20<a href="luajit.html">LuaJIT</a>
21<ul><li>
22<a href="https://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
23</li><li>
24<a href="install.html">Installation</a>
25</li><li>
26<a href="running.html">Running</a>
27</li></ul>
28</li><li>
29<a href="extensions.html">Extensions</a>
30<ul><li>
31<a href="ext_ffi.html">FFI Library</a>
32<ul><li>
33<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
34</li><li>
35<a href="ext_ffi_api.html">ffi.* API</a>
36</li><li>
37<a href="ext_ffi_semantics.html">FFI Semantics</a>
38</li></ul>
39</li><li>
40<a href="ext_jit.html">jit.* Library</a>
41</li><li>
42<a href="ext_c_api.html">Lua/C API</a>
43</li><li>
44<a class="current" href="ext_profiler.html">Profiler</a>
45</li></ul>
46</li><li>
47<a href="status.html">Status</a>
48</li><li>
49<a href="faq.html">FAQ</a>
50</li><li>
51<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
52</li><li>
53<a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
54</li></ul>
55</div>
56<div id="main">
57<p>
58LuaJIT has an integrated statistical profiler with very low overhead. It
59allows sampling the currently executing stack and other parameters in
60regular intervals.
61</p>
62<p>
63The integrated profiler can be accessed from three levels:
64</p>
65<ul>
66<li>The <a href="#hl_profiler">bundled high-level profiler</a>, invoked by the
67<a href="#j_p"><tt>-jp</tt></a> command line option.</li>
68<li>A <a href="#ll_lua_api">low-level Lua API</a> to control the profiler.</li>
69<li>A <a href="#ll_c_api">low-level C API</a> to control the profiler.</li>
70</ul>
71
72<h2 id="hl_profiler">High-Level Profiler</h2>
73<p>
74The bundled high-level profiler offers basic profiling functionality. It
75generates simple textual summaries or source code annotations. It can be
76accessed with the <a href="#j_p"><tt>-jp</tt></a> command line option
77or from Lua code by loading the underlying <tt>jit.p</tt> module.
78</p>
79<p>
80To cut to the chase &mdash; run this to get a CPU usage profile by
81function name:
82</p>
83<pre class="code">
84luajit -jp myapp.lua
85</pre>
86<p>
87It's <em>not</em> a stated goal of the bundled profiler to add every
88possible option or to cater for special profiling needs. The low-level
89profiler APIs are documented below. They may be used by third-party
90authors to implement advanced functionality, e.g. IDE integration or
91graphical profilers.
92</p>
93<p>
94Note: Sampling works for both interpreted and JIT-compiled code. The
95results for JIT-compiled code may sometimes be surprising. LuaJIT
96heavily optimizes and inlines Lua code &mdash; there's no simple
97one-to-one correspondence between source code lines and the sampled
98machine code.
99</p>
100
101<h3 id="j_p"><tt>-jp=[options[,output]]</tt></h3>
102<p>
103The <tt>-jp</tt> command line option starts the high-level profiler.
104When the application run by the command line terminates, the profiler
105stops and writes the results to <tt>stdout</tt> or to the specified
106<tt>output</tt> file.
107</p>
108<p>
109The <tt>options</tt> argument specifies how the profiling is to be
110performed:
111</p>
112<ul>
113<li><tt>f</tt> &mdash; Stack dump: function name, otherwise module:line.
114This is the default mode.</li>
115<li><tt>F</tt> &mdash; Stack dump: ditto, but dump module:name.</li>
116<li><tt>l</tt> &mdash; Stack dump: module:line.</li>
117<li><tt>&lt;number&gt;</tt> &mdash; stack dump depth (callee &larr;
118caller). Default: 1.</li>
119<li><tt>-&lt;number&gt;</tt> &mdash; Inverse stack dump depth (caller
120&rarr; callee).</li>
121<li><tt>s</tt> &mdash; Split stack dump after first stack level. Implies
122depth&nbsp;&ge;&nbsp;2 or depth&nbsp;&le;&nbsp;-2.</li>
123<li><tt>p</tt> &mdash; Show full path for module names.</li>
124<li><tt>v</tt> &mdash; Show VM states.</li>
125<li><tt>z</tt> &mdash; Show <a href="#jit_zone">zones</a>.</li>
126<li><tt>r</tt> &mdash; Show raw sample counts. Default: show percentages.</li>
127<li><tt>a</tt> &mdash; Annotate excerpts from source code files.</li>
128<li><tt>A</tt> &mdash; Annotate complete source code files.</li>
129<li><tt>G</tt> &mdash; Produce raw output suitable for graphical tools.</li>
130<li><tt>m&lt;number&gt;</tt> &mdash; Minimum sample percentage to be shown.
131Default: 3%.</li>
132<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds.
133Default: 10ms.<br>
134Note: The actual sampling precision is OS-dependent.</li>
135</ul>
136<p>
137The default output for <tt>-jp</tt> is a list of the most CPU consuming
138spots in the application. Increasing the stack dump depth with (say)
139<tt>-jp=2</tt> may help to point out the main callers or callees of
140hotspots. But sample aggregation is still flat per unique stack dump.
141</p>
142<p>
143To get a two-level view (split view) of callers/callees, use
144<tt>-jp=s</tt> or <tt>-jp=-s</tt>. The percentages shown for the second
145level are relative to the first level.
146</p>
147<p>
148To see how much time is spent in each line relative to a function, use
149<tt>-jp=fl</tt>.
150</p>
151<p>
152To see how much time is spent in different VM states or
153<a href="#jit_zone">zones</a>, use <tt>-jp=v</tt> or <tt>-jp=z</tt>.
154</p>
155<p>
156Combinations of <tt>v/z</tt> with <tt>f/F/l</tt> produce two-level
157views, e.g. <tt>-jp=vf</tt> or <tt>-jp=fv</tt>. This shows the time
158spent in a VM state or zone vs. hotspots. This can be used to answer
159questions like "Which time consuming functions are only interpreted?" or
160"What's the garbage collector overhead for a specific function?".
161</p>
162<p>
163Multiple options can be combined &mdash; but not all combinations make
164sense, see above. E.g. <tt>-jp=3si4m1</tt> samples three stack levels
165deep in 4ms intervals and shows a split view of the CPU consuming
166functions and their callers with a 1% threshold.
167</p>
168<p>
169Source code annotations produced by <tt>-jp=a</tt> or <tt>-jp=A</tt> are
170always flat and at the line level. Obviously, the source code files need
171to be readable by the profiler script.
172</p>
173<p>
174The high-level profiler can also be started and stopped from Lua code with:
175</p>
176<pre class="code">
177require("jit.p").start(options, output)
178...
179require("jit.p").stop()
180</pre>
181
182<h3 id="jit_zone"><tt>jit.zone</tt> &mdash; Zones</h3>
183<p>
184Zones can be used to provide information about different parts of an
185application to the high-level profiler. E.g. a game could make use of an
186<tt>"AI"</tt> zone, a <tt>"PHYS"</tt> zone, etc. Zones are hierarchical,
187organized as a stack.
188</p>
189<p>
190The <tt>jit.zone</tt> module needs to be loaded explicitly:
191</p>
192<pre class="code">
193local zone = require("jit.zone")
194</pre>
195<ul>
196<li><tt>zone("name")</tt> pushes a named zone to the zone stack.</li>
197<li><tt>zone()</tt> pops the current zone from the zone stack and
198returns its name.</li>
199<li><tt>zone:get()</tt> returns the current zone name or <tt>nil</tt>.</li>
200<li><tt>zone:flush()</tt> flushes the zone stack.</li>
201</ul>
202<p>
203To show the time spent in each zone use <tt>-jp=z</tt>. To show the time
204spent relative to hotspots use e.g. <tt>-jp=zf</tt> or <tt>-jp=fz</tt>.
205</p>
206
207<h2 id="ll_lua_api">Low-level Lua API</h2>
208<p>
209The <tt>jit.profile</tt> module gives access to the low-level API of the
210profiler from Lua code. This module needs to be loaded explicitly:
211<pre class="code">
212local profile = require("jit.profile")
213</pre>
214<p>
215This module can be used to implement your own higher-level profiler.
216A typical profiling run starts the profiler, captures stack dumps in
217the profiler callback, adds them to a hash table to aggregate the number
218of samples, stops the profiler and then analyzes all of the captured
219stack dumps. Other parameters can be sampled in the profiler callback,
220too. But it's important not to spend too much time in the callback,
221since this may skew the statistics.
222</p>
223
224<h3 id="profile_start"><tt>profile.start(mode, cb)</tt>
225&mdash; Start profiler</h3>
226<p>
227This function starts the profiler. The <tt>mode</tt> argument is a
228string holding options:
229</p>
230<ul>
231<li><tt>f</tt> &mdash; Profile with precision down to the function level.</li>
232<li><tt>l</tt> &mdash; Profile with precision down to the line level.</li>
233<li><tt>i&lt;number&gt;</tt> &mdash; Sampling interval in milliseconds (default
23410ms).</br>
235Note: The actual sampling precision is OS-dependent.
236</li>
237</ul>
238<p>
239The <tt>cb</tt> argument is a callback function which is called with
240three arguments: <tt>(thread, samples, vmstate)</tt>. The callback is
241called on a separate coroutine, the <tt>thread</tt> argument is the
242state that holds the stack to sample for profiling. Note: do
243<em>not</em> modify the stack of that state or call functions on it.
244</p>
245<p>
246<tt>samples</tt> gives the number of accumulated samples since the last
247callback (usually 1).
248</p>
249<p>
250<tt>vmstate</tt> holds the VM state at the time the profiling timer
251triggered. This may or may not correspond to the state of the VM when
252the profiling callback is called. The state is either <tt>'N'</tt>
253native (compiled) code, <tt>'I'</tt> interpreted code, <tt>'C'</tt>
254C&nbsp;code, <tt>'G'</tt> the garbage collector, or <tt>'J'</tt> the JIT
255compiler.
256</p>
257
258<h3 id="profile_stop"><tt>profile.stop()</tt>
259&mdash; Stop profiler</h3>
260<p>
261This function stops the profiler.
262</p>
263
264<h3 id="profile_dump"><tt>dump = profile.dumpstack([thread,] fmt, depth)</tt>
265&mdash; Dump stack </h3>
266<p>
267This function allows taking stack dumps in an efficient manner. It
268returns a string with a stack dump for the <tt>thread</tt> (coroutine),
269formatted according to the <tt>fmt</tt> argument:
270</p>
271<ul>
272<li><tt>p</tt> &mdash; Preserve the full path for module names. Otherwise
273only the file name is used.</li>
274<li><tt>f</tt> &mdash; Dump the function name if it can be derived. Otherwise
275use module:line.</li>
276<li><tt>F</tt> &mdash; Ditto, but dump module:name.</li>
277<li><tt>l</tt> &mdash; Dump module:line.</li>
278<li><tt>Z</tt> &mdash; Zap the following characters for the last dumped
279frame.</li>
280<li>All other characters are added verbatim to the output string.</li>
281</ul>
282<p>
283The <tt>depth</tt> argument gives the number of frames to dump, starting
284at the topmost frame of the thread. A negative number dumps the frames in
285inverse order.
286</p>
287<p>
288The first example prints a list of the current module names and line
289numbers of up to 10 frames in separate lines. The second example prints
290semicolon-separated function names for all frames (up to 100) in inverse
291order:
292</p>
293<pre class="code">
294print(profile.dumpstack(thread, "l\n", 10))
295print(profile.dumpstack(thread, "lZ;", -100))
296</pre>
297
298<h2 id="ll_c_api">Low-level C API</h2>
299<p>
300The profiler can be controlled directly from C&nbsp;code, e.g. for
301use by IDEs. The declarations are in <tt>"luajit.h"</tt> (see
302<a href="ext_c_api.html">Lua/C API</a> extensions).
303</p>
304
305<h3 id="luaJIT_profile_start"><tt>luaJIT_profile_start(L, mode, cb, data)</tt>
306&mdash; Start profiler</h3>
307<p>
308This function starts the profiler. <a href="#profile_start">See
309above</a> for a description of the <tt>mode</tt> argument.
310</p>
311<p>
312The <tt>cb</tt> argument is a callback function with the following
313declaration:
314</p>
315<pre class="code">
316typedef void (*luaJIT_profile_callback)(void *data, lua_State *L,
317 int samples, int vmstate);
318</pre>
319<p>
320<tt>data</tt> is available for use by the callback. <tt>L</tt> is the
321state that holds the stack to sample for profiling. Note: do
322<em>not</em> modify this stack or call functions on this stack &mdash;
323use a separate coroutine for this purpose. <a href="#profile_start">See
324above</a> for a description of <tt>samples</tt> and <tt>vmstate</tt>.
325</p>
326
327<h3 id="luaJIT_profile_stop"><tt>luaJIT_profile_stop(L)</tt>
328&mdash; Stop profiler</h3>
329<p>
330This function stops the profiler.
331</p>
332
333<h3 id="luaJIT_profile_dumpstack"><tt>p = luaJIT_profile_dumpstack(L, fmt, depth, len)</tt>
334&mdash; Dump stack </h3>
335<p>
336This function allows taking stack dumps in an efficient manner.
337<a href="#profile_dump">See above</a> for a description of <tt>fmt</tt>
338and <tt>depth</tt>.
339</p>
340<p>
341This function returns a <tt>const&nbsp;char&nbsp;*</tt> pointing to a
342private string buffer of the profiler. The <tt>int&nbsp;*len</tt>
343argument returns the length of the output string. The buffer is
344overwritten on the next call and deallocated when the profiler stops.
345You either need to consume the content immediately or copy it for later
346use.
347</p>
348<br class="flush">
349</div>
350<div id="foot">
351<hr class="hide">
352Copyright &copy; 2005-2020
353<span class="noprint">
354&middot;
355<a href="contact.html">Contact</a>
356</span>
357</div>
358</body>
359</html>
diff --git a/doc/extensions.html b/doc/extensions.html
index b36e2855..cf57e0e8 100644
--- a/doc/extensions.html
+++ b/doc/extensions.html
@@ -57,6 +57,8 @@ td.excinterop {
57<a href="ext_jit.html">jit.* Library</a> 57<a href="ext_jit.html">jit.* Library</a>
58</li><li> 58</li><li>
59<a href="ext_c_api.html">Lua/C API</a> 59<a href="ext_c_api.html">Lua/C API</a>
60</li><li>
61<a href="ext_profiler.html">Profiler</a>
60</li></ul> 62</li></ul>
61</li><li> 63</li><li>
62<a href="status.html">Status</a> 64<a href="status.html">Status</a>
@@ -107,6 +109,9 @@ bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap
107This module is a LuaJIT built-in &mdash; you don't need to download or 109This module is a LuaJIT built-in &mdash; you don't need to download or
108install Lua BitOp. The Lua BitOp site has full documentation for all 110install Lua BitOp. The Lua BitOp site has full documentation for all
109<a href="https://bitop.luajit.org/api.html">Lua BitOp API functions</a>. 111<a href="https://bitop.luajit.org/api.html">Lua BitOp API functions</a>.
112The FFI adds support for
113<a href="ext_ffi_semantics.html#cdata_arith">64&nbsp;bit bitwise operations</a>,
114using the same API functions.
110</p> 115</p>
111<p> 116<p>
112Please make sure to <tt>require</tt> the module before using any of 117Please make sure to <tt>require</tt> the module before using any of
@@ -140,6 +145,11 @@ LuaJIT adds some
140<a href="ext_c_api.html">extra functions to the Lua/C API</a>. 145<a href="ext_c_api.html">extra functions to the Lua/C API</a>.
141</p> 146</p>
142 147
148<h3 id="profiler">Profiler</h3>
149<p>
150LuaJIT has an <a href="ext_profiler.html">integrated profiler</a>.
151</p>
152
143<h2 id="library">Enhanced Standard Library Functions</h2> 153<h2 id="library">Enhanced Standard Library Functions</h2>
144 154
145<h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3> 155<h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>
@@ -167,7 +177,7 @@ in <tt>"-inf"</tt>.
167<h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3> 177<h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3>
168<p> 178<p>
169All string-to-number conversions consistently convert integer and 179All string-to-number conversions consistently convert integer and
170floating-point inputs in decimal and hexadecimal on all platforms. 180floating-point inputs in decimal, hexadecimal and binary on all platforms.
171<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous 181<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous
172problems with poor C library implementations. The builtin conversion 182problems with poor C library implementations. The builtin conversion
173function provides full precision according to the IEEE-754 standard, it 183function provides full precision according to the IEEE-754 standard, it
@@ -191,6 +201,36 @@ for dot releases (x.y.0 &rarr; x.y.1), but may change with major or
191minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign 201minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign
192bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded. 202bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.
193</p> 203</p>
204<p>
205Note: <tt>LJ_GC64</tt> mode requires a different frame layout, which implies
206a different, incompatible bytecode format for all 64 bit ports. This may be
207rectified in the future.
208</p>
209
210<h3 id="table_new"><tt>table.new(narray, nhash)</tt> allocates a pre-sized table</h3>
211<p>
212An extra library function <tt>table.new()</tt> can be made available via
213<tt>require("table.new")</tt>. This creates a pre-sized table, just like
214the C API equivalent <tt>lua_createtable()</tt>. This is useful for big
215tables if the final table size is known and automatic table resizing is
216too expensive.
217</p>
218
219<h3 id="table_clear"><tt>table.clear(tab)</tt> clears a table</h3>
220<p>
221An extra library function <tt>table.clear()</tt> can be made available
222via <tt>require("table.clear")</tt>. This clears all keys and values
223from a table, but preserves the allocated array/hash sizes. This is
224useful when a table, which is linked from multiple places, needs to be
225cleared and/or when recycling a table for use by the same context. This
226avoids managing backlinks, saves an allocation and the overhead of
227incremental array/hash part growth.
228</p>
229<p>
230Please note this function is meant for very specific situations. In most
231cases it's better to replace the (usually single) link with a new table
232and let the GC do its work.
233</p>
194 234
195<h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3> 235<h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3>
196<p> 236<p>
@@ -269,6 +309,26 @@ indexes for varargs.</li>
269<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle 309<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle
270C&nbsp;functions.</li> 310C&nbsp;functions.</li>
271<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li> 311<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>
312<li>Lua/C API extensions:
313<tt>lua_version()</tt>
314<tt>lua_upvalueid()</tt>
315<tt>lua_upvaluejoin()</tt>
316<tt>lua_loadx()</tt>
317<tt>lua_copy()</tt>
318<tt>lua_tonumberx()</tt>
319<tt>lua_tointegerx()</tt>
320<tt>luaL_fileresult()</tt>
321<tt>luaL_execresult()</tt>
322<tt>luaL_loadfilex()</tt>
323<tt>luaL_loadbufferx()</tt>
324<tt>luaL_traceback()</tt>
325<tt>luaL_setfuncs()</tt>
326<tt>luaL_pushmodule()</tt>
327<tt>luaL_newlibtable()</tt>
328<tt>luaL_newlib()</tt>
329<tt>luaL_testudata()</tt>
330<tt>luaL_setmetatable()</tt>
331</li>
272<li>Command line option <tt>-E</tt>.</li> 332<li>Command line option <tt>-E</tt>.</li>
273<li>Command line checks <tt>__tostring</tt> for errors.</li> 333<li>Command line checks <tt>__tostring</tt> for errors.</li>
274</ul> 334</ul>
@@ -294,6 +354,8 @@ exit status.</li>
294<li><tt>debug.setmetatable()</tt> returns object.</li> 354<li><tt>debug.setmetatable()</tt> returns object.</li>
295<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li> 355<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>
296<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li> 356<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li>
357<li><tt>package.searchers</tt>.</li>
358<li><tt>module()</tt> returns the module table.</li>
297</ul> 359</ul>
298<p> 360<p>
299Note: this provides only partial compatibility with Lua 5.2 at the 361Note: this provides only partial compatibility with Lua 5.2 at the
@@ -302,6 +364,21 @@ Lua&nbsp;5.1, which prevents implementing features that would otherwise
302break the Lua/C API and ABI (e.g. <tt>_ENV</tt>). 364break the Lua/C API and ABI (e.g. <tt>_ENV</tt>).
303</p> 365</p>
304 366
367<h2 id="lua53">Extensions from Lua 5.3</h2>
368<p>
369LuaJIT supports some extensions from Lua&nbsp;5.3:
370<ul>
371<li>Unicode escape <tt>'\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.</li>
372<li>The argument table <tt>arg</tt> can be read (and modified) by <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.</li>
373<li><tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.</li>
374<li><tt>assert()</tt> accepts any type of error object.</li>
375<li><tt>table.move(a1, f, e, t [,a2])</tt>.</li>
376<li><tt>coroutine.isyieldable()</tt>.</li>
377<li>Lua/C API extensions:
378<tt>lua_isyieldable()</tt>
379</li>
380</ul>
381
305<h2 id="exceptions">C++ Exception Interoperability</h2> 382<h2 id="exceptions">C++ Exception Interoperability</h2>
306<p> 383<p>
307LuaJIT has built-in support for interoperating with C++&nbsp;exceptions. 384LuaJIT has built-in support for interoperating with C++&nbsp;exceptions.
@@ -316,25 +393,30 @@ the toolchain used to compile LuaJIT:
316</tr> 393</tr>
317<tr class="odd separate"> 394<tr class="odd separate">
318<td class="excplatform">POSIX/x64, DWARF2 unwinding</td> 395<td class="excplatform">POSIX/x64, DWARF2 unwinding</td>
319<td class="exccompiler">GCC 4.3+</td> 396<td class="exccompiler">GCC 4.3+, Clang</td>
320<td class="excinterop"><b style="color: #00a000;">Full</b></td> 397<td class="excinterop"><b style="color: #00a000;">Full</b></td>
321</tr> 398</tr>
322<tr class="even"> 399<tr class="even">
400<td class="excplatform">ARM <tt>-DLUAJIT_UNWIND_EXTERNAL</tt></td>
401<td class="exccompiler">GCC, Clang</td>
402<td class="excinterop"><b style="color: #00a000;">Full</b></td>
403</tr>
404<tr class="odd">
323<td class="excplatform">Other platforms, DWARF2 unwinding</td> 405<td class="excplatform">Other platforms, DWARF2 unwinding</td>
324<td class="exccompiler">GCC</td> 406<td class="exccompiler">GCC, Clang</td>
325<td class="excinterop"><b style="color: #c06000;">Limited</b></td> 407<td class="excinterop"><b style="color: #c06000;">Limited</b></td>
326</tr> 408</tr>
327<tr class="odd"> 409<tr class="even">
328<td class="excplatform">Windows/x64</td> 410<td class="excplatform">Windows/x64</td>
329<td class="exccompiler">MSVC or WinSDK</td> 411<td class="exccompiler">MSVC or WinSDK</td>
330<td class="excinterop"><b style="color: #00a000;">Full</b></td> 412<td class="excinterop"><b style="color: #00a000;">Full</b></td>
331</tr> 413</tr>
332<tr class="even"> 414<tr class="odd">
333<td class="excplatform">Windows/x86</td> 415<td class="excplatform">Windows/x86</td>
334<td class="exccompiler">Any</td> 416<td class="exccompiler">Any</td>
335<td class="excinterop"><b style="color: #a00000;">No</b></td> 417<td class="excinterop"><b style="color: #00a000;">Full</b></td>
336</tr> 418</tr>
337<tr class="odd"> 419<tr class="even">
338<td class="excplatform">Other platforms</td> 420<td class="excplatform">Other platforms</td>
339<td class="exccompiler">Other compilers</td> 421<td class="exccompiler">Other compilers</td>
340<td class="excinterop"><b style="color: #a00000;">No</b></td> 422<td class="excinterop"><b style="color: #a00000;">No</b></td>
@@ -383,14 +465,6 @@ C++ destructors.</li>
383<li>Lua errors <b>cannot</b> be caught on the C++ side.</li> 465<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>
384<li>Throwing Lua errors across C++ frames will <b>not</b> call 466<li>Throwing Lua errors across C++ frames will <b>not</b> call
385C++ destructors.</li> 467C++ destructors.</li>
386<li>Additionally, on Windows/x86 with SEH-based C++&nbsp;exceptions:
387it's <b>not</b> safe to throw a Lua error across any frames containing
388a C++ function with any try/catch construct or using variables with
389(implicit) destructors. This also applies to any functions which may be
390inlined in such a function. It doesn't matter whether <tt>lua_error()</tt>
391is called inside or outside of a try/catch or whether any object actually
392needs to be destroyed: the SEH chain is corrupted and this will eventually
393lead to the termination of the process.</li>
394</ul> 468</ul>
395<br class="flush"> 469<br class="flush">
396</div> 470</div>
diff --git a/doc/faq.html b/doc/faq.html
index 6208882b..31d91e2b 100644
--- a/doc/faq.html
+++ b/doc/faq.html
@@ -43,6 +43,8 @@ dd { margin-left: 1.5em; }
43<a href="ext_jit.html">jit.* Library</a> 43<a href="ext_jit.html">jit.* Library</a>
44</li><li> 44</li><li>
45<a href="ext_c_api.html">Lua/C API</a> 45<a href="ext_c_api.html">Lua/C API</a>
46</li><li>
47<a href="ext_profiler.html">Profiler</a>
46</li></ul> 48</li></ul>
47</li><li> 49</li><li>
48<a href="status.html">Status</a> 50<a href="status.html">Status</a>
diff --git a/doc/install.html b/doc/install.html
index 60665360..bc96b661 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -68,6 +68,8 @@ td.compatno {
68<a href="ext_jit.html">jit.* Library</a> 68<a href="ext_jit.html">jit.* Library</a>
69</li><li> 69</li><li>
70<a href="ext_c_api.html">Lua/C API</a> 70<a href="ext_c_api.html">Lua/C API</a>
71</li><li>
72<a href="ext_profiler.html">Profiler</a>
71</li></ul> 73</li></ul>
72</li><li> 74</li><li>
73<a href="status.html">Status</a> 75<a href="status.html">Status</a>
@@ -106,17 +108,17 @@ operating systems, CPUs and compilers:
106</tr> 108</tr>
107<tr class="odd separate"> 109<tr class="odd separate">
108<td class="compatcpu">x86 (32 bit)</td> 110<td class="compatcpu">x86 (32 bit)</td>
109<td class="compatos">GCC 4.x+<br>GCC 3.4</td> 111<td class="compatos">GCC 4.2+</td>
110<td class="compatos">GCC 4.x+<br>GCC 3.4</td> 112<td class="compatos">GCC 4.2+</td>
111<td class="compatos">XCode 5.0+<br>Clang</td> 113<td class="compatos">XCode 5.0+<br>Clang</td>
112<td class="compatos">MSVC<br>MinGW, Cygwin</td> 114<td class="compatos">MSVC<br>MinGW, Cygwin</td>
113</tr> 115</tr>
114<tr class="even"> 116<tr class="even">
115<td class="compatcpu">x64 (64 bit)</td> 117<td class="compatcpu">x64 (64 bit)</td>
116<td class="compatos">GCC 4.x+</td> 118<td class="compatos">GCC 4.2+</td>
117<td class="compatos">ORBIS (<a href="#ps4">PS4</a>)</td> 119<td class="compatos">GCC 4.2+<br>ORBIS (<a href="#ps4">PS4</a>)</td>
118<td class="compatos">XCode 5.0+<br>Clang</td> 120<td class="compatos">XCode 5.0+<br>Clang</td>
119<td class="compatos">MSVC</td> 121<td class="compatos">MSVC<br>Durango (<a href="#xboxone">Xbox One</a>)</td>
120</tr> 122</tr>
121<tr class="odd"> 123<tr class="odd">
122<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td> 124<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td>
@@ -126,21 +128,21 @@ operating systems, CPUs and compilers:
126<td class="compatos compatno">&nbsp;</td> 128<td class="compatos compatno">&nbsp;</td>
127</tr> 129</tr>
128<tr class="even"> 130<tr class="even">
129<td class="compatcpu"><a href="#cross2">PPC</a></td> 131<td class="compatcpu"><a href="#cross2">ARM64</a></td>
130<td class="compatos">GCC 4.3+</td> 132<td class="compatos">GCC 4.8+</td>
131<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#ps3">PS3</a>)</td> 133<td class="compatos compatno">&nbsp;</td>
134<td class="compatos">XCode 6.0+<br>Clang 3.5+</td>
132<td class="compatos compatno">&nbsp;</td> 135<td class="compatos compatno">&nbsp;</td>
133<td class="compatos">XEDK (<a href="#xbox360">Xbox 360</a>)</td>
134</tr> 136</tr>
135<tr class="odd"> 137<tr class="odd">
136<td class="compatcpu"><a href="#cross2">PPC/e500v2</a></td> 138<td class="compatcpu"><a href="#cross2">PPC</a></td>
137<td class="compatos">GCC 4.3+</td>
138<td class="compatos">GCC 4.3+</td> 139<td class="compatos">GCC 4.3+</td>
140<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#ps3">PS3</a>)</td>
139<td class="compatos compatno">&nbsp;</td> 141<td class="compatos compatno">&nbsp;</td>
140<td class="compatos compatno">&nbsp;</td> 142<td class="compatos">XEDK (<a href="#xbox360">Xbox 360</a>)</td>
141</tr> 143</tr>
142<tr class="even"> 144<tr class="even">
143<td class="compatcpu"><a href="#cross2">MIPS</a></td> 145<td class="compatcpu"><a href="#cross2">MIPS32<br>MIPS64</a></td>
144<td class="compatos">GCC 4.3+</td> 146<td class="compatos">GCC 4.3+</td>
145<td class="compatos">GCC 4.3+</td> 147<td class="compatos">GCC 4.3+</td>
146<td class="compatos compatno">&nbsp;</td> 148<td class="compatos compatno">&nbsp;</td>
@@ -167,6 +169,13 @@ MSVC (Visual Studio).</li>
167Please read the instructions given in these files, before changing 169Please read the instructions given in these files, before changing
168any settings. 170any settings.
169</p> 171</p>
172<p>
173All LuaJIT 64 bit ports use 64 bit GC objects by default (<tt>LJ_GC64</tt>).
174For x64, you can select the old 32-on-64 bit mode by adding
175<tt>XCFLAGS=-DLUAJIT_DISABLE_GC64</tt> to the make command.
176Please check the note about the
177<a href="extensions.html#string_dump">bytecode format</a> differences, too.
178</p>
170 179
171<h2 id="posix">POSIX Systems (Linux, OSX, *BSD etc.)</h2> 180<h2 id="posix">POSIX Systems (Linux, OSX, *BSD etc.)</h2>
172<h3>Prerequisites</h3> 181<h3>Prerequisites</h3>
@@ -194,7 +203,7 @@ which is probably the default on your system, anyway. Simply run:
194make 203make
195</pre> 204</pre>
196<p> 205<p>
197This always builds a native x86, x64 or PPC binary, depending on the host OS 206This always builds a native binary, depending on the host OS
198you're running this command on. Check the section on 207you're running this command on. Check the section on
199<a href="#cross">cross-compilation</a> for more options. 208<a href="#cross">cross-compilation</a> for more options.
200</p> 209</p>
@@ -292,25 +301,36 @@ directory where <tt>luajit.exe</tt> is installed
292 301
293<h2 id="cross">Cross-compiling LuaJIT</h2> 302<h2 id="cross">Cross-compiling LuaJIT</h2>
294<p> 303<p>
304First, let's clear up some terminology:
305</p>
306<ul>
307<li>Host: This is your development system, usually based on a x64 or x86 CPU.</li>
308<li>Target: This is the target system you want LuaJIT to run on, e.g. Android/ARM.</li>
309<li>Toolchain: This comprises a C compiler, linker, assembler and a matching C library.</li>
310<li>Host (or system) toolchain: This is the toolchain used to build native binaries for your host system.</li>
311<li>Cross-compile toolchain: This is the toolchain used to build binaries for the target system. They can only be run on the target system.</li>
312</ul>
313<p>
295The GNU Makefile-based build system allows cross-compiling on any host 314The GNU Makefile-based build system allows cross-compiling on any host
296for any supported target, as long as both architectures have the same 315for any supported target:
297pointer size. If you want to cross-compile to any 32 bit target on an
298x64 OS, you need to install the multilib development package (e.g.
299<tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part
300(<tt>HOST_CC="gcc -m32"</tt>).
301</p> 316</p>
317<ul>
318<li>Yes, you need a toolchain for both your host <em>and</em> your target!</li>
319<li>Both host and target architectures must have the same pointer size.</li>
320<li>E.g. if you want to cross-compile to a 32 bit target on a 64 bit host, you need to install the multilib development package (e.g. <tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part (<tt>HOST_CC="gcc -m32"</tt>).</li>
321<li>64 bit targets always require compilation on a 64 bit host.</li>
322</ul>
302<p> 323<p>
303You need to specify <tt>TARGET_SYS</tt> whenever the host OS and the 324You need to specify <tt>TARGET_SYS</tt> whenever the host OS and the
304target OS differ, or you'll get assembler or linker errors. E.g. if 325target OS differ, or you'll get assembler or linker errors:
305you're compiling on a Windows or OSX host for embedded Linux or Android,
306you need to add <tt>TARGET_SYS=Linux</tt> to the examples below. For a
307minimal target OS, you may need to disable the built-in allocator in
308<tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>. Don't forget to
309specify the same <tt>TARGET_SYS</tt> for the install step, too.
310</p> 326</p>
327<ul>
328<li>E.g. if you're compiling on a Windows or OSX host for embedded Linux or Android, you need to add <tt>TARGET_SYS=Linux</tt> to the examples below.</li>
329<li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.</li>
330<li>Don't forget to specify the same <tt>TARGET_SYS</tt> for the install step, too.</li>
331</ul>
311<p> 332<p>
312The examples below only show some popular targets &mdash; please check 333Here are some examples where host and target have the same CPU:
313the comments in <tt>src/Makefile</tt> for more details.
314</p> 334</p>
315<pre class="code"> 335<pre class="code">
316# Cross-compile to a 32 bit binary on a multilib x64 OS 336# Cross-compile to a 32 bit binary on a multilib x64 OS
@@ -328,34 +348,44 @@ use the canonical toolchain triplets for Linux.
328</p> 348</p>
329<p> 349<p>
330Since there's often no easy way to detect CPU features at runtime, it's 350Since there's often no easy way to detect CPU features at runtime, it's
331important to compile with the proper CPU or architecture settings. You 351important to compile with the proper CPU or architecture settings:
332can specify these when building the toolchain yourself. Or add 352</o>
333<tt>-mcpu=...</tt> or <tt>-march=...</tt> to <tt>TARGET_CFLAGS</tt>. For 353<ul>
334ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting, 354<li>The best way to get consistent results is to specify the correct settings when building the toolchain yourself.</li>
335too. Otherwise LuaJIT may not run at the full performance of your target 355<li>For a pre-built, generic toolchain add <tt>-mcpu=...</tt> or <tt>-march=...</tt> and other necessary flags to <tt>TARGET_CFLAGS</tt>.</li>
336CPU. 356<li>For ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting, too. Otherwise LuaJIT may not run at the full performance of your target CPU.</li>
357<li>For MIPS it's important to select a supported ABI (o32 on MIPS32, n64 on MIPS64) and consistently compile your project either with hard-float or soft-float compiler settings.</li>
358</ul>
359<p>
360Here are some examples for targets with a different CPU than the host:
337</p> 361</p>
338<pre class="code"> 362<pre class="code">
339# ARM soft-float 363# ARM soft-float
340make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ 364make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
341 TARGET_CFLAGS="-mfloat-abi=soft" 365 TARGET_CFLAGS="-mfloat-abi=soft"
342 366
343# ARM soft-float ABI with VFP (example for Cortex-A8) 367# ARM soft-float ABI with VFP (example for Cortex-A9)
344make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ 368make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
345 TARGET_CFLAGS="-mcpu=cortex-a8 -mfloat-abi=softfp" 369 TARGET_CFLAGS="-mcpu=cortex-a9 -mfloat-abi=softfp"
346 370
347# ARM hard-float ABI with VFP (armhf, requires recent toolchain) 371# ARM hard-float ABI with VFP (armhf, most modern toolchains)
348make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf- 372make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf-
349 373
374# ARM64
375make CROSS=aarch64-linux-
376
350# PPC 377# PPC
351make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- 378make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
352# PPC/e500v2 (fast interpreter only)
353make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe-
354 379
355# MIPS big-endian 380# MIPS32 big-endian
356make HOST_CC="gcc -m32" CROSS=mips-linux- 381make HOST_CC="gcc -m32" CROSS=mips-linux-
357# MIPS little-endian 382# MIPS32 little-endian
358make HOST_CC="gcc -m32" CROSS=mipsel-linux- 383make HOST_CC="gcc -m32" CROSS=mipsel-linux-
384
385# MIPS64 big-endian
386make CROSS=mips-linux- TARGET_CFLAGS="-mips64r2 -mabi=64"
387# MIPS64 little-endian
388make CROSS=mipsel-linux- TARGET_CFLAGS="-mips64r2 -mabi=64"
359</pre> 389</pre>
360<p> 390<p>
361You can cross-compile for <b id="android">Android</b> using the <a href="https://developer.android.com/ndk/">Android NDK</a>. 391You can cross-compile for <b id="android">Android</b> using the <a href="https://developer.android.com/ndk/">Android NDK</a>.
@@ -363,8 +393,16 @@ Please adapt the environment variables to match the install locations and the
363desired target platform. E.g. Android&nbsp;4.1 corresponds to ABI level&nbsp;16. 393desired target platform. E.g. Android&nbsp;4.1 corresponds to ABI level&nbsp;16.
364</p> 394</p>
365<pre class="code"> 395<pre class="code">
366# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB) 396# Android/ARM64, aarch64, Android 5.0+ (L)
397NDKDIR=/opt/android/ndk
398NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin
399NDKCROSS=$NDKBIN/aarch64-linux-android-
400NDKCC=$NDKBIN/aarch64-linux-android21-clang
401make CROSS=$NDKCROSS \
402 STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \
403 TARGET_LD=$NDKCC
367 404
405# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB)
368NDKDIR=/opt/android/ndk 406NDKDIR=/opt/android/ndk
369NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin 407NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin
370NDKCROSS=$NDKBIN/arm-linux-androideabi- 408NDKCROSS=$NDKBIN/arm-linux-androideabi-
@@ -374,9 +412,23 @@ make HOST_CC="gcc -m32" CROSS=$NDKCROSS \
374 TARGET_LD=$NDKCC 412 TARGET_LD=$NDKCC
375</pre> 413</pre>
376<p> 414<p>
377Please use the LuaJIT 2.1 branch to compile for 415You can cross-compile for <b id="ios">iOS 3.0+</b> (iPhone/iPad) using the <a href="https://developer.apple.com/ios/">iOS SDK</a>:
378<b id="ios">iOS</b> (iPhone/iPad).
379</p> 416</p>
417<p style="font-size: 8pt;">
418Note: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps
419are not allowed to generate code at runtime. You'll only get the performance
420of the LuaJIT interpreter on iOS. This is still faster than plain Lua, but
421much slower than the JIT compiler. Please complain to Apple, not me.
422Or use Android. :-p
423</p>
424<pre class="code">
425# iOS/ARM64
426ISDKP=$(xcrun --sdk iphoneos --show-sdk-path)
427ICC=$(xcrun --sdk iphoneos --find clang)
428ISDKF="-arch arm64 -isysroot $ISDKP"
429make DEFAULT_CC=clang CROSS="$(dirname $ICC)/" \
430 TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS
431</pre>
380 432
381<h3 id="consoles">Cross-compiling for consoles</h3> 433<h3 id="consoles">Cross-compiling for consoles</h3>
382<p> 434<p>
@@ -432,6 +484,16 @@ the following commands:
432cd src 484cd src
433xedkbuild 485xedkbuild
434</pre> 486</pre>
487<p>
488To cross-compile for <b id="xboxone">Xbox One</b> from a Windows host,
489open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
490<tt>cd</tt> to the directory where you've unpacked the sources and run
491the following commands:
492</p>
493<pre class="code">
494cd src
495xb1build
496</pre>
435 497
436<h2 id="embed">Embedding LuaJIT</h2> 498<h2 id="embed">Embedding LuaJIT</h2>
437<p> 499<p>
@@ -462,14 +524,11 @@ intend to load Lua/C modules at runtime.
462</li> 524</li>
463<li> 525<li>
464If you're building a 64 bit application on OSX which links directly or 526If you're building a 64 bit application on OSX which links directly or
465indirectly against LuaJIT, you need to link your main executable 527indirectly against LuaJIT which is not built for <tt>LJ_GC64</tt> mode,
466with these flags: 528you need to link your main executable with these flags:
467<pre class="code"> 529<pre class="code">
468-pagezero_size 10000 -image_base 100000000 530-pagezero_size 10000 -image_base 100000000
469</pre> 531</pre>
470Also, it's recommended to <tt>rebase</tt> all (self-compiled) shared libraries
471which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).
472See: <tt>man rebase</tt>
473</li> 532</li>
474</ul> 533</ul>
475<p>Additional hints for initializing LuaJIT using the C API functions:</p> 534<p>Additional hints for initializing LuaJIT using the C API functions:</p>
diff --git a/doc/luajit.html b/doc/luajit.html
index c71831bb..3ce81c3e 100644
--- a/doc/luajit.html
+++ b/doc/luajit.html
@@ -125,6 +125,8 @@ table.feature small {
125<a href="ext_jit.html">jit.* Library</a> 125<a href="ext_jit.html">jit.* Library</a>
126</li><li> 126</li><li>
127<a href="ext_c_api.html">Lua/C API</a> 127<a href="ext_c_api.html">Lua/C API</a>
128</li><li>
129<a href="ext_profiler.html">Profiler</a>
128</li></ul> 130</li></ul>
129</li><li> 131</li><li>
130<a href="status.html">Status</a> 132<a href="status.html">Status</a>
@@ -158,13 +160,13 @@ LuaJIT is Copyright &copy; 2005-2020 Mike Pall, released under the
158<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr> 160<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
159</table> 161</table>
160<table class="feature os os3"> 162<table class="feature os os3">
161<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td></tr> 163<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr>
162</table> 164</table>
163<table class="feature compiler"> 165<table class="feature compiler">
164<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr> 166<tr><td>GCC</td><td>Clang<br>LLVM</td><td>MSVC</td></tr>
165</table> 167</table>
166<table class="feature cpu"> 168<table class="feature cpu">
167<tr><td>x86</td><td>x64</td><td>ARM</td><td>PPC</td><td>e500</td><td>MIPS</td></tr> 169<tr><td>x86<br>x64</td><td>ARM<br>ARM64</td><td>PPC</td><td>MIPS32<br>MIPS64</td></tr>
168</table> 170</table>
169<table class="feature fcompat"> 171<table class="feature fcompat">
170<tr><td>Lua&nbsp;5.1<br>API+ABI</td><td>+&nbsp;JIT</td><td>+&nbsp;BitOp</td><td>+&nbsp;FFI</td><td>Drop-in<br>DLL/.so</td></tr> 172<tr><td>Lua&nbsp;5.1<br>API+ABI</td><td>+&nbsp;JIT</td><td>+&nbsp;BitOp</td><td>+&nbsp;FFI</td><td>Drop-in<br>DLL/.so</td></tr>
diff --git a/doc/running.html b/doc/running.html
index a8c71af0..2cba1534 100644
--- a/doc/running.html
+++ b/doc/running.html
@@ -62,6 +62,8 @@ td.param_default {
62<a href="ext_jit.html">jit.* Library</a> 62<a href="ext_jit.html">jit.* Library</a>
63</li><li> 63</li><li>
64<a href="ext_c_api.html">Lua/C API</a> 64<a href="ext_c_api.html">Lua/C API</a>
65</li><li>
66<a href="ext_profiler.html">Profiler</a>
65</li></ul> 67</li></ul>
66</li><li> 68</li><li>
67<a href="status.html">Status</a> 69<a href="status.html">Status</a>
@@ -172,6 +174,7 @@ Here are the available LuaJIT control commands:
172<li id="j_flush"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li> 174<li id="j_flush"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>
173<li id="j_v"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li> 175<li id="j_v"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>
174<li id="j_dump"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li> 176<li id="j_dump"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>
177<li id="j_p"><tt>-jp</tt> &mdash; Start the <a href="ext_profiler.html">integrated profiler</a>.</li>
175</ul> 178</ul>
176<p> 179<p>
177The <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules 180The <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules
diff --git a/doc/status.html b/doc/status.html
index 0d357613..0aafe13a 100644
--- a/doc/status.html
+++ b/doc/status.html
@@ -43,6 +43,8 @@ ul li { padding-bottom: 0.3em; }
43<a href="ext_jit.html">jit.* Library</a> 43<a href="ext_jit.html">jit.* Library</a>
44</li><li> 44</li><li>
45<a href="ext_c_api.html">Lua/C API</a> 45<a href="ext_c_api.html">Lua/C API</a>
46</li><li>
47<a href="ext_profiler.html">Profiler</a>
46</li></ul> 48</li></ul>
47</li><li> 49</li><li>
48<a class="current" href="status.html">Status</a> 50<a class="current" href="status.html">Status</a>
@@ -89,6 +91,17 @@ handled correctly. The error may fall through an on-trace
89<tt>lua_atpanic</tt> on x64. This issue will be fixed with the new 91<tt>lua_atpanic</tt> on x64. This issue will be fixed with the new
90garbage collector. 92garbage collector.
91</li> 93</li>
94<li>
95LuaJIT on 64 bit systems provides a <b>limited range</b> of 47 bits for the
96<b>legacy <tt>lightuserdata</tt></b> data type.
97This is only relevant on x64 systems which use the negative part of the
98virtual address space in user mode, e.g. Solaris/x64, and on ARM64 systems
99configured with a 48 bit or 52 bit VA.
100Avoid using <tt>lightuserdata</tt> to hold pointers that may point outside
101of that range, e.g. variables on the stack. In general, avoid this data
102type for new code and replace it with (much more performant) FFI bindings.
103FFI cdata pointers can address the full 64 bit range.
104</li>
92</ul> 105</ul>
93<br class="flush"> 106<br class="flush">
94</div> 107</div>