PHP-7.1 源代码学习:字节码在 Zend 虚拟机中的解释执行 之 概述
生活随笔
收集整理的這篇文章主要介紹了
PHP-7.1 源代码学习:字节码在 Zend 虚拟机中的解释执行 之 概述
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文簡要介紹 zend 虛擬機解釋執行字節碼的基本邏輯以及相關的數據結構,關于 PHP 源代碼的下載,編譯,調試可以參考之前的系列文章
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 檢測
轉載于:https://www.cnblogs.com/tianshifu/p/6379733.html
總結
以上是生活随笔為你收集整理的PHP-7.1 源代码学习:字节码在 Zend 虚拟机中的解释执行 之 概述的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1035. 插入与归并(25)
- 下一篇: 开发机器上利用vs2013调试远程IIS