ext_jit.html 5.5 KB

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