Folus Wen dd8509b6b1 [Add][GPL][php] 2 lat temu
..
Optimizer dd8509b6b1 [Add][GPL][php] 2 lat temu
asm dd8509b6b1 [Add][GPL][php] 2 lat temu
tests dd8509b6b1 [Add][GPL][php] 2 lat temu
LICENSE dd8509b6b1 [Add][GPL][php] 2 lat temu
Makefile.frag dd8509b6b1 [Add][GPL][php] 2 lat temu
README.md dd8509b6b1 [Add][GPL][php] 2 lat temu
Zend.m4 dd8509b6b1 [Add][GPL][php] 2 lat temu
bench.php dd8509b6b1 [Add][GPL][php] 2 lat temu
micro_bench.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_API.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_API.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_alloc.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_alloc.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_alloc_sizes.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_arena.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ast.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ast.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_attributes.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_attributes.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_attributes.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_attributes_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_bitset.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_build.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_builtin_functions.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_builtin_functions.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_builtin_functions.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_builtin_functions_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_closures.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_closures.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_closures.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_closures_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_compile.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_compile.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_config.w32.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_constants.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_constants.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_cpuinfo.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_cpuinfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_default_classes.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_dtrace.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_dtrace.d dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_dtrace.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_enum.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_enum.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_enum.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_enum_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_errors.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_exceptions.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_exceptions.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_exceptions.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_exceptions_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_execute.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_execute.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_execute_API.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_extensions.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_extensions.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_fibers.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_fibers.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_fibers.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_fibers_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_float.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_float.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_gc.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_gc.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_gdb.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_gdb.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_generators.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_generators.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_generators.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_generators_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_globals.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_globals_macros.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_hash.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_hash.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_highlight.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_highlight.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_inheritance.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_inheritance.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ini.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ini.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ini_parser.y dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ini_scanner.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ini_scanner.l dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_interfaces.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_interfaces.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_interfaces.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_interfaces_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_istdiostream.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_iterators.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_iterators.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_language_parser.y dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_language_scanner.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_language_scanner.l dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_list.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_list.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_llist.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_llist.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_long.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_map_ptr.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_modules.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_multibyte.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_multibyte.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_multiply.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_object_handlers.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_object_handlers.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_objects.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_objects.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_objects_API.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_objects_API.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_observer.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_observer.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_opcode.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_operators.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_operators.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_portability.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ptr_stack.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_ptr_stack.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_range_check.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_signal.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_signal.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_smart_str.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_smart_str.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_smart_str_public.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_smart_string.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_smart_string_public.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_sort.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_sort.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_stack.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_stack.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_stream.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_stream.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_string.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_string.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_strtod.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_strtod.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_strtod_int.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_system_id.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_system_id.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_type_info.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_types.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_variables.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_variables.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_virtual_cwd.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_virtual_cwd.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_def.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_execute.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_execute.skl dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_gen.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_handlers.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_opcodes.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_opcodes.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_trace_handlers.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_trace_lines.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_vm_trace_map.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_weakrefs.c dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_weakrefs.h dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_weakrefs.stub.php dd8509b6b1 [Add][GPL][php] 2 lat temu
zend_weakrefs_arginfo.h dd8509b6b1 [Add][GPL][php] 2 lat temu

README.md

Zend Engine

Zend memory manager

General

The goal of the new memory manager (available since PHP 5.2) is to reduce memory allocation overhead and speedup memory management.

Debugging

Normal:

sapi/cli/php -r 'leak();'

Zend MM disabled:

USE_ZEND_ALLOC=0 valgrind --leak-check=full sapi/cli/php -r 'leak();'

Shared extensions

Since PHP 5.3.11 it is possible to prevent shared extensions from unloading so that valgrind can correctly track the memory leaks in shared extensions. For this there is the ZEND_DONT_UNLOAD_MODULES environment variable. If set, then DL_UNLOAD() is skipped during the shutdown of shared extensions.

