Name Date Size #Lines LOC

..Today-

Optimizer/H18-Dec-2024-

asm/H07-Sep-2024-

tests/H15-Dec-2024-

LICENSEH A D30-Aug-20222.7 KiB5747

Makefile.fragH A D24-Jun-20242.2 KiB4526

README.mdH A D30-Aug-20224.5 KiB140116

Zend.m4H A D10-Dec-202413.9 KiB473425

bench.phpH A D30-Aug-20227.5 KiB423347

micro_bench.phpH A D30-Aug-20227.1 KiB359307

zend.cH A D01-Nov-202460.6 KiB2,0951,645

zend.hH A D24-Sep-202417.3 KiB457322

zend_API.cH A DToday160.5 KiB5,3974,329

zend_API.hH A D15-Dec-2024106.4 KiB2,5892,073

zend_alloc.cH A D26-Nov-202499.7 KiB3,3272,767

zend_alloc.hH A D19-Jun-202420.2 KiB411240

zend_alloc_sizes.hH A D30-Aug-20222.6 KiB6541

zend_arena.hH A D14-Sep-20235.9 KiB225169

zend_ast.cH A D17-Dec-202477.1 KiB2,7362,450

zend_ast.hH A D02-Dec-202413.5 KiB397312

zend_atomic.cH A D30-May-20242.8 KiB7642

zend_atomic.hH A D30-May-202412.8 KiB391283

zend_attributes.cH A D05-Sep-202414.7 KiB529399

zend_attributes.hH A D02-Jul-20245.8 KiB13185

zend_attributes.stub.phpH A D02-Jul-20242 KiB8743

zend_attributes_arginfo.hH A D30-Sep-202413.8 KiB256197

zend_bitset.hH A D02-Apr-20247.9 KiB302232

zend_build.hH A D16-Jan-20231.6 KiB4721

zend_builtin_functions.cH A D27-Sep-202461.3 KiB2,2341,699

zend_builtin_functions.hH A D20-May-20241.5 KiB349

zend_builtin_functions.stub.phpH A D16-Aug-20244.9 KiB21364

zend_builtin_functions_arginfo.hH A D03-Sep-202414.9 KiB380308

zend_call_stack.cH A D23-Aug-202420.8 KiB832601

zend_call_stack.hH A D08-Jul-20243 KiB10469

zend_closures.cH A D22-Oct-202430.1 KiB917688

zend_closures.hH A D20-May-20242.3 KiB4718

zend_closures.stub.phpH A D30-Aug-2022547 2513

zend_closures_arginfo.hH A D24-Aug-20242 KiB5138

zend_compile.cH A D09-Dec-2024358.5 KiB11,9999,670

zend_compile.hH A D22-Sep-202452.1 KiB1,299832

zend_config.w32.hH A D12-Dec-20241.9 KiB5424

zend_constants.cH A D07-Nov-202415.7 KiB536430

zend_constants.hH A D31-Oct-20246.6 KiB10872

zend_constants.stub.phpH A D18-Sep-20241.8 KiB14124

zend_constants_arginfo.hH A D18-Sep-20241.8 KiB3026

zend_cpuinfo.cH A D09-Aug-20244.7 KiB154113

zend_cpuinfo.hH A D08-Aug-20249 KiB274201

zend_default_classes.cH A D30-Aug-20221.8 KiB4423

zend_dtrace.cH A D30-Aug-20224.2 KiB12278

zend_dtrace.dH A D30-Aug-20222.1 KiB3613

zend_dtrace.hH A D30-Aug-20222 KiB4922

zend_enum.cH A D17-Sep-202421.1 KiB630507

zend_enum.hH A D17-Sep-20242.9 KiB6536

zend_enum.stub.phpH A D30-Aug-2022273 1610

zend_enum_arginfo.hH A D25-Feb-20241.7 KiB4732

zend_errors.hH A D18-Sep-20242.4 KiB5223

zend_exceptions.cH A D10-Nov-202431.8 KiB1,043785

zend_exceptions.hH A D10-Nov-20244.5 KiB9751

zend_exceptions.stub.phpH A D08-Feb-20244 KiB17794

zend_exceptions_arginfo.hH A D30-Sep-202415.4 KiB339246

zend_execute.cH A D25-Oct-2024176.1 KiB5,7624,889

zend_execute.hH A D30-Oct-202423.5 KiB562418

zend_execute_API.cH A DToday54.1 KiB1,9931,601

zend_extensions.cH A D07-Sep-202413.7 KiB429324

zend_extensions.hH A D24-Sep-20246.4 KiB16491

zend_fibers.cH A D28-Aug-202433.2 KiB1,153808

