Skip to content

Commit 56163b4

Browse files
committed
add global register variables
1 parent 95ec461 commit 56163b4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

3/zend_global_register.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### 3.3.4 全局execute_data和opline
2+
Zend执行器在opcode的执行过程中,会频繁的用到execute_data和opline两个变量,execute_data为zend_execute_data结构,opline为当前执行的指令。普通的处理方式在执行每条opcode指令的handler时,会把execute_data地址作为参数传给handler使用,使用时先从当前栈上获取execute_data地址,然后再从堆上获取变量的数据,这种方式下Zend执行器展开后是下面这样:
3+
```c
4+
ZEND_API void execute_ex(zend_execute_data *ex)
5+
{
6+
zend_execute_data *execute_data = ex;
7+
8+
while (1) {
9+
int ret;
10+
11+
if (UNEXPECTED((ret = ((opcode_handler_t)execute_data->opline->handler)(execute_data)) != 0)) {
12+
if (EXPECTED(ret > 0)) {
13+
execute_data = EG(current_execute_data);
14+
} else {
15+
return;
16+
}
17+
}
18+
}
19+
}
20+
```
21+
执行器实际是一个大循环,从第一条opcode开始执行,execute_data->opline指向当前执行的指令,执行完以后指向下一条指令,opline类似eip(或rip)寄存器的作用。通过这个循环,ZendVM完成opcode指令的执行,如下图。
22+
23+
![](../img/executor.png)
24+
25+
26+
27+
28+
全局寄存器变量(Global Register Variables)是数据保存在寄存器中的一种变量类型,与存储在内存中的变量相比,寄存器变量具有更快的访问速度,在计算机的存储层次中,寄存器的速度最快,其次是内存,最慢的是内存。

img/executor.png

13.5 KB
Loading

0 commit comments

Comments
 (0)