ZEND_VM

ZEND_VM architecture allows specializing opcode handlers according to op_type fields and using different execution methods (call threading, switch threading and direct threading). As a result ZE2 got more than 20% speedup on raw PHP code execution (with specialized executor and direct threading execution method). As in most PHP applications raw execution speed isn't the limiting factor but system calls and database calls are, your mileage with this patch will vary.

Most parts of the old zend_execute.c go into zend_vm_def.h. Here you can find opcode handlers and helpers. The typical opcode handler template looks like this:

ZEND_VM_HANDLER(<OPCODE-NUMBER>, <OPCODE>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HANDLER'S CODE>
}

<OPCODE-NUMBER> is a opcode number (0, 1, ...) <OPCODE> is an opcode name (ZEN_NOP, ZEND_ADD, :) <OP1_TYPES> and <OP2_TYPES> are masks for allowed operand op_types. Specializer will generate code only for defined combination of types. You can use any combination of the following op_types UNUSED, CONST, VAR, TMP and CV also you can use ANY mask to disable specialization according operand's op_type. <HANDLER'S CODE> is a handler's code itself. For most handlers it stills the same as in old zend_execute.c, but now it uses macros to access opcode operands and some internal executor data.

You can see the conformity of new macros to old code in the following list:

EXECUTE_DATA
    execute_data
ZEND_VM_DISPATCH_TO_HANDLER(<OP>)
    return <OP>_helper(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER(<NAME>)
    return <NAME>(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER_EX(<NAME>,<PARAM>,<VAL>)
    return <NAME>(<VAL>, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_CONTINUE()
    return 0
ZEND_VM_NEXT_OPCODE()
    NEXT_OPCODE()
ZEND_VM_SET_OPCODE(<TARGET>
    SET_OPCODE(<TARGET>
ZEND_VM_INC_OPCODE()
    INC_OPCOD()
ZEND_VM_RETURN_FROM_EXECUTE_LOOP()
    RETURN_FROM_EXECUTE_LOOP()
ZEND_VM_C_LABEL(<LABEL>):
    <LABEL>:
ZEND_VM_C_GOTO(<LABEL>)
    goto <LABEL>
OP<X>_TYPE
    opline->op<X>.op_type
GET_OP<X>_ZVAL_PTR(<TYPE>)
    get_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_ZVAL_PTR_PTR(<TYPE>)
    get_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR(<TYPE>)
    get_obj_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR_PTR(<TYPE>)
    get_obj_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
IS_OP<X>_TMP_FREE()
    IS_TMP_FREE(free_op<X>)
FREE_OP<X>()
    FREE_OP(free_op<X>)
FREE_OP<X>_IF_VAR()
    FREE_VAR(free_op<X>)
FREE_OP<X>_VAR_PTR()
    FREE_VAR_PTR(free_op<X>)

Executor's helpers can be defined without parameters or with one parameter. This is done with the following constructs:

ZEND_VM_HELPER(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HELPER'S CODE>
}

ZEND_VM_HELPER_EX(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>, <PARAM_SPEC>)
{
    <HELPER'S CODE>
}

Executor's code is generated by PHP script zend_vm_gen.php it uses zend_vm_def.h and zend_vm_execute.skl as input and produces zend_vm_opcodes.h and zend_vm_execute.h. The first file is a list of opcode definitions. It is included from zend_compile.h. The second one is an executor code itself. It is included from zend_execute.c.

zend_vm_gen.php can produce different kind of executors. You can select different opcode threading model using --with-vm-kind=CALL|SWITCH|GOTO. You can disable opcode specialization using --without-specializer. You can include or exclude old executor together with specialized one using --without-old-executor. At last you can debug executor using original zend_vm_def.h or generated file zend_vm_execute.h. Debugging with original file requires --with-lines option. By default ZE2 uses the following command to generate executor:

php zend_vm_gen.php --with-vm-kind=CALL