Name Date Size #Lines LOC

..09-Jan-2024-

tests/H08-Sep-2022-

LICENSEH A D02-Dec-20202.7 KiB5747

Makefile.fragH A D02-Dec-20202 KiB3824

README.mdH A D02-Dec-20204.5 KiB140116

Zend.m4H A D04-Aug-20229.4 KiB347302

bench.phpH A D02-Dec-20207.5 KiB423347

micro_bench.phpH A D02-Dec-20207.1 KiB359307

zend.cH A D07-Mar-202251 KiB1,8011,432

zend.hH A D09-Jan-202413.5 KiB360258

zend_API.cH A D09-Jun-2022131.8 KiB4,5603,644

zend_API.hH A D09-Jun-202290 KiB2,2421,780

zend_alloc.cH A D08-Feb-202291.6 KiB3,0882,566

zend_alloc.hH A D31-May-202118.8 KiB409237

zend_alloc_sizes.hH A D22-Aug-20222.6 KiB6541

zend_arena.hH A D02-Dec-20205.9 KiB225169

zend_ast.cH A D02-Dec-202063.4 KiB2,2822,039

zend_ast.hH A D02-Dec-202012.3 KiB365290

zend_attributes.cH A D07-Mar-20229.1 KiB304221

zend_attributes.hH A D02-Dec-20205.1 KiB12076

zend_attributes.stub.phpH A D02-Dec-2020139 95

zend_attributes_arginfo.hH A D02-Dec-2020503 168

zend_bitset.hH A D02-Dec-20207.8 KiB295227

zend_build.hH A D02-Dec-20201.6 KiB4721

zend_builtin_functions.cH A D25-May-202156.2 KiB2,1661,655

zend_builtin_functions.hH A D02-Dec-20201.5 KiB307

zend_builtin_functions.stub.phpH A D02-Dec-20203.7 KiB13158

zend_builtin_functions_arginfo.hH A D02-Dec-202012.7 KiB336272

zend_closures.cH A D16-Nov-202126.1 KiB807607

zend_closures.hH A D02-Dec-20202.2 KiB4416

zend_closures.stub.phpH A D02-Dec-2020499 2113

zend_closures_arginfo.hH A D02-Dec-20201.7 KiB4331

zend_compile.cH A D08-Sep-2022289.5 KiB9,9897,999

zend_compile.hH A D26-Jan-202143.8 KiB1,140726

zend_config.w32.hH A D02-Dec-20202.2 KiB7136

zend_constants.cH A D02-Dec-202016.3 KiB518412

zend_constants.hH A D02-Dec-20206.3 KiB10569

zend_cpuinfo.cH A D23-Dec-20214.5 KiB154113

zend_cpuinfo.hH A D02-Dec-20207.3 KiB224162

zend_default_classes.cH A D02-Dec-20201.7 KiB4019

zend_dtrace.cH A D02-Dec-20204.2 KiB12278

zend_dtrace.dH A D02-Dec-20202.1 KiB3613

zend_dtrace.hH A D02-Dec-20202 KiB4922

zend_errors.hH A D02-Dec-20202.3 KiB5123

zend_exceptions.cH A D23-Oct-202232 KiB1,028781

zend_exceptions.hH A D02-Dec-20204 KiB8843

zend_exceptions.stub.phpH A D09-Feb-20212.9 KiB13068

zend_exceptions_arginfo.hH A D09-Feb-20217.9 KiB188128

zend_execute.cH A D04-Nov-2022153 KiB5,0724,319

zend_execute.hH A D04-Nov-202218.2 KiB456337

zend_execute_API.cH A D03-May-202247.4 KiB1,7501,397

zend_extensions.cH A D01-Mar-202210.6 KiB348273

zend_extensions.hH A D01-Mar-20226 KiB15886

zend_float.cH A D02-Dec-20201.8 KiB5730

zend_float.hH A D02-Dec-202015.1 KiB416259

