• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Optimizer/H15-Dec-2021-24,04820,407

asm/H15-Dec-2021-4,8642,481

tests/H03-May-2022-118,597100,941

LICENSEH A D15-Dec-20212.7 KiB5747

Makefile.fragH A D15-Dec-20212.5 KiB4930

README.mdH A D15-Dec-20214.5 KiB140116

Zend.m4H A D15-Dec-202110.9 KiB389338

bench.phpH A D15-Dec-20217.5 KiB423347

micro_bench.phpH A D15-Dec-20217.1 KiB359307

zend.cH A D15-Dec-202153.7 KiB1,8971,508

zend.hH A D15-Dec-202114.8 KiB407299

zend_API.cH A D15-Dec-2021142.9 KiB4,9193,934

zend_API.hH A D15-Dec-202193.5 KiB2,2781,817

zend_alloc.cH A D15-Dec-202191 KiB3,0752,555

zend_alloc.hH A D15-Dec-202118.8 KiB409237

zend_alloc_sizes.hH A D15-Dec-20212.6 KiB6541

zend_arena.hH A D15-Dec-20215.9 KiB225169

zend_ast.cH A D15-Dec-202167.5 KiB2,4322,170

zend_ast.hH A D15-Dec-202112.6 KiB375297

zend_attributes.cH A D15-Dec-20218.9 KiB297214

zend_attributes.hH A D15-Dec-20215.1 KiB12076

zend_attributes.stub.phpH A D15-Dec-2021235 1610

zend_attributes_arginfo.hH A D15-Dec-20211.8 KiB5436

zend_bitset.hH A D15-Dec-20217.7 KiB295227

zend_build.hH A D15-Dec-20211.6 KiB4721

zend_builtin_functions.cH A D15-Dec-202150.2 KiB1,9211,439

zend_builtin_functions.hH A D15-Dec-20211.5 KiB307

zend_builtin_functions.stub.phpH A D15-Dec-20214.6 KiB19862

zend_builtin_functions_arginfo.hH A D15-Dec-202113.3 KiB358288

zend_closures.cH A D15-Dec-202127.2 KiB845635

zend_closures.hH A D15-Dec-20212.2 KiB4517

zend_closures.stub.phpH A D15-Dec-2021547 2513

zend_closures_arginfo.hH A D15-Dec-20212 KiB5439

zend_compile.cH A D15-Dec-2021309.5 KiB10,5428,459

zend_compile.hH A D15-Dec-202145.7 KiB1,160736

zend_config.w32.hH A D15-Dec-20212 KiB6130

zend_constants.cH A D15-Dec-202118.9 KiB602422

zend_constants.hH A D15-Dec-20216.5 KiB10670

zend_cpuinfo.cH A D15-Dec-20214.5 KiB154113

zend_cpuinfo.hH A D15-Dec-20217.4 KiB224162

zend_default_classes.cH A D15-Dec-20211.8 KiB4423

zend_dtrace.cH A D15-Dec-20214.2 KiB12278

zend_dtrace.dH A D15-Dec-20212.1 KiB3613

zend_dtrace.hH A D15-Dec-20212 KiB4922

zend_enum.cH A D15-Dec-202116.4 KiB479384

zend_enum.hH A D15-Dec-20212.6 KiB6032

zend_enum.stub.phpH A D15-Dec-2021273 1610

zend_enum_arginfo.hH A D15-Dec-20211.7 KiB5032

zend_errors.hH A D15-Dec-20212.3 KiB5123

zend_exceptions.cH A D15-Dec-202131.5 KiB1,027768

zend_exceptions.hH A D15-Dec-20214.4 KiB9449

zend_exceptions.stub.phpH A D15-Dec-20213.7 KiB17190

zend_exceptions_arginfo.hH A D15-Dec-202116.9 KiB398288

zend_execute.cH A D15-Dec-2021154.6 KiB5,0844,317

zend_execute.hH A D15-Dec-202119.4 KiB482359

zend_execute_API.cH A D15-Dec-202147.5 KiB1,7971,437

zend_extensions.cH A D15-Dec-202110.3 KiB339265

zend_extensions.hH A D15-Dec-20216 KiB15785

