rfc:jit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:jit [2019/02/06 09:23] dmitryrfc:jit [2020/08/01 23:41] (current) – RFC was implemented in PHP 8.0 carusogabriel
Line 1: Line 1:
 ====== PHP RFC: JIT ====== ====== PHP RFC: JIT ======
-  * Version: 0.9+  * Version: 1.0
   * Date: 2019-01-28   * Date: 2019-01-28
   * Author: Dmitry Stogov <dmitry@php.net>, Zeev Suraski <zeev@php.net>   * Author: Dmitry Stogov <dmitry@php.net>, Zeev Suraski <zeev@php.net>
-  * Status: Under Discussion+  * Status: Implemented (PHP 8.0)
   * First Published at: https://wiki.php.net/rfc/jit   * First Published at: https://wiki.php.net/rfc/jit
  
Line 25: Line 25:
  
 PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile time and at run-time. PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile time and at run-time.
-When enabled, native code of PHP files is stored in an additional region of the OPcache shared memory and op_array->opcodes[].handler(s) keep pointers to the JIT-ed code. This approach doesn't require engine modification at all.+When enabled, native code of PHP files is stored in an additional region of the OPcache shared memory and op_array->opcodes[].handler(s) keep pointers to the entry points of JIT-ed code. This approach doesn't require engine modification at all.
  
-We use DynAsm (developed for LuaJIT project) for generation of native code. It's a very lightweight and advanced tool, but does assume good, and very low-level development knowledge of target assembler languages.  In the past we tried LLVM, but its code generation speed was almost 100 times slower, making it prohibitively expensive to use. Currently we support only x86 and x86_64 on POSIX platforms. Windows support should be relatively straightforward, but was (and still is) a low priority for us. DynAsm also supports ARM. ARM64, MIPS, MIPS64 and PPC, so in theory we should be able to support all of the platforms that are popular for PHP deployments (given enough efforts).+We use DynAsm (developed for LuaJIT project) for generation of native code. It's a very lightweight and advanced tool, but does assume good, and very low-level development knowledge of target assembler languages.  In the past we tried LLVM, but its code generation speed was almost 100 times slower, making it prohibitively expensive to use. Currently we support x86 and x86_64 CPUs on POSIX platforms and Windows. DynAsm also supports ARM. ARM64, MIPS, MIPS64 and PPC, so in theory we should be able to support all of the platforms that are popular for PHP deployments (given enough efforts).
  
 +PHP JIT doesn't introduce any additional IR (Intermediate Representation) form. It generates native code directly from PHP byte-code and information collected by SSA static analyses framework (a part of opcache optimizer). Code is usually generated separately for each PHP byte-code instruction. Only few combinations are considered together (e.g. compare + conditional jump).
 +
 +If type of PHP variable is exactly inferred (in SSA) to LONG or DOUBLE, and it can't be accessed indirectly, JIT may store its value directly in CPU registers, avoiding memory stores and loads. PHP JIT liner-scan register allocation algorithm, tat combines high speed with reasonable quality.
  
 The quality of the JIT may be demonstrated on Mandelbrot benchmark published at https://gist.github.com/dstogov/12323ad13d3240aee8f1, where it improves performance more than 4 times (0.011 sec vs 0.046 sec on PHP 7.4). The quality of the JIT may be demonstrated on Mandelbrot benchmark published at https://gist.github.com/dstogov/12323ad13d3240aee8f1, where it improves performance more than 4 times (0.011 sec vs 0.046 sec on PHP 7.4).
Line 261: Line 264:
  jmp .L10  jmp .L10
 </code> </code>
 +
 +In comparison to V8, HHVM, PyPy and most others modern JIT implementations PHP JIT is extremely simple, but anyway it increases the level of the whole PHP complexity, risk of new kind of bugs and cost of development and maintenance.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 396: Line 401:
 </code> </code>
  
-===== Open Issues ===== +===== State and compatibility ===== 
-Make sure there are no open issues when the vote starts!+Currently we support x86 and x86_64 on POSIX platforms (tested on Linux with GCC and LVVM) and Windows (both non-ZTS and ZTS builds). We support "Hybrid" and "Call" VM with and without GCC explicit global register variables extension. 
 +There are no any restrictions on C compiler and OS any more.
  
 ===== Future Scope ===== ===== Future Scope =====
Line 403: Line 409:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-This project requires a 50%+1 majority.+Support for JIT is more a strategic PHP question. JIT definitely requires a lot of work, but it may be actively developed only as a part of PHP, with common effort. 
 + 
 +This project requires a 2/3+1 majority. Voting opened 2019-03-21 and closes 2019-03-28
  
 <doodle title="Include JIT into PHP 8?" auth="user" voteType="single" closed="true"> <doodle title="Include JIT into PHP 8?" auth="user" voteType="single" closed="true">
Line 410: Line 418:
 </doodle> </doodle>
  
-As PHP 7.4 is already branched and its engine is not expected to be significantly changed (consequently requiring corresponding changes to the JIT implementation), we can also consider including JIT in PHP-7.4 as an experimental feature (disabled by default).+As PHP 7.4 is already branched and its engine is not expected to be significantly changed (consequently requiring corresponding changes to the JIT implementation), we can also consider including JIT in PHP-7.4 as an experimental feature (disabled by default), to provide early access and receive more feedback. This also requires a 2/3+1 majority. 
 + 
 +In case JIT is not included in PHP-7.4 and PHP-8 introduces language compatibility breaks (it already does), existing applications couldn't be tested with JIT without porting to PHP-8.
  
 <doodle title="Include JIT into PHP 7.4 (experimental)?" auth="user" voteType="single" closed="true"> <doodle title="Include JIT into PHP 7.4 (experimental)?" auth="user" voteType="single" closed="true">
Line 423: Line 433:
  
 ===== Implementation ===== ===== Implementation =====
-After the project is implemented, this section should contain  +Merged into PHP master by [[https://github.com/php/php-src/commit/9a06876072b9ccb023d4a14426ccb587f10882f3|9a06876072b9ccb023d4a14426ccb587f10882f3]] commit
-  - the version(s) it was merged into +
-  a link to the git commit(s) +
-  - a link to the PHP manual entry for the feature +
-  - a link to the language specification section (if any)+
  
 ===== References ===== ===== References =====
   - [[https://luajit.org/dynasm.html|DynAsm page]]   - [[https://luajit.org/dynasm.html|DynAsm page]]
   - [[https://corsix.github.io/dynasm-doc/|The Unofficial DynASM Documentation]]   - [[https://corsix.github.io/dynasm-doc/|The Unofficial DynASM Documentation]]
- 
-===== Rejected Features ===== 
-Keep this updated with features that were discussed on the mail lists. 
  
rfc/jit.1549445032.txt.gz · Last modified: 2019/02/06 09:23 by dmitry