Name Date Size #Lines LOC

..31-Oct-2022-

tests/H16-Nov-2021-

LICENSEH A D05-Dec-20192.7 KiB5747

Makefile.fragH A D05-Dec-20192 KiB3824

README.mdH A D05-Dec-20194.5 KiB140116

Zend.m4H A D05-Oct-202013.8 KiB532464

bench.phpH A D05-Feb-20207.5 KiB423347

micro_bench.phpH A D05-Feb-20207.1 KiB359307

zend.cH A D24-Nov-202049.6 KiB1,7871,423

zend.hH A D13-Mar-202013.6 KiB359257

zend_API.cH A D23-Jul-2021129.4 KiB4,4883,617

zend_API.hH A D05-Dec-201969.4 KiB1,7521,391

zend_alloc.cH A D31-May-202189.5 KiB3,0142,504

zend_alloc.hH A D05-Feb-202018.8 KiB408236

zend_alloc_sizes.hH A D05-Dec-20192.6 KiB6541

zend_arena.hH A D05-Dec-20195.9 KiB225169

zend_ast.cH A D05-Feb-202058.8 KiB2,1061,887

zend_ast.hH A D05-Dec-201911.4 KiB343272

zend_bitset.hH A D05-Dec-20196.7 KiB255193

zend_build.hH A D05-Dec-20191.6 KiB4721

zend_builtin_functions.cH A D31-Jul-202073.7 KiB2,6912,067

zend_builtin_functions.hH A D05-Dec-20191.5 KiB307

zend_closures.cH A D16-Nov-202126.6 KiB809609

zend_closures.hH A D05-Dec-20192.2 KiB4416

zend_compile.cH A D01-Jul-2021261.9 KiB9,0507,255

zend_compile.hH A D05-Dec-201942.6 KiB1,109701

zend_config.w32.hH A D05-Dec-20192.6 KiB8348

zend_constants.cH A D05-Dec-201917.2 KiB535426

zend_constants.hH A D05-Dec-20196.2 KiB9762

zend_cpuinfo.cH A D27-Nov-20204.5 KiB153112

zend_cpuinfo.hH A D05-Dec-20197.1 KiB210149

zend_default_classes.cH A D05-Dec-20191.6 KiB3817

zend_dtrace.cH A D05-Dec-20194 KiB11572

zend_dtrace.dH A D05-Dec-20192.1 KiB3613

zend_dtrace.hH A D05-Dec-20191.9 KiB4721

zend_errors.hH A D05-Dec-20192 KiB4320

zend_exceptions.cH A D30-Jun-202034 KiB1,071810

zend_exceptions.hH A D05-Dec-20193.8 KiB8339

zend_execute.cH A D02-Jul-2021145.5 KiB4,7694,068

zend_execute.hH A D10-Dec-201916.5 KiB436323

zend_execute_API.cH A D15-Dec-202046.1 KiB1,6621,326

zend_extensions.cH A D05-Dec-20199.9 KiB332258

zend_extensions.hH A D05-Dec-20195.9 KiB15785

zend_float.cH A D22-May-20201.8 KiB5730

zend_float.hH A D26-May-202015.1 KiB416259

zend_gc.cH A D05-Dec-201939.1 KiB1,6261,335

zend_gc.hH A D05-Dec-20192.8 KiB8849

zend_generators.cH A D18-Nov-202037.9 KiB1,263899

zend_generators.hH A D05-Dec-20197.2 KiB13767

zend_globals.hH A D13-Dec-20197.6 KiB316195

zend_globals_macros.hH A D05-Dec-20192.7 KiB7238

zend_hash.cH A D01-Mar-202170.2 KiB2,8352,413

zend_hash.hH A D05-Dec-201935.6 KiB1,193931

zend_highlight.cH A D05-Dec-20195.8 KiB231185

zend_highlight.hH A D05-Dec-20192.2 KiB5124

zend_inheritance.cH A D06-Oct-202090 KiB2,6132,109

zend_inheritance.hH A D05-Dec-20192 KiB4315

zend_ini.cH A D21-Aug-202017.4 KiB701518

zend_ini.hH A D05-Dec-20199.6 KiB198138

zend_ini_parser.yH A D14-May-202011.8 KiB424318

zend_ini_scanner.hH A D05-Dec-20191.8 KiB3814

zend_ini_scanner.lH A D10-Feb-202016.8 KiB663435

zend_interfaces.cH A D05-Dec-201919.2 KiB609458

zend_interfaces.hH A D05-Dec-20194.2 KiB8347

zend_istdiostream.hH A D05-Dec-20191.5 KiB3513

zend_iterators.cH A D05-Dec-20193.1 KiB10573

zend_iterators.hH A D05-Dec-20193.3 KiB8130