zend_fibers.hH A D02-Jul-20245.3 KiB16782

zend_fibers.stub.phpH A D30-Aug-2022752 3819

zend_fibers_arginfo.hH A D24-Aug-20243.4 KiB9268

zend_float.cH A D16-Jan-20231.8 KiB5730

zend_float.hH A D24-Sep-202415.1 KiB418260

zend_frameless_function.cH A D06-Feb-20241.2 KiB256

zend_frameless_function.hH A D15-Jun-20245.4 KiB134102

zend_gc.cH A D18-Dec-202457.9 KiB2,2871,863

zend_gc.hH A D02-Jul-20244.6 KiB162109

zend_gdb.cH A D14-Jun-20244.4 KiB159112

zend_gdb.hH A D30-Aug-20221.4 KiB286

zend_generators.cH A D02-Oct-202436.8 KiB1,229858

zend_generators.hH A D02-Oct-20247.5 KiB14267

zend_generators.stub.phpH A D21-May-2024578 3316

zend_generators_arginfo.hH A D03-Sep-20242.8 KiB7353

zend_globals.hH A D07-Sep-20249.8 KiB393251

zend_globals_macros.hH A D20-May-20242.8 KiB7439

zend_hash.cH A D04-Nov-202485.4 KiB3,4432,931

zend_hash.hH A D18-Nov-202450.9 KiB1,6951,330

zend_highlight.cH A D14-Jul-20245.6 KiB224179

zend_highlight.hH A D20-May-20242.3 KiB5325

zend_hrtime.cH A D10-Dec-20242.1 KiB7133

zend_hrtime.hH A D10-Dec-20244.1 KiB11476

zend_inheritance.cH A D09-Dec-2024137.2 KiB3,9353,196

zend_inheritance.hH A D14-Jul-20243.1 KiB6129

zend_ini.cH A D19-Jul-202427.6 KiB1,057788

zend_ini.hH A D20-May-202411.9 KiB262155

zend_ini_parser.yH A D28-Jun-202413.6 KiB479373

zend_ini_scanner.hH A D20-May-20241.9 KiB4216

zend_ini_scanner.lH A D18-Jul-202317.5 KiB692466

zend_interfaces.cH A D26-Sep-202422 KiB682504

zend_interfaces.hH A D16-Jan-20234 KiB8248

zend_interfaces.stub.phpH A D30-Aug-20221.7 KiB8643

zend_interfaces_arginfo.hH A D03-Sep-20247.7 KiB202147

zend_iterators.cH A D16-Jan-20233.3 KiB10674

zend_iterators.hH A D20-May-20243.8 KiB9941

zend_language_parser.yH A D27-Aug-202463.4 KiB1,8451,554

zend_language_scanner.hH A D20-May-20243 KiB8850

zend_language_scanner.lH A D18-Nov-202475.7 KiB3,1712,500

zend_lazy_objects.cH A D22-Oct-202425.2 KiB819571

zend_lazy_objects.hH A D16-Sep-20244.6 KiB10963

zend_list.cH A D29-Oct-20239.2 KiB350259

zend_list.hH A D20-Apr-20233.4 KiB7740

zend_llist.cH A D16-Jan-20236.7 KiB312229

zend_llist.hH A D20-May-20243.9 KiB9460

zend_long.hH A D16-Jan-20234.1 KiB12997

zend_map_ptr.hH A D07-Sep-20243.3 KiB9161

zend_max_execution_timer.cH A D20-Aug-20244.2 KiB14188

zend_max_execution_timer.hH A D24-Oct-20241.5 KiB3915

zend_mmap.hH A D08-Sep-20221.5 KiB4519

zend_modules.hH A D24-Sep-20244.7 KiB13291

zend_multibyte.cH A D11-Jan-20247.2 KiB213159

zend_multibyte.hH A D20-May-20244.8 KiB8246

zend_multiply.hH A D08-Jul-202410 KiB357285

zend_object_handlers.cH A D09-Dec-202473.9 KiB2,4692,031

zend_object_handlers.hH A D30-Aug-202417.6 KiB362201

zend_objects.cH A D16-Sep-202410.5 KiB332256

zend_objects.hH A D30-Aug-20241.9 KiB4014

zend_objects_API.cH A D02-Jul-20246.6 KiB203147

zend_objects_API.hH A D16-Sep-20245.2 KiB13282

zend_observer.cH A D15-Jun-202417.2 KiB437332

zend_observer.hH A D15-Jun-20248.8 KiB177109

zend_opcode.cH A D12-Dec-202437.2 KiB1,2721,063

zend_operators.cH A D09-Dec-202498.3 KiB3,8033,189

