你好,游客 登录 注册 搜索
背景:
阅读新闻

Zend 引擎执行器的核心代码

[日期:2014-11-08] 来源:Linux社区  作者:RichardXu [字体:大 中 小]

Zend 引擎执行器的核心代码

ZEND_API void execute(zend_op_array *op_array TSRMLS_DC)
{
 // 初始化执行上下文
 zend_execute_data execute_data;

 // 如果有异常就退出执行
 if (EG(exception)) {
  return;
 }

 /* Initialize execute_data */
 EX(fbc) = NULL; // 初始化正在调用的函数
 EX(object) = NULL; // 初始化正在调用的对象
 EX(old_error_reporting) = NULL; // 初始化错误报告变量
 
 // 为执行栈分配空间
 if (op_array->T < TEMP_VAR_STACK_LIMIT) {
  EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T);
 } else {
  EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0);
 }
 // 为临时变量分配空间并初始化这些空间
 EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var);
 memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
 
 EX(op_array) = op_array;
 
 // 切换执行上下文
 EX(original_in_execution) = EG(in_execution);
 EX(symbol_table) = EG(active_symbol_table);
 EX(prev_execute_data) = EG(current_execute_data); // 将当前全局变量中的执行数据压栈
 EG(current_execute_data) = &execute_data; // 将当前执行上下文压栈

 EG(in_execution) = 1;
 // 初始化第一个指令(opcode)
 /*
 #define ZEND_VM_SET_OPCODE(new_op) \
 CHECK_SYMBOL_TABLES() \
 EX(opline) = new_op
 
 execute_data.opline 为当前执行的 opcode
 */
 if (op_array->start_op) {
  ZEND_VM_SET_OPCODE(op_array->start_op);
 } else {
  ZEND_VM_SET_OPCODE(op_array->opcodes);
 }

 if (op_array->uses_this && EG(This)) {
  EG(This)->refcount++; /* For $this pointer */
  if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) {
   EG(This)->refcount--;
  }
 }

 // 将存储opline的内存地址赋给 executor_globals.online_ptr ,可以实时跟踪opcode的执行
 EG(opline_ptr) = &EX(opline);

 EX(function_state).function = (zend_function *) op_array;
 EG(function_state_ptr) = &EX(function_state);
#if ZEND_DEBUG
 /* function_state.function_symbol_table is saved as-is to a stack,
  * which is an intentional UMR.  Shut it up if we're in DEBUG.
  */
 EX(function_state).function_symbol_table = NULL;
#endif
 
 while (1) {
#ifdef ZEND_WIN32
  if (EG(timed_out)) {
   zend_timeout(0);
  }
#endif
 
  // 循环调用每个opline的 handler 函数,如果是推出函数的话,返回值大于0,就退出
  if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0) {
      return;
  }

 }
 zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
}

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署LNMP的时候遇到Nginx启动失败的2个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

《细说PHP》高清扫描PDF+光盘源码+全套教学视频 http://www.linuxidc.com/Linux/2014-03/97536.htm

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-11/109117.htm

linux
相关资讯       Zend引擎  Zend引擎执行器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款