zend_gc.cH A D02-Dec-202040.2 KiB1,6631,366

zend_gc.hH A D10-Dec-20203.8 KiB12678

zend_gdb.cH A D21-Dec-20214.3 KiB159112

zend_gdb.hH A D02-Dec-20201.4 KiB286

zend_generators.cH A D04-Nov-202235 KiB1,169820

zend_generators.hH A D02-Dec-20207.3 KiB13465

zend_generators.stub.phpH A D09-Feb-2021485 2715

zend_generators_arginfo.hH A D09-Feb-20212 KiB5437

zend_globals.hH A D02-Dec-20207.9 KiB322199

zend_globals_macros.hH A D02-Dec-20202.7 KiB7238

zend_hash.cH A D01-Mar-202170.9 KiB2,8602,429

zend_hash.hH A D02-Dec-202037.7 KiB1,264983

zend_highlight.cH A D02-Dec-20205.8 KiB231185

zend_highlight.hH A D02-Dec-20202.2 KiB5124

zend_inheritance.cH A D05-Nov-202189.2 KiB2,5962,090

zend_inheritance.hH A D02-Dec-20201.9 KiB4214

zend_ini.cH A D02-Dec-202016.6 KiB631467

zend_ini.hH A D02-Dec-20209.9 KiB206144

zend_ini_parser.yH A D02-Dec-202011.8 KiB415319

zend_ini_scanner.hH A D02-Dec-20201.8 KiB3814

zend_ini_scanner.lH A D02-Dec-202016.8 KiB656435

zend_interfaces.cH A D15-Apr-202119.9 KiB636463

zend_interfaces.hH A D02-Dec-20204.3 KiB8649

zend_interfaces.stub.phpH A D28-Jan-20211.5 KiB8543

zend_interfaces_arginfo.hH A D28-Jan-20215.2 KiB12281

zend_istdiostream.hH A D02-Dec-20201.5 KiB3513

zend_iterators.cH A D02-Dec-20203.2 KiB10674

zend_iterators.hH A D02-Dec-20203.5 KiB8531

zend_language_parser.yH A D02-Dec-202055.3 KiB1,6371,374

zend_language_scanner.hH A D02-Dec-20203 KiB8649

zend_language_scanner.lH A D16-Dec-202073.6 KiB3,0802,433

zend_list.cH A D31-Aug-20219 KiB345255

zend_list.hH A D02-Dec-20203.4 KiB7740

zend_llist.cH A D02-Dec-20206.7 KiB310227

zend_llist.hH A D02-Dec-20203.7 KiB7747

zend_long.hH A D02-Dec-20204.1 KiB12896

zend_map_ptr.hH A D02-Dec-20203.4 KiB9667

zend_modules.hH A D02-Dec-20204.7 KiB13291

zend_multibyte.cH A D02-Dec-20207.2 KiB213159

zend_multibyte.hH A D02-Dec-20204.8 KiB8045

zend_multiply.hH A D02-Dec-20209.6 KiB344272

zend_object_handlers.cH A D15-Jul-202155.1 KiB1,8481,511

zend_object_handlers.hH A D16-Feb-202113.5 KiB263132

zend_objects.cH A D02-Dec-20208.8 KiB277214

zend_objects.hH A D02-Dec-20201.8 KiB3612

zend_objects_API.cH A D02-Dec-20206.6 KiB202146

zend_objects_API.hH A D02-Dec-20204.6 KiB11870

zend_observer.cH A D01-Mar-20228.4 KiB251174

zend_observer.hH A D01-Mar-20223.3 KiB8443

zend_opcode.cH A D07-Mar-202234.8 KiB1,168981

zend_operators.cH A D04-Aug-202280.8 KiB3,2552,717

zend_operators.hH A D04-Aug-202230.5 KiB946788

zend_portability.hH A D04-Nov-202120.4 KiB670519

zend_ptr_stack.cH A D02-Dec-20203 KiB11876

