Name Date Size #Lines LOC

..Today-

Optimizer/H03-Nov-2024-

asm/H03-Nov-2024-

tests/HToday-

LICENSEH A D28-Sep-20232.7 KiB5747

Makefile.fragH A D03-Nov-20242.3 KiB4526

README.mdH A D28-Sep-20234.5 KiB140116

Zend.m4H A D03-Nov-202411.7 KiB402347

bench.phpH A D28-Sep-20237.5 KiB423347

micro_bench.phpH A D28-Sep-20237.1 KiB359307

zend.cH A D03-Nov-202457.4 KiB2,0111,575

zend.hH A D03-Nov-202415.5 KiB421308

zend_API.cH A D03-Nov-2024152.3 KiB5,1824,154

zend_API.hH A D03-Nov-2024103.3 KiB2,5352,025

zend_alloc.cH A D03-Nov-202493.8 KiB3,1692,638

zend_alloc.hH A D03-Nov-202418.8 KiB405233

zend_alloc_sizes.hH A D28-Sep-20232.6 KiB6541

zend_arena.hH A D03-Nov-20245.9 KiB225169

zend_ast.cH A D03-Nov-202472.7 KiB2,5992,322

zend_ast.hH A D03-Nov-202413 KiB386305

zend_atomic.cH A D03-Nov-20241.9 KiB4819

zend_atomic.hH A D03-Nov-20245.6 KiB180113

zend_attributes.cH A D03-Nov-202411.3 KiB397295

zend_attributes.hH A D03-Nov-20245.5 KiB12782

zend_attributes.stub.phpH A D03-Nov-20241.6 KiB7437

zend_attributes_arginfo.hH A D03-Nov-202412.1 KiB235177

zend_bitset.hH A D03-Nov-20247.9 KiB302232

zend_build.hH A D28-Sep-20231.6 KiB4721

zend_builtin_functions.cH A D03-Nov-202455.2 KiB2,0341,528

zend_builtin_functions.hH A D03-Nov-20241.5 KiB307

zend_builtin_functions.stub.phpH A D03-Nov-20244.7 KiB20162

zend_builtin_functions_arginfo.hH A D03-Nov-202413.9 KiB364293

zend_call_stack.cH A D03-Nov-202414.8 KiB539362

zend_call_stack.hH A D03-Nov-20242.8 KiB9560

zend_closures.cH A D03-Nov-202429.6 KiB905678

zend_closures.hH A D03-Nov-20242.2 KiB4517

zend_closures.stub.phpH A D28-Sep-2023547 2513

zend_closures_arginfo.hH A D03-Nov-20242 KiB5439

zend_compile.cH A D03-Nov-2024325.2 KiB11,0108,852

zend_compile.hH A D03-Nov-202448.9 KiB1,221770

zend_config.w32.hH A D03-Nov-20242 KiB6130

zend_constants.cH A D03-Nov-202417.6 KiB594415

zend_constants.hH A D03-Nov-20246.5 KiB10771

zend_constants.stub.phpH A D03-Nov-20241.7 KiB13024

zend_constants_arginfo.hH A D03-Nov-20241.8 KiB3226

zend_cpuinfo.cH A D03-Nov-20244.7 KiB154113

zend_cpuinfo.hH A D03-Nov-20248.9 KiB273200

zend_default_classes.cH A D28-Sep-20231.8 KiB4423

zend_dtrace.cH A D28-Sep-20234.2 KiB12278

zend_dtrace.dH A D28-Sep-20232.1 KiB3613

zend_dtrace.hH A D28-Sep-20232 KiB4922

zend_enum.cH A D03-Nov-202420.9 KiB623500

zend_enum.hH A D03-Nov-20242.9 KiB6536

zend_enum.stub.phpH A D28-Sep-2023273 1610

zend_enum_arginfo.hH A D03-Nov-20241.7 KiB5032

zend_errors.hH A D03-Nov-20242.3 KiB5123

zend_exceptions.cH A D03-Nov-202431.7 KiB1,048791

zend_exceptions.hH A D03-Nov-20244.4 KiB9449

zend_exceptions.stub.phpH A D03-Nov-20243.9 KiB17391

