PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_execute.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 87 90 96.7 %
Date: 2015-08-29 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifndef ZEND_EXECUTE_H
      23             : #define ZEND_EXECUTE_H
      24             : 
      25             : #include "zend_compile.h"
      26             : #include "zend_hash.h"
      27             : #include "zend_operators.h"
      28             : #include "zend_variables.h"
      29             : 
      30             : BEGIN_EXTERN_C()
      31             : struct _zend_fcall_info;
      32             : ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data);
      33             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      34             : 
      35             : void init_executor(void);
      36             : void shutdown_executor(void);
      37             : void shutdown_destructors(void);
      38             : ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
      39             : ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value);
      40             : ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
      41             : ZEND_API void execute_ex(zend_execute_data *execute_data);
      42             : ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
      43             : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
      44             : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload);
      45             : ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex);
      46             : ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex);
      47             : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name);
      48             : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name);
      49             : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions);
      50             : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions);
      51             : 
      52             : ZEND_API void ZEND_FASTCALL zend_check_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg);
      53             : ZEND_API int  ZEND_FASTCALL zend_check_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, void **cache_slot);
      54             : ZEND_API int  ZEND_FASTCALL zend_check_missing_arg(zend_execute_data *execute_data, uint32_t arg_num, void **cache_slot);
      55             : 
      56             : static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
      57             : {
      58    25536731 :         zend_refcounted *ref = NULL;
      59             : 
      60    25536731 :         if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
      61      847036 :                 ref = Z_COUNTED_P(value);
      62      847036 :                 value = Z_REFVAL_P(value);
      63             :         }
      64             : 
      65             :         do {
      66    25536731 :                 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
      67             :                         zend_refcounted *garbage;
      68             : 
      69    16839049 :                         if (Z_ISREF_P(variable_ptr)) {
      70     2786590 :                                 variable_ptr = Z_REFVAL_P(variable_ptr);
      71     2786590 :                                 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
      72             :                                         break;
      73             :                                 }
      74             :                         }
      75    15900592 :                         if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
      76      840993 :                         UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
      77           0 :                                 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
      78           0 :                                 return variable_ptr;
      79             :                         }
      80    15059599 :                         if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && variable_ptr == value) {
      81         120 :                                 return variable_ptr;
      82             :                         }
      83    15059479 :                         garbage = Z_COUNTED_P(variable_ptr);
      84    15059479 :                         if (--GC_REFCOUNT(garbage) == 0) {
      85     8352395 :                                 ZVAL_COPY_VALUE(variable_ptr, value);
      86     8352395 :                                 if (value_type == IS_CONST) {
      87             :                                         /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
      88     1011790 :                                         if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
      89       14601 :                                                 zval_copy_ctor_func(variable_ptr);
      90             :                                         }
      91     7340605 :                                 } else if (value_type == IS_CV) {
      92     1499028 :                                         if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
      93             :                                                 Z_ADDREF_P(variable_ptr);
      94             :                                         }
      95     5841577 :                                 } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
      96           4 :                                         if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
      97           0 :                                                 efree_size(ref, sizeof(zend_reference));
      98           4 :                                         } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
      99             :                                                 Z_ADDREF_P(variable_ptr);
     100             :                                         }
     101             :                                 }
     102     8352395 :                                 zval_dtor_func_for_ptr(garbage);
     103     8352394 :                                 return variable_ptr;
     104             :                         } else { /* we need to split */
     105             :                                 /* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
     106     7022930 :                                 if ((Z_COLLECTABLE_P(variable_ptr)) &&
     107      315846 :                                 UNEXPECTED(!GC_INFO(garbage))) {
     108       28015 :                                         gc_possible_root(garbage);
     109             :                                 }
     110             :                         }
     111             :                 }
     112             :         } while (0);
     113             : 
     114    17184216 :         ZVAL_COPY_VALUE(variable_ptr, value);
     115    17184216 :         if (value_type == IS_CONST) {
     116             :                 /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
     117     4442884 :                 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
     118      205752 :                         zval_copy_ctor_func(variable_ptr);
     119             :                 }
     120    12741332 :         } else if (value_type == IS_CV) {
     121     4107490 :                 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     122             :                         Z_ADDREF_P(variable_ptr);
     123             :                 }
     124     8633842 :         } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
     125          16 :                 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
     126           2 :                         efree_size(ref, sizeof(zend_reference));
     127          14 :                 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     128             :                         Z_ADDREF_P(variable_ptr);
     129             :                 }
     130             :         }
     131    17184216 :         return variable_ptr;
     132             : }
     133             : 
     134             : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change);
     135             : ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope);
     136             : 
     137             : /* dedicated Zend executor functions - do not use! */
     138             : struct _zend_vm_stack {
     139             :         zval *top;
     140             :         zval *end;
     141             :         zend_vm_stack prev;
     142             : };
     143             : 
     144             : #define ZEND_VM_STACK_HEADER_SLOTS \
     145             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     146             : 
     147             : #define ZEND_VM_STACK_ELEMETS(stack) \
     148             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
     149             : 
     150             : /*
     151             :  * In general in RELEASE build ZEND_ASSERT() must be zero-cost, but for some
     152             :  * reason, GCC generated worse code, performing CSE on assertion code and the
     153             :  * following "slow path" and moving memory read operatins from slow path into
     154             :  * common header. This made a degradation for the fast path.
     155             :  * The following "#if ZEND_DEBUG" eliminates it.
     156             :  */
     157             : #if ZEND_DEBUG
     158             : # define ZEND_ASSERT_VM_STACK(stack) ZEND_ASSERT(stack->top > (zval *) stack && stack->end > (zval *) stack && stack->top <= stack->end)
     159             : # define ZEND_ASSERT_VM_STACK_GLOBAL ZEND_ASSERT(EG(vm_stack_top) > (zval *) EG(vm_stack) && EG(vm_stack_end) > (zval *) EG(vm_stack) && EG(vm_stack_top) <= EG(vm_stack_end))
     160             : #else
     161             : # define ZEND_ASSERT_VM_STACK(stack)
     162             : # define ZEND_ASSERT_VM_STACK_GLOBAL
     163             : #endif
     164             : 
     165             : ZEND_API void zend_vm_stack_init(void);
     166             : ZEND_API void zend_vm_stack_destroy(void);
     167             : ZEND_API void* zend_vm_stack_extend(size_t size);
     168             : 
     169             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     170             : {
     171    27659292 :         zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
     172             : 
     173             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     174             : 
     175    27659292 :         if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
     176           4 :                 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
     177           4 :                 ZEND_SET_CALL_INFO(call, call_info | ZEND_CALL_ALLOCATED);
     178             :         } else {
     179    27659288 :                 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
     180    27659288 :                 ZEND_SET_CALL_INFO(call, call_info);
     181             :         }
     182             : 
     183             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     184             : 
     185    27659292 :         call->func = func;
     186    27659292 :         Z_OBJ(call->This) = object;
     187    27659292 :         ZEND_CALL_NUM_ARGS(call) = num_args;
     188    27659292 :         call->called_scope = called_scope;
     189    27659292 :         return call;
     190             : }
     191             : 
     192             : static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
     193             : {
     194     4417227 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     195             : 
     196     4417227 :         if (EXPECTED(ZEND_USER_CODE(func->type))) {
     197      971036 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     198             :         }
     199     4417227 :         return used_stack * sizeof(zval);
     200             : }
     201             : 
     202             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     203             : {
     204     4181930 :         uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
     205             : 
     206     4181930 :         return zend_vm_stack_push_call_frame_ex(used_stack, call_info,
     207             :                 func, num_args, called_scope, object);
     208             : }
     209             : 
     210             : static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_info, zend_execute_data *call)
     211             : {
     212     1774546 :         if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
     213         396 :                 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
     214         396 :                 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
     215             :                 do {
     216        1106 :                         p--;
     217        1106 :                         if (Z_REFCOUNTED_P(p)) {
     218         742 :                                 if (!Z_DELREF_P(p)) {
     219           6 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     220           6 :                                         ZVAL_NULL(p);
     221           6 :                                         zval_dtor_func_for_ptr(r);
     222             :                                 } else {
     223             :                                         GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
     224             :                                 }
     225             :                         }
     226        1106 :                 } while (p != end);
     227             :         }
     228             : }
     229             : 
     230             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
     231             : {
     232       50389 :         zend_vm_stack_free_extra_args_ex(ZEND_CALL_INFO(call), call);
     233             : }
     234             : 
     235             : static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
     236             : {
     237    25803564 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
     238             : 
     239    25803564 :         if (EXPECTED(num_args > 0)) {
     240    19520835 :                 zval *end = ZEND_CALL_ARG(call, 1);
     241    19520835 :                 zval *p = end + num_args;
     242             : 
     243             :                 do {
     244    34739872 :                         p--;
     245    34739872 :                         if (Z_REFCOUNTED_P(p)) {
     246    20749542 :                                 if (!Z_DELREF_P(p)) {
     247     1651883 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     248     1651883 :                                         ZVAL_NULL(p);
     249     1651883 :                                         zval_dtor_func_for_ptr(r);
     250             :                                 }
     251             :                         }
     252    34739872 :                 } while (p != end);
     253             :         }
     254             : }
     255             : 
     256             : static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call)
     257             : {
     258             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     259             : 
     260    27607294 :         if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
     261           8 :                 zend_vm_stack p = EG(vm_stack);
     262             : 
     263           8 :                 zend_vm_stack prev = p->prev;
     264             : 
     265           8 :                 EG(vm_stack_top) = prev->top;
     266           8 :                 EG(vm_stack_end) = prev->end;
     267           8 :                 EG(vm_stack) = prev;
     268           8 :                 efree(p);
     269             : 
     270             :         } else {
     271    27607286 :                 EG(vm_stack_top) = (zval*)call;
     272             :         }
     273             : 
     274             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     275             : }
     276             : 
     277             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
     278             : {
     279    26322647 :         zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
     280             : }
     281             : 
     282             : /* services */
     283             : ZEND_API const char *get_active_class_name(const char **space);
     284             : ZEND_API const char *get_active_function_name(void);
     285             : ZEND_API const char *zend_get_executed_filename(void);
     286             : ZEND_API zend_string *zend_get_executed_filename_ex(void);
     287             : ZEND_API uint zend_get_executed_lineno(void);
     288             : ZEND_API zend_bool zend_is_executing(void);
     289             : 
     290             : ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
     291             : ZEND_API void zend_unset_timeout(void);
     292             : ZEND_API void zend_timeout(int dummy);
     293             : ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type);
     294             : ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type);
     295             : void zend_verify_abstract_class(zend_class_entry *ce);
     296             : 
     297             : ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim);
     298             : 
     299             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     300             : 
     301             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     302             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     303             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     304             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     305             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     306             : 
     307             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     308             : 
     309             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     310             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     311             : 
     312             : /* former zend_execute_locks.h */
     313             : typedef zval* zend_free_op;
     314             : 
     315             : ZEND_API zval *zend_get_zval_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type);
     316             : 
     317             : ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
     318             : void zend_free_compiled_variables(zend_execute_data *execute_data);
     319             : void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num);
     320             : 
     321             : #define CACHE_ADDR(num) \
     322             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))
     323             : 
     324             : #define CACHED_PTR(num) \
     325             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0]
     326             : 
     327             : #define CACHE_PTR(num, ptr) do { \
     328             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] = (ptr); \
     329             :         } while (0)
     330             : 
     331             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     332             :         (EXPECTED(((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] == (void*)(ce)) ? \
     333             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[1] : \
     334             :                 NULL)
     335             : 
     336             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     337             :                 void **slot = (void**)((char*)EX_RUN_TIME_CACHE() + (num)); \
     338             :                 slot[0] = (ce); \
     339             :                 slot[1] = (ptr); \
     340             :         } while (0)
     341             : 
     342             : #define CACHED_PTR_EX(slot) \
     343             :         (slot)[0]
     344             : 
     345             : #define CACHE_PTR_EX(slot, ptr) do { \
     346             :                 (slot)[0] = (ptr); \
     347             :         } while (0)
     348             : 
     349             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     350             :         (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
     351             : 
     352             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     353             :                 (slot)[0] = (ce); \
     354             :                 (slot)[1] = (ptr); \
     355             :         } while (0)
     356             : 
     357             : #define SKIP_EXT_OPLINE(opline) do { \
     358             :                 while (UNEXPECTED((opline)->opcode >= ZEND_EXT_STMT \
     359             :                         && (opline)->opcode <= ZEND_TICKS)) {     \
     360             :                         (opline)--;                                  \
     361             :                 }                                                \
     362             :         } while (0)
     363             : 
     364             : END_EXTERN_C()
     365             : 
     366             : #endif /* ZEND_EXECUTE_H */
     367             : 
     368             : /*
     369             :  * Local variables:
     370             :  * tab-width: 4
     371             :  * c-basic-offset: 4
     372             :  * indent-tabs-mode: t
     373             :  * End:
     374             :  */

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:12 +0000 (4 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.