zend_ptr_stack.hH A D02-Dec-20204.2 KiB11977

zend_range_check.hH A D02-Dec-20202.9 KiB6832

zend_signal.cH A D15-Dec-202012.7 KiB446314

zend_signal.hH A D02-Dec-20204 KiB11372

zend_smart_str.cH A D16-Sep-20215.4 KiB172140

zend_smart_str.hH A D02-Dec-20205.3 KiB151115

zend_smart_str_public.hH A D02-Dec-20201.1 KiB267

zend_smart_string.hH A D02-Dec-20204.1 KiB11478

zend_smart_string_public.hH A D02-Dec-20201.2 KiB309

zend_sort.cH A D02-Dec-20209.2 KiB308192

zend_sort.hH A D02-Dec-20201.5 KiB297

zend_stack.cH A D02-Dec-20203.8 KiB161115

zend_stack.hH A D02-Dec-20202.3 KiB5024

zend_stream.cH A D02-Dec-20207.1 KiB253196

zend_stream.hH A D02-Dec-20203.5 KiB9963

zend_string.cH A D02-Dec-202013.2 KiB494386

zend_string.hH A D29-Nov-202118.3 KiB567441

zend_strtod.cH A D02-Dec-202090.5 KiB4,5623,929

zend_strtod.hH A D02-Dec-20201.8 KiB3714

zend_strtod_int.hH A D02-Dec-20203.3 KiB14491

zend_system_id.cH A D02-Dec-20203.1 KiB9263

zend_system_id.hH A D02-Dec-20201.4 KiB319

zend_ts_hash.cH A D02-Dec-20208 KiB348261

zend_ts_hash.hH A D02-Dec-20205.3 KiB13480

zend_type_info.hH A D02-Dec-20203.7 KiB7442

zend_types.hH A D14-Jan-202143.8 KiB1,4121,077

zend_variables.cH A D02-Dec-20204.6 KiB13494

zend_variables.hH A D02-Dec-20203 KiB9357

zend_virtual_cwd.cH A D25-May-202142.7 KiB1,7491,416

zend_virtual_cwd.hH A D02-Dec-202012.3 KiB385294

zend_vm.hH A D02-Dec-20201.9 KiB4116

zend_vm_def.hH A D22-Oct-2022273.4 KiB9,7548,395

zend_vm_execute.hH A D22-Oct-20222 MiB63,65856,526

zend_vm_execute.sklH A D02-Dec-20203.6 KiB147124

zend_vm_gen.phpH A D02-Dec-2021136.8 KiB3,0572,701

zend_vm_handlers.hH A D01-Feb-202289.3 KiB1,8501,849

zend_vm_opcodes.cH A D01-Feb-20228.5 KiB443419

zend_vm_opcodes.hH A D02-Dec-202012.2 KiB289258

zend_vm_trace_handlers.hH A D02-Dec-20203.1 KiB11384

zend_vm_trace_lines.hH A D02-Dec-20201.7 KiB4319

zend_vm_trace_map.hH A D02-Dec-20202.6 KiB8256

zend_weakrefs.cH A D15-Jul-202219.8 KiB665523

zend_weakrefs.hH A D21-Oct-20211.7 KiB4721

zend_weakrefs.stub.phpH A D02-Dec-2020739 3416

zend_weakrefs_arginfo.hH A D02-Dec-20202.5 KiB6648

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
122Executor's code is generated by 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
129different opcode threading model using `--with-vm-kind=CALL|SWITCH|GOTO`. You
130can disable opcode specialization using `--without-specializer`. You can include
131or exclude old executor together with specialized one using
132`--without-old-executor`. At last you can debug executor using original
133`zend_vm_def.h` or generated file `zend_vm_execute.h`. Debugging with original
134file requires `--with-lines` option. By default ZE2 uses the following command
135to generate executor:
136
137```bash
138php zend_vm_gen.php --with-vm-kind=CALL
139```
140