zend_exceptions_arginfo.hH A D03-Nov-202417.5 KiB404293

zend_execute.cH A D03-Nov-2024168.9 KiB5,5244,690

zend_execute.hH A D03-Nov-202422.2 KiB535399

zend_execute_API.cH A D03-Nov-202452.7 KiB1,9471,559

zend_extensions.cH A D03-Nov-202412.7 KiB403303

zend_extensions.hH A D03-Nov-20246.2 KiB16188

zend_fibers.cH A D03-Nov-202431 KiB1,092767

zend_fibers.hH A D03-Nov-20245 KiB16379

zend_fibers.stub.phpH A D28-Sep-2023752 3819

zend_fibers_arginfo.hH A D03-Nov-20243.5 KiB9770

zend_float.cH A D28-Sep-20231.8 KiB5730

zend_float.hH A D03-Nov-202415.1 KiB416259

zend_gc.cH A D03-Nov-202453.9 KiB2,1281,742

zend_gc.hH A D03-Nov-20244.6 KiB161108

zend_gdb.cH A D03-Nov-20244.4 KiB159112

zend_gdb.hH A D28-Sep-20231.4 KiB286

zend_generators.cH A D03-Nov-202435.9 KiB1,200833

zend_generators.hH A D03-Nov-20247.3 KiB13665

zend_generators.stub.phpH A D03-Nov-2024533 3115

zend_generators_arginfo.hH A D03-Nov-20242.7 KiB7653

zend_globals.hH A D03-Nov-20249.5 KiB383244

zend_globals_macros.hH A D03-Nov-20242.7 KiB7238

zend_hash.cH A DToday85 KiB3,4432,932

zend_hash.hH A DToday50.1 KiB1,6861,324

zend_highlight.cH A D03-Nov-20245.6 KiB223178

zend_highlight.hH A D03-Nov-20242.2 KiB5124

zend_hrtime.cH A D17-Mar-20242.1 KiB7133

zend_hrtime.hH A D17-Mar-20243.8 KiB10870

zend_inheritance.cH A D03-Nov-2024119.2 KiB3,4672,791

zend_inheritance.hH A D03-Nov-20242.4 KiB4818

zend_ini.cH A D03-Nov-202427.6 KiB1,057788

zend_ini.hH A D03-Nov-202411.9 KiB260154

zend_ini_parser.yH A D03-Nov-202413.6 KiB479373

zend_ini_scanner.hH A D03-Nov-20241.9 KiB3814

zend_ini_scanner.lH A D28-Sep-202317.5 KiB692466

zend_interfaces.cH A D03-Nov-202422 KiB678499

zend_interfaces.hH A D28-Sep-20234 KiB8248

zend_interfaces.stub.phpH A D28-Sep-20231.7 KiB8643

zend_interfaces_arginfo.hH A D03-Nov-20247.8 KiB216151

zend_istdiostream.hH A D03-Nov-20241.5 KiB3513

zend_iterators.cH A D28-Sep-20233.3 KiB10674

zend_iterators.hH A D03-Nov-20243.7 KiB9237

zend_language_parser.yH A D03-Nov-202460.9 KiB1,7741,490

zend_language_scanner.hH A D03-Nov-20243 KiB8649

zend_language_scanner.lH A D03-Nov-202475.3 KiB3,1552,488

zend_list.cH A D29-Oct-20239.2 KiB350259

zend_list.hH A D28-Sep-20233.4 KiB7740

zend_llist.cH A D28-Sep-20236.7 KiB312229

zend_llist.hH A D03-Nov-20243.9 KiB9259

zend_long.hH A D28-Sep-20234.1 KiB12997

zend_map_ptr.hH A D03-Nov-20242.9 KiB8254

zend_max_execution_timer.cH A D03-Nov-20243.8 KiB12776

zend_max_execution_timer.hH A D28-Sep-20231.4 KiB3713

zend_mmap.hH A D28-Sep-20231.5 KiB4519

zend_modules.hH A D03-Nov-20244.7 KiB13291

zend_multibyte.cH A D03-Nov-20247.2 KiB213159

zend_multibyte.hH A D03-Nov-20244.8 KiB8045

zend_multiply.hH A D03-Nov-202410 KiB357285