zend_fibers.cH A D15-Dec-202125.5 KiB917640

zend_fibers.hH A D15-Dec-20214.6 KiB14971

zend_fibers.stub.phpH A D15-Dec-2021752 3819

zend_fibers_arginfo.hH A D15-Dec-20213.5 KiB9770

zend_float.cH A D15-Dec-20211.8 KiB5730

zend_float.hH A D15-Dec-202115.1 KiB416259

zend_gc.cH A D15-Dec-202141.6 KiB1,7141,404

zend_gc.hH A D15-Dec-20213.8 KiB12678

zend_gdb.cH A D15-Dec-20213.8 KiB14298

zend_gdb.hH A D15-Dec-20211.4 KiB286

zend_generators.cH A D15-Dec-202133.5 KiB1,125794

zend_generators.hH A D15-Dec-20217.2 KiB13162

zend_generators.stub.phpH A D15-Dec-2021533 3115

zend_generators_arginfo.hH A D15-Dec-20212.7 KiB7653

zend_globals.hH A D15-Dec-20218.6 KiB345213

zend_globals_macros.hH A D15-Dec-20212.7 KiB7238

zend_hash.cH A D15-Dec-202171.3 KiB2,8852,450

zend_hash.hH A D15-Dec-202139.7 KiB1,3341,036

zend_highlight.cH A D15-Dec-20215.7 KiB231186

zend_highlight.hH A D15-Dec-20212.2 KiB5124

zend_inheritance.cH A D15-Dec-2021105.3 KiB3,0852,493

zend_inheritance.hH A D15-Dec-20212.3 KiB4516

zend_ini.cH A D15-Dec-202116.5 KiB632468

zend_ini.hH A D15-Dec-20219.9 KiB206144

zend_ini_parser.cH A D15-Dec-202173.7 KiB2,2421,532

zend_ini_parser.hH A D15-Dec-20213.4 KiB9849

zend_ini_parser.outputH A D15-Dec-202124 KiB939598

zend_ini_parser.yH A D15-Dec-202111.8 KiB414318

zend_ini_scanner.cH A D15-Dec-202183.8 KiB3,7673,590

zend_ini_scanner.hH A D15-Dec-20211.8 KiB3814

zend_ini_scanner.lH A D15-Dec-202116.9 KiB660439

zend_ini_scanner_defs.hH A D15-Dec-2021186 1310

zend_interfaces.cH A D15-Dec-202119.3 KiB617449

zend_interfaces.hH A D15-Dec-20213.6 KiB7238

zend_interfaces.stub.phpH A D15-Dec-20211.7 KiB8643

zend_interfaces_arginfo.hH A D15-Dec-20217.8 KiB216151

zend_istdiostream.hH A D15-Dec-20211.5 KiB3513

zend_iterators.cH A D15-Dec-20213.2 KiB10674

zend_iterators.hH A D15-Dec-20213.5 KiB8531

zend_language_parser.cH A D15-Dec-2021358.4 KiB7,2315,963

zend_language_parser.hH A D15-Dec-202110.5 KiB236184

zend_language_parser.outputH A D15-Dec-20211.4 MiB33,19427,988

zend_language_parser.yH A D15-Dec-202158.3 KiB1,7061,428

zend_language_scanner.cH A D15-Dec-2021218.1 KiB9,8909,437

zend_language_scanner.hH A D15-Dec-20213 KiB8649

zend_language_scanner.lH A D15-Dec-202174.4 KiB3,1402,478

zend_language_scanner_defs.hH A D15-Dec-2021266 1613

zend_list.cH A D15-Dec-20219.1 KiB348258

zend_list.hH A D15-Dec-20213.4 KiB7740

zend_llist.cH A D15-Dec-20216.7 KiB312229

zend_llist.hH A D15-Dec-20213.7 KiB7747

zend_long.hH A D15-Dec-20214.1 KiB12896

zend_map_ptr.hH A D15-Dec-20213.6 KiB9666

zend_modules.hH A D15-Dec-20214.7 KiB13291

zend_multibyte.cH A D15-Dec-20217.2 KiB213159

zend_multibyte.hH A D15-Dec-20214.8 KiB8045

zend_multiply.hH A D15-Dec-20219.6 KiB344272

