ext_jit.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>jit.* Library</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta name="Copyright" content="Copyright (C) 2005-2023">
  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><tt>jit.*</tt> Library</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 class="current" href="ext_jit.html">jit.* Library</a>
  41. </li><li>
  42. <a href="ext_c_api.html">Lua/C API</a>
  43. </li></ul>
  44. </li><li>
  45. <a href="https://luajit.org/status.html">Status <span class="ext">&raquo;</span></a>
  46. </li><li>
  47. <a href="https://luajit.org/faq.html">FAQ <span class="ext">&raquo;</span></a>
  48. </li><li>
  49. <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
  50. </li></ul>
  51. </div>
  52. <div id="main">
  53. <p>
  54. The functions in this built-in module control the behavior of the JIT
  55. compiler engine. Note that JIT-compilation is fully automatic &mdash;
  56. you probably won't need to use any of the following functions unless
  57. you have special needs.
  58. </p>
  59. <h3 id="jit_onoff"><tt>jit.on()<br>
  60. jit.off()</tt></h3>
  61. <p>
  62. Turns the whole JIT compiler on (default) or off.
  63. </p>
  64. <p>
  65. These functions are typically used with the command line options
  66. <tt>-j on</tt> or <tt>-j off</tt>.
  67. </p>
  68. <h3 id="jit_flush"><tt>jit.flush()</tt></h3>
  69. <p>
  70. Flushes the whole cache of compiled code.
  71. </p>
  72. <h3 id="jit_onoff_func"><tt>jit.on(func|true [,true|false])<br>
  73. jit.off(func|true [,true|false])<br>
  74. jit.flush(func|true [,true|false])</tt></h3>
  75. <p>
  76. <tt>jit.on</tt> enables JIT compilation for a Lua function (this is
  77. the default).
  78. </p>
  79. <p>
  80. <tt>jit.off</tt> disables JIT compilation for a Lua function and
  81. flushes any already compiled code from the code cache.
  82. </p>
  83. <p>
  84. <tt>jit.flush</tt> flushes the code, but doesn't affect the
  85. enable/disable status.
  86. </p>
  87. <p>
  88. The current function, i.e. the Lua function calling this library
  89. function, can also be specified by passing <tt>true</tt> as the first
  90. argument.
  91. </p>
  92. <p>
  93. If the second argument is <tt>true</tt>, JIT compilation is also
  94. enabled, disabled or flushed recursively for all sub-functions of a
  95. function. With <tt>false</tt> only the sub-functions are affected.
  96. </p>
  97. <p>
  98. The <tt>jit.on</tt> and <tt>jit.off</tt> functions only set a flag
  99. which is checked when the function is about to be compiled. They do
  100. not trigger immediate compilation.
  101. </p>
  102. <p>
  103. Typical usage is <tt>jit.off(true, true)</tt> in the main chunk
  104. of a module to turn off JIT compilation for the whole module for
  105. debugging purposes.
  106. </p>
  107. <h3 id="jit_flush_tr"><tt>jit.flush(tr)</tt></h3>
  108. <p>
  109. Flushes the root trace, specified by its number, and all of its side
  110. traces from the cache. The code for the trace will be retained as long
  111. as there are any other traces which link to it.
  112. </p>
  113. <h3 id="jit_status"><tt>status, ... = jit.status()</tt></h3>
  114. <p>
  115. Returns the current status of the JIT compiler. The first result is
  116. either <tt>true</tt> or <tt>false</tt> if the JIT compiler is turned
  117. on or off. The remaining results are strings for CPU-specific features
  118. and enabled optimizations.
  119. </p>
  120. <h3 id="jit_version"><tt>jit.version</tt></h3>
  121. <p>
  122. Contains the LuaJIT version string.
  123. </p>
  124. <h3 id="jit_version_num"><tt>jit.version_num</tt></h3>
  125. <p>
  126. Contains the version number of the LuaJIT core. Version xx.yy.zz
  127. is represented by the decimal number xxyyzz.<br>
  128. <b>DEPRECATED after the switch to
  129. <a href="https://luajit.org/status.html#release"><span class="ext">&raquo;</span>&nbsp;rolling releases</a>. zz is frozen at 99.</b>
  130. </p>
  131. <h3 id="jit_os"><tt>jit.os</tt></h3>
  132. <p>
  133. Contains the target OS name:
  134. "Windows", "Linux", "OSX", "BSD", "POSIX" or "Other".
  135. </p>
  136. <h3 id="jit_arch"><tt>jit.arch</tt></h3>
  137. <p>
  138. Contains the target architecture name:
  139. "x86", "x64", "arm", "ppc", "ppcspe", or "mips".
  140. </p>
  141. <h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>
  142. <p>
  143. This submodule provides the backend for the <tt>-O</tt> command line
  144. option.
  145. </p>
  146. <p>
  147. You can also use it programmatically, e.g.:
  148. </p>
  149. <pre class="code">
  150. jit.opt.start(2) -- same as -O2
  151. jit.opt.start("-dce")
  152. jit.opt.start("hotloop=10", "hotexit=2")
  153. </pre>
  154. <p>
  155. Unlike in LuaJIT 1.x, the module is built-in and
  156. <b>optimization is turned on by default!</b>
  157. It's no longer necessary to run <tt>require("jit.opt").start()</tt>,
  158. which was one of the ways to enable optimization.
  159. </p>
  160. <h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>
  161. <p>
  162. This submodule holds functions to introspect the bytecode, generated
  163. traces, the IR and the generated machine code. The functionality
  164. provided by this module is still in flux and therefore undocumented.
  165. </p>
  166. <p>
  167. The debug modules <tt>-jbc</tt>, <tt>-jv</tt> and <tt>-jdump</tt> make
  168. extensive use of these functions. Please check out their source code,
  169. if you want to know more.
  170. </p>
  171. <br class="flush">
  172. </div>
  173. <div id="foot">
  174. <hr class="hide">
  175. Copyright &copy; 2005-2023
  176. <span class="noprint">
  177. &middot;
  178. <a href="contact.html">Contact</a>
  179. </span>
  180. </div>
  181. </body>
  182. </html>