zend_object_handlers.cH A D03-Nov-202461.5 KiB2,0531,684

zend_object_handlers.hH A D03-Nov-202414.2 KiB283136

zend_objects.cH A D03-Nov-20249.9 KiB307237

zend_objects.hH A D03-Nov-20241.8 KiB3612

zend_objects_API.cH A D03-Nov-20246.7 KiB209151

zend_objects_API.hH A D03-Nov-20244.5 KiB11770

zend_observer.cH A D03-Nov-202415.3 KiB405306

zend_observer.hH A D03-Nov-20246.2 KiB13180

zend_opcode.cH A D03-Nov-202436.6 KiB1,2521,045

zend_operators.cH A D03-Nov-202497.5 KiB3,7723,161

zend_operators.hH A D03-Nov-202432.7 KiB988811

zend_portability.hH A D03-Nov-202423.8 KiB771600

zend_ptr_stack.cH A D28-Sep-20232.9 KiB11876

zend_ptr_stack.hH A D03-Nov-20244.2 KiB11977

zend_range_check.hH A D28-Sep-20232.9 KiB6832

zend_signal.cH A D03-Nov-202412.9 KiB449315

zend_signal.hH A D03-Nov-20244 KiB11372

zend_smart_str.cH A D03-Nov-20246.8 KiB224181

zend_smart_str.hH A D03-Nov-20246.8 KiB201157

zend_smart_str_public.hH A D03-Nov-20241.1 KiB277

zend_smart_string.hH A D28-Sep-20234.1 KiB11478

zend_smart_string_public.hH A D28-Sep-20231.2 KiB309

zend_sort.cH A D28-Sep-20239.2 KiB308192

zend_sort.hH A D03-Nov-20241.5 KiB297

zend_stack.cH A D28-Sep-20233.9 KiB161115

zend_stack.hH A D03-Nov-20242.4 KiB5226

zend_stream.cH A D28-Sep-20238.2 KiB289226

zend_stream.hH A D03-Nov-20243.5 KiB10166

zend_string.cH A D03-Nov-202415.9 KiB531413

zend_string.hH A D03-Nov-202421.9 KiB644501

zend_strtod.cH A D03-Nov-202492.1 KiB4,6384,003

zend_strtod.hH A D03-Nov-20242.1 KiB4621

zend_strtod_int.hH A D03-Nov-20243.1 KiB12877

zend_system_id.cH A D03-Nov-20243.1 KiB9263

zend_system_id.hH A D03-Nov-20241.4 KiB319

zend_type_info.hH A D03-Nov-20234.4 KiB8551

zend_types.hH A D03-Nov-202450.8 KiB1,5781,203

zend_variables.cH A D28-Sep-20234.6 KiB13696

zend_variables.hH A D03-Nov-20243 KiB9357

zend_virtual_cwd.cH A D03-Nov-202442.9 KiB1,7591,427

zend_virtual_cwd.hH A D03-Nov-202412.5 KiB395303

zend_vm.hH A D03-Nov-20241.9 KiB4217

zend_vm_def.hH A D03-Nov-2024285.7 KiB10,1438,742

zend_vm_execute.hH A D03-Nov-20242.1 MiB65,82558,530

zend_vm_execute.sklH A D28-Sep-20233.9 KiB157133

zend_vm_gen.phpH A D03-Nov-2024137 KiB3,0532,694

zend_vm_handlers.hH A D03-Nov-202490 KiB1,8641,863

zend_vm_opcodes.cH A D03-Nov-20249 KiB461437

zend_vm_opcodes.hH A D03-Nov-202412.4 KiB293262

zend_vm_trace_handlers.hH A D28-Sep-20233.1 KiB11384

zend_vm_trace_lines.hH A D28-Sep-20231.7 KiB4319

zend_vm_trace_map.hH A D28-Sep-20232.6 KiB8256

zend_weakrefs.cH A D03-Nov-202424.9 KiB778611

zend_weakrefs.hH A D28-Sep-20233.2 KiB7536

zend_weakrefs.stub.phpH A D28-Sep-2023826 4016

zend_weakrefs_arginfo.hH A D03-Nov-20243.4 KiB8965

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