zend_operators.hH A D25-Sep-202433 KiB997819

zend_portability.hH A D12-Dec-202426.8 KiB874691

zend_property_hooks.cH A D18-Dec-202413 KiB392326

zend_property_hooks.hH A D14-Jul-20241.8 KiB4317

zend_ptr_stack.cH A D16-Jan-20232.9 KiB11876

zend_ptr_stack.hH A D20-May-20244.2 KiB12178

zend_range_check.hH A D30-Aug-20222.9 KiB6832

zend_signal.cH A D22-May-202412.9 KiB449315

zend_signal.hH A D20-May-20244 KiB11573

zend_smart_str.cH A D10-Jun-20247.3 KiB239195

zend_smart_str.hH A D10-Jun-20246.9 KiB202158

zend_smart_str_public.hH A D20-May-20241.2 KiB319

zend_smart_string.hH A D16-Jan-20234.1 KiB11478

zend_smart_string_public.hH A D16-Jan-20231.2 KiB309

zend_sort.cH A D16-Jan-20239.2 KiB308192

zend_sort.hH A D20-May-20241.5 KiB318

zend_stack.cH A D21-Feb-20233.9 KiB161115

zend_stack.hH A D20-May-20242.4 KiB5427

zend_stream.cH A D16-Jan-20238.2 KiB289226

zend_stream.hH A D20-May-20243.6 KiB10367

zend_string.cH A D11-Oct-202415.9 KiB531413

zend_string.hH A D30-Sep-202422.3 KiB653508

zend_strtod.cH A D08-Nov-202492.2 KiB4,6384,000

zend_strtod.hH A D23-Apr-20242.3 KiB5227

zend_strtod_int.hH A D08-Sep-20242.8 KiB11062

zend_system_id.cH A D05-Sep-20243.3 KiB9667

zend_system_id.hH A D20-May-20241.4 KiB3310

zend_type_info.hH A D02-Nov-20234.4 KiB8551

zend_types.hH A D18-Dec-202451 KiB1,5881,212

zend_variables.cH A D03-Mar-20234.6 KiB13696

zend_variables.hH A D11-Sep-20233 KiB9458

zend_verify_type_inference.hH A D24-Sep-20248.1 KiB204151

zend_virtual_cwd.cH A D23-Aug-202442.9 KiB1,7561,424

zend_virtual_cwd.hH A D29-Nov-202412.9 KiB402307

zend_vm.hH A D20-May-20242.1 KiB4720

zend_vm_def.hH A D15-Nov-2024295 KiB10,4298,994

zend_vm_execute.hH A D15-Nov-20242.2 MiB68,48361,074

zend_vm_execute.sklH A D05-Dec-20233.9 KiB157133

zend_vm_gen.phpH A D15-Jun-2024138.9 KiB3,0952,736

zend_vm_handlers.hH A D14-Aug-202490.5 KiB1,8741,873

zend_vm_opcodes.cH A D14-Aug-20249.2 KiB473449

zend_vm_opcodes.hH A D14-Aug-202413.5 KiB298267

zend_vm_trace_handlers.hH A D30-Aug-20223.1 KiB11384

zend_vm_trace_lines.hH A D30-Aug-20221.7 KiB4319

zend_vm_trace_map.hH A D30-Aug-20222.6 KiB8256

zend_weakrefs.cH A D15-Oct-202425.7 KiB806632

zend_weakrefs.hH A D14-Oct-20243.4 KiB8142

zend_weakrefs.stub.phpH A D30-Aug-2022826 4016

zend_weakrefs_arginfo.hH A D24-Aug-20243.4 KiB8463

README.md