zend_language_parser.yH A D30-Jan-202048.1 KiB1,3971,186

zend_language_scanner.hH A D05-Dec-20192.7 KiB7742

zend_language_scanner.lH A D16-Dec-202068.1 KiB2,9132,305

zend_list.cH A D31-Aug-20219.1 KiB354267

zend_list.hH A D05-Dec-20193.4 KiB7740

zend_llist.cH A D05-Dec-20196.7 KiB310227

zend_llist.hH A D05-Dec-20193.7 KiB7747

zend_long.hH A D05-Dec-20194.2 KiB13098

zend_map_ptr.hH A D05-Dec-20193.1 KiB8657

zend_modules.hH A D05-Dec-20194.7 KiB13291

zend_multibyte.cH A D05-Dec-20197.2 KiB213159

zend_multibyte.hH A D05-Dec-20194.7 KiB8045

zend_multiply.hH A D05-Dec-20199.6 KiB344272

zend_object_handlers.cH A D15-Jul-202156.6 KiB1,9481,567

zend_object_handlers.hH A D05-Dec-201913.2 KiB260134

zend_objects.cH A D05-Dec-20199.5 KiB317246

zend_objects.hH A D05-Dec-20191.8 KiB3612

zend_objects_API.cH A D05-Dec-20196.6 KiB202146

zend_objects_API.hH A D05-Dec-20194.6 KiB11870

zend_opcode.cH A D05-Feb-202033.2 KiB1,110932

zend_operators.cH A D17-Aug-202181.4 KiB3,2832,757

zend_operators.hH A D23-Feb-202033.3 KiB984831

zend_portability.hH A D30-Jan-202019.7 KiB660519

zend_ptr_stack.cH A D05-Dec-20193 KiB11876

zend_ptr_stack.hH A D05-Dec-20194.2 KiB11977

zend_range_check.hH A D05-Dec-20192.9 KiB6832

zend_signal.cH A D15-Dec-202012.7 KiB449315

zend_signal.hH A D05-Dec-20194 KiB11372

zend_smart_str.cH A D16-Sep-20215.5 KiB174140

zend_smart_str.hH A D05-Dec-20195.4 KiB153115

zend_smart_str_public.hH A D05-Dec-20191.2 KiB287

zend_smart_string.hH A D05-Dec-20194.3 KiB11678

zend_smart_string_public.hH A D05-Dec-20191.4 KiB329

zend_sort.cH A D05-Dec-201910.6 KiB375244

zend_sort.hH A D05-Dec-20191.6 KiB308

zend_stack.cH A D05-Dec-20193.9 KiB165118

zend_stack.hH A D05-Dec-20192.3 KiB5024

zend_stream.cH A D24-Apr-20207 KiB252196

zend_stream.hH A D05-Dec-20193.5 KiB9963

zend_string.cH A D05-Dec-201912.4 KiB464362

zend_string.hH A D29-Nov-202117.1 KiB527405

zend_strtod.cH A D30-Jan-202090.5 KiB4,5623,929

zend_strtod.hH A D05-Dec-20191.8 KiB3714

zend_strtod_int.hH A D05-Dec-20193.4 KiB14895

zend_ts_hash.cH A D05-Dec-20198 KiB356265

zend_ts_hash.hH A D05-Dec-20195.6 KiB13984

zend_type_info.hH A D05-Dec-20193 KiB5933

zend_types.hH A D11-Dec-201939.6 KiB1,284989

zend_variables.cH A D05-Dec-20194.6 KiB13494

zend_variables.hH A D05-Dec-20193.2 KiB9761

zend_virtual_cwd.cH A D25-May-202142.7 KiB1,7511,419

zend_virtual_cwd.hH A D05-Dec-201912.4 KiB386294

zend_vm.hH A D05-Dec-20191.9 KiB4116

zend_vm_def.hH A D18-Aug-2021264.9 KiB9,4248,119

zend_vm_execute.hH A D18-Aug-20211.9 MiB61,48053,846

zend_vm_execute.sklH A D26-May-20203.5 KiB145122

zend_vm_gen.phpH A D05-Feb-2020142.8 KiB3,2022,843

zend_vm_handlers.hH A D05-Dec-201985.9 KiB1,7771,776

zend_vm_opcodes.cH A D05-Dec-20198.3 KiB433409

zend_vm_opcodes.hH A D05-Dec-201911.8 KiB278248

zend_vm_trace_handlers.hH A D05-Dec-20193.1 KiB11384

zend_vm_trace_map.hH A D05-Dec-20192.6 KiB8256

zend_weakrefs.cH A D05-Dec-20196.4 KiB214142

zend_weakrefs.hH A D05-Dec-20191.4 KiB3710

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