PHP-7.1 源代码学习:字节码在 Zend 虚拟机中的解释执行 之 概述
2017-02-08 20:06
387 查看
本文简要介绍 zend 虚拟机解释执行字节码的基本逻辑以及相关的数据结构,关于 PHP 源代码的下载,编译,调试可以参考之前的系列文章
由于是执行脚本文件,所以 do_cli 调用了 php_execute_script 函数,最终调用 execute_ex 函数:
和其它 C 语言编写的系统软件类似,函数中使用了大量的宏定义,通过宏定义的名字还是能大概看出其用途
DCL_OPLINE,变量声明
LOAD_OPLINE(),加载指令字节码
ZEND_VM_LOOP_INTERRUPT_CHECK(),interrupt 检测
execute_ex
我们来看看执行一个简单的脚本 test.php 的调用栈execute_ex @ zend_vm_execute.h : 411 zend_execute @ zend_vm_execute.h : 474 php_execute_script @ zend.c : 1474 do_cli @ php_cli.c : 993 main @ php_cli.c : 1381
由于是执行脚本文件,所以 do_cli 调用了 php_execute_script 函数,最终调用 execute_ex 函数:
ZEND_API void execute_ex(zend_execute_data *ex) { DCL_OPLINE #ifdef ZEND_VM_IP_GLOBAL_REG const zend_op *orig_opline = opline; #endif #ifdef ZEND_VM_FP_GLOBAL_REG zend_execute_data *orig_execute_data = execute_data; execute_data = ex; #else zend_execute_data *execute_data = ex; #endif LOAD_OPLINE(); ZEND_VM_LOOP_INTERRUPT_CHECK(); while (1) { #if !defined(ZEND_VM_FP_GLOBAL_REG) || !defined(ZEND_VM_IP_GLOBAL_REG) int ret; #endif #if defined(ZEND_VM_FP_GLOBAL_REG) && defined(ZEND_VM_IP_GLOBAL_REG) ((opcode_handler_t)OPLINE->handler)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); if (UNEXPECTED(!OPLINE)) { #else if (UNEXPECTED((ret = ((opcode_handler_t)OPLINE->handler)www.90168.org(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)) != 0)) { #endif #ifdef ZEND_VM_FP_GLOBAL_REG execute_data = orig_execute_data; # ifdef ZEND_VM_IP_GLOBAL_REG opline = orig_opline; # endif return; #else if (EXPECTED(ret > 0)) { execute_data = EG(current_execute_data); ZEND_VM_LOOP_INTERRUPT_CHECK(); } else { # ifdef ZEND_VM_IP_GLOBAL_REG opline = orig_opline; # endif return; } #endif } } zend_error_noreturn(E_CORE_ERROR, "Arrived at end of main loop which shouldn't happen"); }
和其它 C 语言编写的系统软件类似,函数中使用了大量的宏定义,通过宏定义的名字还是能大概看出其用途
DCL_OPLINE,变量声明
LOAD_OPLINE(),加载指令字节码
ZEND_VM_LOOP_INTERRUPT_CHECK(),interrupt 检测
相关文章推荐
- PHP-7.1 源代码学习:字节码生成 之 "$a = 1"
- 【php源代码学习】从接受请求到执行
- 【分析】dalvik虚拟机解释执行字节码
- 【php学习笔记】Php 体系结构及其执行概述
- PHP内核探索 —— 如何执行PHP脚本:Zend引擎是如何解释PHP脚本的
- PHP中的源代码签名(PHP源码学习快速方法)
- 【php源代码学习笔记】开始-搭建环境
- php学习笔记――PHP 概述
- 如何编译PHP源代码(ZEND)
- Php 体系结构及其执行概述
- 函数执行效率的小比较----PHP 函数学习
- 一起学习php:Ubuntu如何安装Zend Server CE ( 2 )
- 一起学习php:Ubuntu如何安装Zend Server CE ( 1 )
- 基本概念:源代码,字节码,编译器,虚拟机
- PHP 源代码分析 Zend HashTable详解第1/3页
- php学习之smarty和zend mvc 选择之惑
- php学习之smarty和zend mvc 的选择困惑
- 如何编译PHP源代码(介绍Zend Encode的安装方法)
- 一起学习php:Ubuntu如何安装Zend Server CE ( 3 )
- PHP实现源代码学习笔记