zend_object_handlers.cH A D15-Dec-202157.5 KiB1,9411,588

zend_object_handlers.hH A D15-Dec-202114 KiB277133

zend_objects.cH A D15-Dec-20219.1 KiB285222

zend_objects.hH A D15-Dec-20211.8 KiB3612

zend_objects_API.cH A D15-Dec-20216.7 KiB209151

zend_objects_API.hH A D15-Dec-20214.5 KiB11770

zend_observer.cH A D15-Dec-202110.4 KiB322240

zend_observer.hH A D15-Dec-20214.1 KiB9652

zend_opcode.cH A D15-Dec-202135.7 KiB1,2211,021

zend_operators.cH A D15-Dec-202185.8 KiB3,4222,868

zend_operators.hH A D15-Dec-202129.8 KiB914760

zend_portability.hH A D15-Dec-202120.7 KiB683529

zend_ptr_stack.cH A D15-Dec-20212.9 KiB11876

zend_ptr_stack.hH A D15-Dec-20214.2 KiB11977

zend_range_check.hH A D15-Dec-20212.9 KiB6832

zend_signal.cH A D15-Dec-202112.7 KiB446314

zend_signal.hH A D15-Dec-20214 KiB11372

zend_smart_str.cH A D15-Dec-20216.8 KiB224181

zend_smart_str.hH A D15-Dec-20215.7 KiB156119

zend_smart_str_public.hH A D15-Dec-20211.1 KiB267

zend_smart_string.hH A D15-Dec-20214.1 KiB11478

zend_smart_string_public.hH A D15-Dec-20211.2 KiB309

zend_sort.cH A D15-Dec-20219.2 KiB308192

zend_sort.hH A D15-Dec-20211.5 KiB297

zend_stack.cH A D15-Dec-20213.8 KiB161115

zend_stack.hH A D15-Dec-20212.3 KiB5024

zend_stream.cH A D15-Dec-20218.1 KiB286223

zend_stream.hH A D15-Dec-20213.5 KiB10166

zend_string.cH A D15-Dec-202114.4 KiB486374

zend_string.hH A D15-Dec-202119.1 KiB584457

zend_strtod.cH A D15-Dec-202192.1 KiB4,6384,003

zend_strtod.hH A D15-Dec-20212.1 KiB4621

zend_strtod_int.hH A D15-Dec-20213.3 KiB14491

zend_system_id.cH A D15-Dec-20213.1 KiB9263

zend_system_id.hH A D15-Dec-20211.4 KiB319

zend_type_info.hH A D15-Dec-20214.3 KiB8450

zend_types.hH A D15-Dec-202144.8 KiB1,4311,086

zend_variables.cH A D15-Dec-20214.7 KiB13696

zend_variables.hH A D15-Dec-20213 KiB9357

zend_virtual_cwd.cH A D15-Dec-202142.7 KiB1,7491,417

zend_virtual_cwd.hH A D15-Dec-202112.3 KiB385294

zend_vm.hH A D15-Dec-20211.9 KiB4116

zend_vm_def.hH A D15-Dec-2021275.3 KiB9,8148,447

zend_vm_execute.hH A D15-Dec-20212 MiB63,02355,992

zend_vm_execute.sklH A D15-Dec-20213.6 KiB147124

zend_vm_gen.phpH A D15-Dec-2021137.8 KiB3,0872,725

zend_vm_handlers.hH A D15-Dec-202189.4 KiB1,8531,852

zend_vm_opcodes.cH A D15-Dec-20218.9 KiB458434

zend_vm_opcodes.hH A D15-Dec-202112.4 KiB293262

zend_vm_trace_handlers.hH A D15-Dec-20213.1 KiB11384

zend_vm_trace_lines.hH A D15-Dec-20211.7 KiB4319

zend_vm_trace_map.hH A D15-Dec-20212.6 KiB8256

zend_weakrefs.cH A D15-Dec-202119.3 KiB653512

zend_weakrefs.hH A D15-Dec-20211.7 KiB4721

zend_weakrefs.stub.phpH A D15-Dec-2021826 4016

zend_weakrefs_arginfo.hH A D15-Dec-20213.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
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