php-src/Zend
Max Kellermann c7637ed1c0 Zend/zend_type_code: remove hard-coded integer values and
remove unused macro ZEND_SAME_FAKE_TYPE
Zend/zend_variables: add _Static_assert on the size zend_rc_dtor_func
_Static_assert is C11, but has been supported since GCC 4.6.

Also removing the comment about keeping those values in sync with
`zend_variables.c` which was obsoleted by commit 0460420205
(designated initializers).

Closes GH-10714.
2023-02-27 20:52:17 +00:00
..
asm Merge branch 'PHP-8.2' 2023-02-05 16:47:09 +00:00
Optimizer Improve handling of XML options 2023-02-26 14:34:39 +00:00
tests Fix GH-10489: run-tests.php does not escape path when building cmd (#10560) 2023-02-25 14:02:06 +00:00
bench.php
LICENSE
Makefile.frag ext/Zend: zend_language_scanner_defs.h as make target 2023-02-17 16:37:13 +00:00
micro_bench.php
README.md
zend.c Zend/zend_types.h: move zend_rc_debug to zend_rc_debug.h 2023-02-26 14:16:53 +00:00
zend.h Zend/zend_types.h: move IS_* to zend_type_code.h 2023-02-26 14:16:53 +00:00
Zend.m4 Remove now-unused check for /dev/urandom from Zend/Zend.m4 2023-01-23 17:38:50 +01:00
zend_alloc.c Zend/zend_alloc: make stderr_last_error() static (#10587) 2023-02-18 19:39:54 +00:00
zend_alloc.h Zend/zend_types.h: move zend_string to zend_string.h 2023-02-26 14:16:53 +00:00
zend_alloc_sizes.h Fix GH-9361: Segmentation fault on script exit 2022-08-22 12:59:17 +02:00
zend_API.c Zend/zend_types.h: move zend_rc_debug to zend_rc_debug.h 2023-02-26 14:16:53 +00:00
zend_API.h Zend/zend_types.h: move zend_uchar.h to zend_char.h 2023-02-26 14:16:53 +00:00
zend_arena.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_ast.c Fix comp-time and constant evaluation of dynamic class constant fetch 2023-02-02 19:18:17 +01:00
zend_ast.h Fix lineno for all constant expressions 2023-02-02 19:03:47 +01:00
zend_atomic.c Fixed undefined macros warnings 2022-09-22 13:17:02 +02:00
zend_atomic.h Fixed undefined macros warnings 2022-09-22 13:17:02 +02:00
zend_attributes.c Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
zend_attributes.h Support the actual #[\SensitiveParameter] attribute in stubs (#8836) 2022-07-12 12:43:44 +02:00
zend_attributes.stub.php Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
zend_attributes_arginfo.h Fix RC debug of stub attribute (#9082) 2022-07-21 15:06:04 +02:00
zend_bitset.h Add AVX2-accelerated UTF-16 decoding/encoding routines 2023-02-05 20:06:42 +02:00
zend_build.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_builtin_functions.c [skip ci] Add comments as to why no ZPP union type format is used 2023-02-25 17:16:03 +00:00
zend_builtin_functions.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_builtin_functions.stub.php Add four extra fields to gc_status() (#9336) 2022-10-04 13:56:02 +01:00
zend_builtin_functions_arginfo.h Add four extra fields to gc_status() (#9336) 2022-10-04 13:56:02 +01:00
zend_call_stack.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_call_stack.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_char.h Zend/zend_types.h: move zend_uchar.h to zend_char.h 2023-02-26 14:16:53 +00:00
zend_closures.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_closures.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_closures.stub.php
zend_closures_arginfo.h
zend_compile.c Merge branch 'PHP-8.2' 2023-02-24 20:42:00 +01:00
zend_compile.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_config.w32.h
zend_constants.c Declare remaining Zend constants in stubs (#9730) 2022-10-12 22:43:36 +02:00
zend_constants.h
zend_constants.stub.php Declare remaining Zend constants in stubs (#9730) 2022-10-12 22:43:36 +02:00
zend_constants_arginfo.h Declare remaining Zend constants in stubs (#9730) 2022-10-12 22:43:36 +02:00
zend_cpuinfo.c Windows arm64 zend and standard extension support 2022-08-09 12:45:14 +02:00
zend_cpuinfo.h base64: add avx512 and vbmi version. (#6361) 2023-02-13 03:30:47 +00:00
zend_default_classes.c
zend_dtrace.c
zend_dtrace.d
zend_dtrace.h
zend_enum.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_enum.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_enum.stub.php
zend_enum_arginfo.h
zend_errors.h
zend_exceptions.c Fix GH-9709: Guard against current_execute_data==NULL in is_handle_exception_set 2022-10-23 00:50:22 +01:00
zend_exceptions.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_exceptions.stub.php Require zend_constants.stub.php from zend_exceptions.stubs.php 2022-07-12 10:35:03 +02:00
zend_exceptions_arginfo.h Require zend_constants.stub.php from zend_exceptions.stubs.php 2022-07-12 10:35:03 +02:00
zend_execute.c Minor cleanups in Zend execution APIs (#10699) 2023-02-26 14:15:04 +00:00
zend_execute.h Zend/zend_types.h: move IS_* to zend_type_code.h 2023-02-26 14:16:53 +00:00
zend_execute_API.c Minor cleanups in Zend execution APIs (#10699) 2023-02-26 14:15:04 +00:00
zend_extensions.c Zend/zend_extensions: make zend_extension_version_info const (#10592) 2023-02-20 13:20:54 +00:00
zend_extensions.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_fibers.c Zend/zend_fibers: change return value to zend_result 2023-02-26 15:07:08 +00:00
zend_fibers.h Zend/zend_fibers: change return value to zend_result 2023-02-26 15:07:08 +00:00
zend_fibers.stub.php
zend_fibers_arginfo.h
zend_float.c Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_float.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_gc.c Fix incorrect UNEXPECTED paren placement in zend_gc.c 2023-01-18 19:42:20 +01:00
zend_gc.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_gdb.c
zend_gdb.h
zend_generators.c Merge branch 'PHP-8.2' 2023-02-13 13:10:44 +01:00
zend_generators.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_generators.stub.php
zend_generators_arginfo.h
zend_globals.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_globals_macros.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_hash.c Revert "#include cleanup (#10216)" 2023-01-16 12:29:41 +01:00
zend_hash.h Zend/zend_types.h: move IS_* to zend_type_code.h 2023-02-26 14:16:53 +00:00
zend_highlight.c
zend_highlight.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_inheritance.c Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597) 2023-02-18 19:31:28 +00:00
zend_inheritance.h Convert some macros to zend_always_inline functions (#8288) 2022-08-04 13:24:12 +01:00
zend_ini.c Merge branch 'PHP-8.2' 2023-02-21 13:54:12 +00:00
zend_ini.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_ini_parser.y Zend/zend_ini_scanner: parse const strings 2023-01-04 12:49:48 +00:00
zend_ini_scanner.h Zend/zend_ini_scanner: parse const strings 2023-01-04 12:49:48 +00:00
zend_ini_scanner.l zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_interfaces.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_interfaces.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_interfaces.stub.php
zend_interfaces_arginfo.h
zend_istdiostream.h
zend_iterators.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_iterators.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_language_parser.y Fix GH-10377: Unable to have an anonymous readonly class 2023-02-20 13:32:26 +01:00
zend_language_scanner.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_language_scanner.l Use an explicit failure check for zend_result functions in the scanner (#10688) 2023-02-23 22:56:07 +01:00
zend_list.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_list.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_llist.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_llist.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_long.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_map_ptr.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_mmap.h Use PDEATHSIG to kill cli-server workers if parent exists 2022-09-08 10:48:20 +02:00
zend_modules.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_multibyte.c Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_multibyte.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_multiply.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_object_handlers.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_object_handlers.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_objects.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_objects.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_objects_API.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_objects_API.h Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597) 2023-02-18 19:31:28 +00:00
zend_observer.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_observer.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_opcode.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_operators.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_operators.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_portability.h Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597) 2023-02-18 19:31:28 +00:00
zend_ptr_stack.c Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_ptr_stack.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_range_check.h
zend_rc_debug.c Zend/zend_rc_debug: convert ZEND_RC_MOD_CHECK() to function 2023-02-26 14:16:53 +00:00
zend_rc_debug.h Zend/zend_rc_debug: convert ZEND_RC_MOD_CHECK() to function 2023-02-26 14:16:53 +00:00
zend_refcounted.h Zend/zend_types.h: move zend_refcounted to zend_refcounted.h 2023-02-26 14:16:53 +00:00
zend_result.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_signal.c Mark globals as const (#10303) 2023-01-23 13:46:58 +00:00
zend_signal.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_smart_str.c Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_smart_str.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_smart_str_public.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_smart_string.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_smart_string_public.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_sort.c Revert "#include cleanup (#10216)" 2023-01-16 12:29:41 +01:00
zend_sort.h Revert "#include cleanup (#10216)" 2023-01-16 12:29:41 +01:00
zend_stack.c Two enums instead of preprocessor macros (#10617) 2023-02-21 15:34:33 +01:00
zend_stack.h Two enums instead of preprocessor macros (#10617) 2023-02-21 15:34:33 +01:00
zend_stream.c Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_stream.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_string.c Zend/zend_types.h: move zend_string to zend_string.h 2023-02-26 14:16:53 +00:00
zend_string.h Zend/zend_types.h: move zend_string to zend_string.h 2023-02-26 14:16:53 +00:00
zend_strtod.c Mark constant static arrays in function bodies actually as const (#10325) 2023-01-15 14:51:31 +00:00
zend_strtod.h
zend_strtod_int.h build/php.m4: remove test for integer types (#10304) 2023-01-13 11:51:15 +00:00
zend_system_id.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_system_id.h Zend/zend_types.h: move zend_result to separate header (#10609) 2023-02-20 13:07:51 +00:00
zend_type_code.h Zend/zend_type_code: remove hard-coded integer values and 2023-02-27 20:52:17 +00:00
zend_type_info.h
zend_types.h Zend/zend_types.h: move zend_string to zend_string.h 2023-02-26 14:16:53 +00:00
zend_variables.c Zend/zend_type_code: remove hard-coded integer values and 2023-02-27 20:52:17 +00:00
zend_variables.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_virtual_cwd.c Fix GH-9227: Trailing dots and spaces in filenames are ignored 2022-08-19 14:23:57 +02:00
zend_virtual_cwd.h
zend_vm.h
zend_vm_def.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_vm_execute.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_vm_execute.skl Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597) 2023-02-18 19:31:28 +00:00
zend_vm_gen.php zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_vm_handlers.h Implement dynamic class const fetch 2023-01-26 16:46:34 +01:00
zend_vm_opcodes.c zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_vm_opcodes.h zend_compiler, ...: use uint8_t instead of zend_uchar (#10621) 2023-02-23 14:56:54 +00:00
zend_vm_trace_handlers.h
zend_vm_trace_lines.h
zend_vm_trace_map.h
zend_weakrefs.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_weakrefs.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_weakrefs.stub.php
zend_weakrefs_arginfo.h

Zend Engine

Zend memory manager

General

The goal of the new memory manager (available since PHP 5.2) is to reduce memory allocation overhead and speedup memory management.

Debugging

Normal:

sapi/cli/php -r 'leak();'

Zend MM disabled:

USE_ZEND_ALLOC=0 valgrind --leak-check=full sapi/cli/php -r 'leak();'

Shared extensions

Since PHP 5.3.11 it is possible to prevent shared extensions from unloading so that valgrind can correctly track the memory leaks in shared extensions. For this there is the ZEND_DONT_UNLOAD_MODULES environment variable. If set, then DL_UNLOAD() is skipped during the shutdown of shared extensions.

ZEND_VM

ZEND_VM architecture allows specializing opcode handlers according to op_type fields and using different execution methods (call threading, switch threading and direct threading). As a result ZE2 got more than 20% speedup on raw PHP code execution (with specialized executor and direct threading execution method). As in most PHP applications raw execution speed isn't the limiting factor but system calls and database calls are, your mileage with this patch will vary.

Most parts of the old zend_execute.c go into zend_vm_def.h. Here you can find opcode handlers and helpers. The typical opcode handler template looks like this:

ZEND_VM_HANDLER(<OPCODE-NUMBER>, <OPCODE>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HANDLER'S CODE>
}

<OPCODE-NUMBER> is a opcode number (0, 1, ...) <OPCODE> is an opcode name (ZEN_NOP, ZEND_ADD, :) <OP1_TYPES> and <OP2_TYPES> are masks for allowed operand op_types. Specializer will generate code only for defined combination of types. You can use any combination of the following op_types UNUSED, CONST, VAR, TMP and CV also you can use ANY mask to disable specialization according operand's op_type. <HANDLER'S CODE> is a handler's code itself. For most handlers it stills the same as in old zend_execute.c, but now it uses macros to access opcode operands and some internal executor data.

You can see the conformity of new macros to old code in the following list:

EXECUTE_DATA
    execute_data
ZEND_VM_DISPATCH_TO_HANDLER(<OP>)
    return <OP>_helper(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER(<NAME>)
    return <NAME>(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER_EX(<NAME>,<PARAM>,<VAL>)
    return <NAME>(<VAL>, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_CONTINUE()
    return 0
ZEND_VM_NEXT_OPCODE()
    NEXT_OPCODE()
ZEND_VM_SET_OPCODE(<TARGET>
    SET_OPCODE(<TARGET>
ZEND_VM_INC_OPCODE()
    INC_OPCOD()
ZEND_VM_RETURN_FROM_EXECUTE_LOOP()
    RETURN_FROM_EXECUTE_LOOP()
ZEND_VM_C_LABEL(<LABEL>):
    <LABEL>:
ZEND_VM_C_GOTO(<LABEL>)
    goto <LABEL>
OP<X>_TYPE
    opline->op<X>.op_type
GET_OP<X>_ZVAL_PTR(<TYPE>)
    get_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_ZVAL_PTR_PTR(<TYPE>)
    get_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR(<TYPE>)
    get_obj_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR_PTR(<TYPE>)
    get_obj_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
IS_OP<X>_TMP_FREE()
    IS_TMP_FREE(free_op<X>)
FREE_OP<X>()
    FREE_OP(free_op<X>)
FREE_OP<X>_IF_VAR()
    FREE_VAR(free_op<X>)
FREE_OP<X>_VAR_PTR()
    FREE_VAR_PTR(free_op<X>)

Executor's helpers can be defined without parameters or with one parameter. This is done with the following constructs:

ZEND_VM_HELPER(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HELPER'S CODE>
}

ZEND_VM_HELPER_EX(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>, <PARAM_SPEC>)
{
    <HELPER'S CODE>
}

The executors code is generated by the PHP script zend_vm_gen.php. It uses zend_vm_def.h and zend_vm_execute.skl as input and produces zend_vm_opcodes.h and zend_vm_execute.h. The first file is a list of opcode definitions. It is included from zend_compile.h. The second one is an executor code itself. It is included from zend_execute.c.

zend_vm_gen.php can produce different kind of executors. You can select a different opcode threading model using --with-vm-kind=CALL|SWITCH|GOTO|HYBRID. You can disable opcode specialization using --without-specializer. At last you can debug the executor using the original zend_vm_def.h or the generated zend_vm_execute.h file. Debugging with the original file requires the --with-lines option. By default, Zend Engine uses the following command to generate the executor:

# Default VM kind is HYBRID
php zend_vm_gen.php --with-vm-kind=HYBRID