1# Zend Engine
2
3## Zend memory manager
4
5### General
6
7The goal of the new memory manager (available since PHP 5.2) is to reduce memory
8allocation overhead and speedup memory management.
9
10### Debugging
11
12Normal:
13
14```bash
15sapi/cli/php -r 'leak();'
16```
17
18Zend MM disabled:
19
20```bash
21USE_ZEND_ALLOC=0 valgrind --leak-check=full sapi/cli/php -r 'leak();'
22```
23
24### Shared extensions
25
26Since PHP 5.3.11 it is possible to prevent shared extensions from unloading so
27that valgrind can correctly track the memory leaks in shared extensions. For
28this there is the `ZEND_DONT_UNLOAD_MODULES` environment variable. If set, then
29`DL_UNLOAD()` is skipped during the shutdown of shared extensions.
30
31## ZEND_VM
32
33`ZEND_VM` architecture allows specializing opcode handlers according to
34`op_type` fields and using different execution methods (call threading, switch
35threading and direct threading). As a result ZE2 got more than 20% speedup on
36raw PHP code execution (with specialized executor and direct threading execution
37method). As in most PHP applications raw execution speed isn't the limiting
38factor but system calls and database calls are, your mileage with this patch
39will vary.
40
41Most parts of the old zend_execute.c go into `zend_vm_def.h`. Here you can find
42opcode handlers and helpers. The typical opcode handler template looks like
43this:
44
45```c
46ZEND_VM_HANDLER(<OPCODE-NUMBER>, <OPCODE>, <OP1_TYPES>, <OP2_TYPES>)
47{
48    <HANDLER'S CODE>
49}
50```
51
52`<OPCODE-NUMBER>` is a opcode number (0, 1, ...)
53`<OPCODE>` is an opcode name (ZEN_NOP, ZEND_ADD, :)
54`<OP1_TYPES>` and `<OP2_TYPES>` are masks for allowed operand op_types.
55Specializer will generate code only for defined combination of types. You can
56use any combination of the following op_types UNUSED, CONST, VAR, TMP and CV
57also you can use ANY mask to disable specialization according operand's op_type.
58`<HANDLER'S CODE>` is a handler's code itself. For most handlers it stills the
59same as in old `zend_execute.c`, but now it uses macros to access opcode
60operands and some internal executor data.
61
62You can see the conformity of new macros to old code in the following list:
63
64```c
65EXECUTE_DATA
66    execute_data
67ZEND_VM_DISPATCH_TO_HANDLER(<OP>)
68    return <OP>_helper(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
69ZEND_VM_DISPATCH_TO_HELPER(<NAME>)
70    return <NAME>(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
71ZEND_VM_DISPATCH_TO_HELPER_EX(<NAME>,<PARAM>,<VAL>)
72    return <NAME>(<VAL>, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
73ZEND_VM_CONTINUE()
74    return 0
75ZEND_VM_NEXT_OPCODE()
76    NEXT_OPCODE()
77ZEND_VM_SET_OPCODE(<TARGET>
78    SET_OPCODE(<TARGET>
79ZEND_VM_INC_OPCODE()
80    INC_OPCOD()
81ZEND_VM_RETURN_FROM_EXECUTE_LOOP()
82    RETURN_FROM_EXECUTE_LOOP()
83ZEND_VM_C_LABEL(<LABEL>):
84    <LABEL>:
85ZEND_VM_C_GOTO(<LABEL>)
86    goto <LABEL>
87OP<X>_TYPE
88    opline->op<X>.op_type
89GET_OP<X>_ZVAL_PTR(<TYPE>)
90    get_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
91GET_OP<X>_ZVAL_PTR_PTR(<TYPE>)
92    get_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
93GET_OP<X>_OBJ_ZVAL_PTR(<TYPE>)
94    get_obj_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
95GET_OP<X>_OBJ_ZVAL_PTR_PTR(<TYPE>)
96    get_obj_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
97IS_OP<X>_TMP_FREE()
98    IS_TMP_FREE(free_op<X>)
99FREE_OP<X>()
100    FREE_OP(free_op<X>)
101FREE_OP<X>_IF_VAR()
102    FREE_VAR(free_op<X>)
103FREE_OP<X>_VAR_PTR()
104    FREE_VAR_PTR(free_op<X>)
105```
106
107Executor's helpers can be defined without parameters or with one parameter. This
108is done with the following constructs:
109
110```c
111ZEND_VM_HELPER(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>)
112{
113    <HELPER'S CODE>
114}
115
116ZEND_VM_HELPER_EX(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>, <PARAM_SPEC>)
117{
118    <HELPER'S CODE>
119}
120```
121
122The executors code is generated by the PHP script `zend_vm_gen.php`. It uses
123`zend_vm_def.h` and `zend_vm_execute.skl` as input and produces
124`zend_vm_opcodes.h` and `zend_vm_execute.h`. The first file is a list of opcode
125definitions. It is included from `zend_compile.h`. The second one is an executor
126code itself. It is included from `zend_execute.c`.
127
128`zend_vm_gen.php` can produce different kind of executors. You can select a
129different opcode threading model using `--with-vm-kind=CALL|SWITCH|GOTO|HYBRID`.
130You can disable opcode specialization using `--without-specializer`.
131At last you can debug the executor using the original `zend_vm_def.h` or the
132generated `zend_vm_execute.h` file. Debugging with the original file requires
133the `--with-lines` option. By default, Zend Engine uses the following
134command to generate the executor:
135
136```bash
137# Default VM kind is HYBRID
138php zend_vm_gen.php --with-vm-kind=HYBRID
139```
140