From: Dmitry Stogov Date: Mon, 19 Feb 2018 13:42:02 +0000 (+0300) Subject: Added VM instrumentation ability X-Git-Tag: php-7.3.0alpha1~341 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d3e1bd124f0c547abaa666f4c8abb36201e570d;p=php Added VM instrumentation ability --- diff --git a/Zend/zend.c b/Zend/zend.c index dc0cab8cc0..efe51b7b47 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -705,8 +705,6 @@ static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p } /* }}} */ -void zend_init_opcodes_handlers(void); - static void module_destructor_zval(zval *zv) /* {{{ */ { zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv); @@ -807,7 +805,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) / /* Set up the default garbage collection implementation. */ gc_collect_cycles = zend_gc_collect_cycles; - zend_init_opcodes_handlers(); + zend_vm_init(); /* set up version */ zend_version_info = strdup(ZEND_CORE_VERSION_INFO); @@ -939,6 +937,8 @@ int zend_post_startup(void) /* {{{ */ void zend_shutdown(void) /* {{{ */ { + zend_vm_dtor(); + zend_destroy_rsrc_list(&EG(persistent_list)); zend_destroy_modules(); diff --git a/Zend/zend_vm.h b/Zend/zend_vm.h index 34751c7249..8d4e2b79d4 100644 --- a/Zend/zend_vm.h +++ b/Zend/zend_vm.h @@ -32,6 +32,9 @@ ZEND_API const zend_op *zend_get_halt_op(void); ZEND_API int ZEND_FASTCALL zend_vm_call_opcode_handler(zend_execute_data *ex); ZEND_API int zend_vm_kind(void); +void zend_vm_init(void); +void zend_vm_dtor(void); + END_EXTERN_C() #define ZEND_VM_SET_OPCODE_HANDLER(opline) zend_vm_set_opcode_handler(opline) diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 71a6a4d3bf..5f35f90b22 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -336,6 +336,12 @@ static const void *zend_vm_get_opcode_handler_func(zend_uchar opcode, const zend #ifndef VM_TRACE # define VM_TRACE(op) #endif +#ifndef VM_TRACE_START() +# define VM_TRACE_START() +#endif +#ifndef VM_TRACE_END() +# define VM_TRACE_END() +#endif #if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) #define HYBRID_NEXT() goto *(void**)(OPLINE->handler) #define HYBRID_SWITCH() HYBRID_NEXT(); @@ -62308,7 +62314,7 @@ ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value) } -void zend_init_opcodes_handlers(void) +void zend_vm_init(void) { static const void * const labels[] = { ZEND_NOP_SPEC_HANDLER, @@ -66461,6 +66467,12 @@ void zend_init_opcodes_handlers(void) zend_handlers_count = sizeof(labels) / sizeof(void*); zend_spec_handlers = specs; #endif + VM_TRACE_START(); +} + +void zend_vm_dtor(void) +{ + VM_TRACE_END(); } static HashTable *zend_handlers_table = NULL; diff --git a/Zend/zend_vm_execute.skl b/Zend/zend_vm_execute.skl index 25809a90b3..dfe25bce70 100644 --- a/Zend/zend_vm_execute.skl +++ b/Zend/zend_vm_execute.skl @@ -47,6 +47,12 @@ ZEND_API void zend_{%EXECUTOR_NAME%}(zend_op_array *op_array, zval *return_value void {%INITIALIZER_NAME%}(void) { {%EXTERNAL_LABELS%} + VM_TRACE_START(); +} + +void zend_vm_dtor(void) +{ + VM_TRACE_END(); } static HashTable *zend_handlers_table = NULL; diff --git a/Zend/zend_vm_gen.php b/Zend/zend_vm_gen.php index ad99c1086f..eae662a7f8 100644 --- a/Zend/zend_vm_gen.php +++ b/Zend/zend_vm_gen.php @@ -1710,6 +1710,12 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name) out($f,"#ifndef VM_TRACE\n"); out($f,"# define VM_TRACE(op)\n"); out($f,"#endif\n"); + out($f,"#ifndef VM_TRACE_START()\n"); + out($f,"# define VM_TRACE_START()\n"); + out($f,"#endif\n"); + out($f,"#ifndef VM_TRACE_END()\n"); + out($f,"# define VM_TRACE_END()\n"); + out($f,"#endif\n"); switch ($kind) { case ZEND_VM_KIND_HYBRID: out($f,"#if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)\n"); @@ -2514,7 +2520,7 @@ function gen_vm($def, $skel) { out($f, "255\n};\n\n"); // Generate specialized executor - gen_executor($f, $skl, ZEND_VM_SPEC, ZEND_VM_KIND, "execute", "zend_init_opcodes_handlers"); + gen_executor($f, $skl, ZEND_VM_SPEC, ZEND_VM_KIND, "execute", "zend_vm_init"); // Generate zend_vm_get_opcode_handler() function out($f, "static const void *zend_vm_get_opcode_handler_ex(uint32_t spec, const zend_op* op)\n");