php-internal-docs 8.4.8
Unofficial docs for php/php-src
|
Directories | |
ir | |
Files | |
zend_jit.c | |
zend_jit.h | |
zend_jit_helpers.c | |
zend_jit_internal.h | |
zend_jit_ir.c | |
zend_jit_trace.c | |
zend_jit_vm_helpers.c | |
This is the implementation of Opcache's JIT (Just-In-Time compiler), This converts the PHP Virtual Machine's opcodes into Intermediate Representation and uses IR - Lightweight JIT Compilation Framework to produce optimized native code. The necessary part of the IR Framework is embedded into php-src.
Then, to test the JIT, e.g. with opcache.jit=tracing, an example command based on what is used to test in CI:
opcache.jit_buffer_size=16M
enables the JIT in tests by providing 16 megabytes of memory to use with the JIT to test with.opcache.protect_memory=1
will detect writing to memory that is meant to be read-only, which is sometimes the cause of opcache bugs.--repeat 2
is optional, but used in CI since some JIT bugs only show up after processing a request multiple times (the first request compiles the trace and the second executes it)-j$(nproc)
runs as many workers to run tests as there are CPUs.ext/opcache/
and Zend
are the folders with the tests to run, in this case opcache and the Zend engine itself. If no folders are provided, all tests are run.When investigating test failures such as segmentation faults, configuring the build of php with --enable-address-sanitizer
to enable AddressSanitizer is often useful.
Some of the time, adding -m --show-mem
to the TESTS
configuration is also useful to test with valgrind to detect out of bounds memory accesses. Using valgrind is slower at detecting invalid memory read/writes than AddressSanitizer when running large numbers of tests, but does not require rebuilding php.
Note that the JIT supports 3 different architectures: X86_64
, i386
, and arm64
.
Refer to ../../../.github/workflows/push.yml for examples of dependencies to install.
If you are running this natively (outside of Docker or a VM):
-y
- if the package manager warns you that the dependencies conflict then don't try to force install them.This assumes you are using a Debian-based Linux distribution and have already set up prerequisites for regular development.
This assumes you are using a Debian-based Linux distribution and have already set up prerequisites for 32-bit development.
See the section "Running tests of the JIT".
https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ may be useful for local development.
Note that this is slower than compiling and testing natively.
Then, the docker image can be used to run tests with make test
. For example, to test ext/opcache
in parallel with the tracing JIT enabled: