2013-12-30 02:51:47 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend OPcache |
|
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 15:27:30 +00:00
|
|
|
| Copyright (c) 1998-2015 The PHP Group |
|
2013-12-30 02:51:47 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
| Stanislav Malyshev <stas@zend.com> |
|
|
|
|
| Dmitry Stogov <dmitry@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "Optimizer/zend_optimizer.h"
|
|
|
|
#include "Optimizer/zend_optimizer_internal.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_execute.h"
|
|
|
|
#include "zend_vm.h"
|
|
|
|
|
|
|
|
static void zend_optimizer_zval_dtor_wrapper(zval *zvalue)
|
|
|
|
{
|
|
|
|
zval_dtor(zvalue);
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:23:12 +00:00
|
|
|
void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
zval val;
|
|
|
|
|
2014-06-18 13:09:37 +00:00
|
|
|
if (!ctx->constants) {
|
|
|
|
ctx->constants = zend_arena_alloc(&ctx->arena, sizeof(HashTable));
|
|
|
|
zend_hash_init(ctx->constants, 16, NULL, zend_optimizer_zval_dtor_wrapper, 0);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
2014-03-28 19:34:49 +00:00
|
|
|
ZVAL_DUP(&val, value);
|
2014-06-18 13:09:37 +00:00
|
|
|
zend_hash_add(ctx->constants, Z_STR_P(name), &val);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 13:23:12 +00:00
|
|
|
int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
zval *val;
|
|
|
|
|
2014-03-28 19:34:49 +00:00
|
|
|
if ((val = zend_hash_find(constants, Z_STR_P(name))) != NULL) {
|
|
|
|
ZVAL_DUP(value, val);
|
2013-12-30 02:51:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:23:12 +00:00
|
|
|
int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_ulong hash_value = zend_string_hash_val(name);
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
while (i < op_array->last_var) {
|
2014-03-28 19:34:49 +00:00
|
|
|
if (op_array->vars[i] == name ||
|
2015-06-30 01:05:24 +00:00
|
|
|
(ZSTR_H(op_array->vars[i]) == hash_value &&
|
|
|
|
ZSTR_LEN(op_array->vars[i]) == ZSTR_LEN(name) &&
|
|
|
|
memcmp(ZSTR_VAL(op_array->vars[i]), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)) {
|
2014-11-28 08:11:33 +00:00
|
|
|
return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
i = op_array->last_var;
|
|
|
|
op_array->last_var++;
|
2014-03-28 19:34:49 +00:00
|
|
|
op_array->vars = erealloc(op_array->vars, op_array->last_var * sizeof(zend_string*));
|
2014-08-25 17:24:55 +00:00
|
|
|
op_array->vars[i] = zend_string_dup(name, 0);
|
2014-03-31 14:13:16 +00:00
|
|
|
|
|
|
|
/* all IS_TMP_VAR and IS_VAR variable numbers have to be adjusted */
|
|
|
|
{
|
|
|
|
zend_op *opline = op_array->opcodes;
|
|
|
|
zend_op *end = opline + op_array->last;
|
|
|
|
while (opline < end) {
|
|
|
|
if (opline->op1_type & (IS_TMP_VAR|IS_VAR)) {
|
|
|
|
opline->op1.var += sizeof(zval);
|
|
|
|
}
|
|
|
|
if (opline->op2_type & (IS_TMP_VAR|IS_VAR)) {
|
|
|
|
opline->op2.var += sizeof(zval);
|
|
|
|
}
|
|
|
|
if (opline->result_type & (IS_TMP_VAR|IS_VAR)) {
|
|
|
|
opline->result.var += sizeof(zval);
|
|
|
|
}
|
|
|
|
if (opline->opcode == ZEND_DECLARE_INHERITED_CLASS ||
|
2015-04-27 09:24:39 +00:00
|
|
|
opline->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS ||
|
2014-03-31 14:13:16 +00:00
|
|
|
opline->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED) {
|
|
|
|
opline->extended_value += sizeof(zval);
|
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2014-11-28 08:11:33 +00:00
|
|
|
return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
int i = op_array->last_literal;
|
|
|
|
op_array->last_literal++;
|
2014-04-17 11:40:45 +00:00
|
|
|
op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval));
|
|
|
|
ZVAL_COPY_VALUE(&op_array->literals[i], zv);
|
|
|
|
Z_CACHE_SLOT(op_array->literals[i]) = -1;
|
2013-12-30 02:51:47 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2015-11-06 22:00:39 +00:00
|
|
|
static inline int zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) {
|
|
|
|
zval zv;
|
|
|
|
ZVAL_STR(&zv, str);
|
|
|
|
zend_string_hash_val(str);
|
|
|
|
return zend_optimizer_add_literal(op_array, &zv);
|
|
|
|
}
|
|
|
|
|
2015-03-27 09:50:36 +00:00
|
|
|
int zend_optimizer_is_disabled_func(const char *name, size_t len) {
|
|
|
|
zend_function *fbc = (zend_function *)zend_hash_str_find_ptr(EG(function_table), name, len);
|
|
|
|
|
2015-03-28 06:09:54 +00:00
|
|
|
return (fbc && fbc->type == ZEND_INTERNAL_FUNCTION &&
|
2015-03-27 09:50:36 +00:00
|
|
|
fbc->internal_function.handler == ZEND_FN(display_disabled_function));
|
|
|
|
}
|
|
|
|
|
2015-11-07 09:59:18 +00:00
|
|
|
static inline void drop_leading_backslash(zval *val) {
|
|
|
|
if (Z_STRVAL_P(val)[0] == '\\') {
|
|
|
|
zend_string *str = zend_string_init(Z_STRVAL_P(val) + 1, Z_STRLEN_P(val) - 1, 0);
|
|
|
|
zval_dtor(val);
|
|
|
|
ZVAL_STR(val, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-07 10:48:21 +00:00
|
|
|
int zend_optimizer_update_op1_const(zend_op_array *op_array,
|
|
|
|
zend_op *opline,
|
|
|
|
zval *val)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
2015-11-07 10:48:21 +00:00
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_FREE:
|
|
|
|
MAKE_NOP(opline);
|
|
|
|
zval_dtor(val);
|
|
|
|
break;
|
|
|
|
case ZEND_INIT_STATIC_METHOD_CALL:
|
|
|
|
case ZEND_CATCH:
|
|
|
|
case ZEND_FETCH_CONSTANT:
|
|
|
|
case ZEND_DEFINED:
|
|
|
|
case ZEND_NEW:
|
|
|
|
if (Z_TYPE_P(val) != IS_STRING) {
|
|
|
|
zval_dtor(val);
|
|
|
|
return 0;
|
2015-03-24 19:47:21 +00:00
|
|
|
}
|
2015-11-07 10:48:21 +00:00
|
|
|
ZEND_OP1_TYPE(opline) = IS_CONST;
|
|
|
|
drop_leading_backslash(val);
|
2014-12-13 22:06:14 +00:00
|
|
|
opline->op1.constant = zend_optimizer_add_literal(op_array, val);
|
2015-11-07 10:48:21 +00:00
|
|
|
zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline)));
|
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += sizeof(void*);
|
|
|
|
zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val)));
|
|
|
|
break;
|
|
|
|
case ZEND_CONCAT:
|
|
|
|
case ZEND_FAST_CONCAT:
|
|
|
|
convert_to_string(val);
|
|
|
|
/* break missing intentionally */
|
|
|
|
default:
|
|
|
|
ZEND_OP1_TYPE(opline) = IS_CONST;
|
|
|
|
opline->op1.constant = zend_optimizer_add_literal(op_array, val);
|
|
|
|
if (Z_TYPE_P(val) == IS_STRING) {
|
|
|
|
zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline)));
|
|
|
|
}
|
|
|
|
break;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
2015-11-07 10:48:21 +00:00
|
|
|
|
|
|
|
return 1;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 10:48:21 +00:00
|
|
|
int zend_optimizer_update_op2_const(zend_op_array *op_array,
|
|
|
|
zend_op *opline,
|
|
|
|
zval *val)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
2014-06-30 11:43:45 +00:00
|
|
|
if (opline->opcode == ZEND_INIT_FCALL) {
|
2015-11-07 10:48:21 +00:00
|
|
|
ZEND_OP2_TYPE(opline) = IS_CONST;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
|
2014-12-13 22:06:14 +00:00
|
|
|
opline->op2.constant = zend_optimizer_add_literal(op_array, val);
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline)));
|
2015-02-24 22:52:35 +00:00
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += sizeof(void*);
|
2015-11-07 10:48:21 +00:00
|
|
|
return 1;
|
2014-06-30 11:43:45 +00:00
|
|
|
}
|
2015-11-07 09:59:18 +00:00
|
|
|
|
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_ROPE_INIT:
|
|
|
|
case ZEND_ROPE_ADD:
|
|
|
|
case ZEND_ROPE_END:
|
|
|
|
case ZEND_CONCAT:
|
|
|
|
case ZEND_FAST_CONCAT:
|
|
|
|
convert_to_string(val);
|
|
|
|
break;
|
|
|
|
case ZEND_FETCH_R:
|
|
|
|
case ZEND_FETCH_W:
|
|
|
|
case ZEND_FETCH_RW:
|
|
|
|
case ZEND_FETCH_IS:
|
|
|
|
case ZEND_FETCH_UNSET:
|
|
|
|
case ZEND_FETCH_FUNC_ARG:
|
|
|
|
case ZEND_FETCH_CLASS:
|
|
|
|
case ZEND_INIT_FCALL_BY_NAME:
|
|
|
|
/*case ZEND_INIT_NS_FCALL_BY_NAME:*/
|
|
|
|
case ZEND_UNSET_VAR:
|
|
|
|
case ZEND_ISSET_ISEMPTY_VAR:
|
|
|
|
case ZEND_ADD_INTERFACE:
|
|
|
|
case ZEND_ADD_TRAIT:
|
|
|
|
case ZEND_INSTANCEOF:
|
2015-11-07 10:48:21 +00:00
|
|
|
if (Z_TYPE_P(val) != IS_STRING) {
|
|
|
|
zval_dtor(val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* break missing intentionally */
|
2015-11-07 09:59:18 +00:00
|
|
|
case ZEND_INIT_DYNAMIC_CALL:
|
|
|
|
drop_leading_backslash(val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-07 10:48:21 +00:00
|
|
|
ZEND_OP2_TYPE(opline) = IS_CONST;
|
2014-12-13 22:06:14 +00:00
|
|
|
opline->op2.constant = zend_optimizer_add_literal(op_array, val);
|
2013-12-30 02:51:47 +00:00
|
|
|
if (Z_TYPE_P(val) == IS_STRING) {
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline)));
|
2013-12-30 02:51:47 +00:00
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_FETCH_R:
|
|
|
|
case ZEND_FETCH_W:
|
|
|
|
case ZEND_FETCH_RW:
|
|
|
|
case ZEND_FETCH_IS:
|
|
|
|
case ZEND_FETCH_UNSET:
|
|
|
|
case ZEND_FETCH_FUNC_ARG:
|
|
|
|
case ZEND_FETCH_CLASS:
|
|
|
|
case ZEND_INIT_FCALL_BY_NAME:
|
|
|
|
/*case ZEND_INIT_NS_FCALL_BY_NAME:*/
|
|
|
|
case ZEND_UNSET_VAR:
|
|
|
|
case ZEND_ISSET_ISEMPTY_VAR:
|
|
|
|
case ZEND_ADD_INTERFACE:
|
|
|
|
case ZEND_ADD_TRAIT:
|
2014-10-22 13:23:43 +00:00
|
|
|
case ZEND_INSTANCEOF:
|
2015-02-24 22:52:35 +00:00
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += sizeof(void*);
|
2015-11-06 22:00:39 +00:00
|
|
|
zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val)));
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
2015-02-24 19:29:47 +00:00
|
|
|
case ZEND_INIT_DYNAMIC_CALL:
|
|
|
|
opline->opcode = ZEND_INIT_FCALL_BY_NAME;
|
2015-02-24 22:52:35 +00:00
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += sizeof(void*);
|
2015-11-06 22:00:39 +00:00
|
|
|
zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val)));
|
2015-02-24 19:29:47 +00:00
|
|
|
break;
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_INIT_METHOD_CALL:
|
|
|
|
case ZEND_INIT_STATIC_METHOD_CALL:
|
2015-11-06 22:00:39 +00:00
|
|
|
zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val)));
|
2015-01-03 09:22:58 +00:00
|
|
|
/* break missing intentionally */
|
2013-12-30 02:51:47 +00:00
|
|
|
/*case ZEND_FETCH_CONSTANT:*/
|
|
|
|
case ZEND_ASSIGN_OBJ:
|
|
|
|
case ZEND_FETCH_OBJ_R:
|
|
|
|
case ZEND_FETCH_OBJ_W:
|
|
|
|
case ZEND_FETCH_OBJ_RW:
|
|
|
|
case ZEND_FETCH_OBJ_IS:
|
|
|
|
case ZEND_FETCH_OBJ_UNSET:
|
|
|
|
case ZEND_FETCH_OBJ_FUNC_ARG:
|
|
|
|
case ZEND_UNSET_OBJ:
|
|
|
|
case ZEND_PRE_INC_OBJ:
|
|
|
|
case ZEND_PRE_DEC_OBJ:
|
|
|
|
case ZEND_POST_INC_OBJ:
|
|
|
|
case ZEND_POST_DEC_OBJ:
|
|
|
|
case ZEND_ISSET_ISEMPTY_PROP_OBJ:
|
2015-02-24 22:52:35 +00:00
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += 2 * sizeof(void*);
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
|
|
|
case ZEND_ASSIGN_ADD:
|
|
|
|
case ZEND_ASSIGN_SUB:
|
|
|
|
case ZEND_ASSIGN_MUL:
|
|
|
|
case ZEND_ASSIGN_DIV:
|
2015-09-13 10:35:35 +00:00
|
|
|
case ZEND_ASSIGN_POW:
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_ASSIGN_MOD:
|
|
|
|
case ZEND_ASSIGN_SL:
|
|
|
|
case ZEND_ASSIGN_SR:
|
|
|
|
case ZEND_ASSIGN_CONCAT:
|
|
|
|
case ZEND_ASSIGN_BW_OR:
|
|
|
|
case ZEND_ASSIGN_BW_AND:
|
|
|
|
case ZEND_ASSIGN_BW_XOR:
|
|
|
|
if (opline->extended_value == ZEND_ASSIGN_OBJ) {
|
2015-02-24 22:52:35 +00:00
|
|
|
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size;
|
|
|
|
op_array->cache_size += 2 * sizeof(void*);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ZEND_OP_DATA:
|
|
|
|
if ((opline-1)->opcode == ZEND_ASSIGN_DIM ||
|
|
|
|
((opline-1)->extended_value == ZEND_ASSIGN_DIM &&
|
|
|
|
((opline-1)->opcode == ZEND_ASSIGN_ADD ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_SUB ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_MUL ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_DIV ||
|
2015-09-13 10:35:35 +00:00
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_POW ||
|
2013-12-30 02:51:47 +00:00
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_MOD ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_SL ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_SR ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_CONCAT ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_BW_OR ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_BW_AND ||
|
|
|
|
(opline-1)->opcode == ZEND_ASSIGN_BW_XOR))) {
|
|
|
|
goto check_numeric;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ZEND_ISSET_ISEMPTY_DIM_OBJ:
|
|
|
|
case ZEND_ADD_ARRAY_ELEMENT:
|
|
|
|
case ZEND_INIT_ARRAY:
|
2015-02-27 03:42:36 +00:00
|
|
|
case ZEND_ASSIGN_DIM:
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_UNSET_DIM:
|
|
|
|
case ZEND_FETCH_DIM_R:
|
|
|
|
case ZEND_FETCH_DIM_W:
|
|
|
|
case ZEND_FETCH_DIM_RW:
|
|
|
|
case ZEND_FETCH_DIM_IS:
|
|
|
|
case ZEND_FETCH_DIM_FUNC_ARG:
|
|
|
|
case ZEND_FETCH_DIM_UNSET:
|
2014-10-05 09:02:58 +00:00
|
|
|
case ZEND_FETCH_LIST:
|
2013-12-30 02:51:47 +00:00
|
|
|
check_numeric:
|
|
|
|
{
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_ulong index;
|
2013-12-30 02:51:47 +00:00
|
|
|
|
2014-06-03 09:10:42 +00:00
|
|
|
if (ZEND_HANDLE_NUMERIC(Z_STR_P(val), index)) {
|
2013-12-30 02:51:47 +00:00
|
|
|
zval_dtor(val);
|
2014-08-25 17:24:55 +00:00
|
|
|
ZVAL_LONG(val, index);
|
2014-04-17 11:40:45 +00:00
|
|
|
op_array->literals[opline->op2.constant] = *val;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-07 10:48:21 +00:00
|
|
|
|
|
|
|
return 1;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 21:57:40 +00:00
|
|
|
int zend_optimizer_replace_by_const(zend_op_array *op_array,
|
|
|
|
zend_op *opline,
|
|
|
|
zend_uchar type,
|
|
|
|
uint32_t var,
|
2014-12-13 22:06:14 +00:00
|
|
|
zval *val)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
zend_op *end = op_array->opcodes + op_array->last;
|
|
|
|
|
|
|
|
while (opline < end) {
|
2014-09-23 21:57:40 +00:00
|
|
|
if (ZEND_OP1_TYPE(opline) == type &&
|
2013-12-30 02:51:47 +00:00
|
|
|
ZEND_OP1(opline).var == var) {
|
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_FETCH_DIM_W:
|
|
|
|
case ZEND_FETCH_DIM_RW:
|
|
|
|
case ZEND_FETCH_DIM_FUNC_ARG:
|
|
|
|
case ZEND_FETCH_DIM_UNSET:
|
|
|
|
case ZEND_ASSIGN_DIM:
|
|
|
|
case ZEND_SEPARATE:
|
|
|
|
return 0;
|
2014-11-18 11:37:36 +00:00
|
|
|
case ZEND_SEND_VAR:
|
|
|
|
opline->extended_value = 0;
|
|
|
|
opline->opcode = ZEND_SEND_VAL;
|
|
|
|
break;
|
|
|
|
case ZEND_SEND_VAR_EX:
|
|
|
|
opline->extended_value = 0;
|
|
|
|
opline->opcode = ZEND_SEND_VAL_EX;
|
|
|
|
break;
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_SEND_VAR_NO_REF:
|
|
|
|
if (opline->extended_value & ZEND_ARG_COMPILE_TIME_BOUND) {
|
|
|
|
if (opline->extended_value & ZEND_ARG_SEND_BY_REF) {
|
2015-03-20 02:24:04 +00:00
|
|
|
zval_dtor(val);
|
2013-12-30 02:51:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-07 22:13:53 +00:00
|
|
|
opline->extended_value = 0;
|
|
|
|
opline->opcode = ZEND_SEND_VAL_EX;
|
2013-12-30 02:51:47 +00:00
|
|
|
} else {
|
2014-06-30 11:43:45 +00:00
|
|
|
opline->extended_value = 0;
|
2014-07-07 22:13:53 +00:00
|
|
|
opline->opcode = ZEND_SEND_VAL;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-09-23 21:57:40 +00:00
|
|
|
/* In most cases IS_TMP_VAR operand may be used only once.
|
|
|
|
* The operands are usually destroyed by the opcode handler.
|
|
|
|
* ZEND_CASE is an exception, that keeps operand unchanged,
|
|
|
|
* and allows its reuse. The number of ZEND_CASE instructions
|
|
|
|
* usually terminated by ZEND_FREE that finally kills the value.
|
|
|
|
*/
|
2015-02-25 12:16:15 +00:00
|
|
|
case ZEND_FREE:
|
2014-09-23 21:57:40 +00:00
|
|
|
case ZEND_CASE: {
|
2015-07-10 00:31:52 +00:00
|
|
|
zend_op *m, *n;
|
|
|
|
int brk = op_array->last_brk_cont;
|
|
|
|
zend_bool in_switch = 0;
|
|
|
|
while (brk--) {
|
|
|
|
if (op_array->brk_cont_array[brk].start <= (opline - op_array->opcodes) &&
|
|
|
|
op_array->brk_cont_array[brk].brk > (opline - op_array->opcodes)) {
|
|
|
|
in_switch = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 12:16:15 +00:00
|
|
|
|
2015-07-10 00:31:52 +00:00
|
|
|
if (!in_switch) {
|
|
|
|
ZEND_ASSERT(opline->opcode == ZEND_FREE);
|
|
|
|
MAKE_NOP(opline);
|
|
|
|
zval_dtor(val);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m = opline;
|
|
|
|
n = op_array->opcodes + op_array->brk_cont_array[brk].brk + 1;
|
|
|
|
while (m < n) {
|
|
|
|
if (ZEND_OP1_TYPE(m) == type &&
|
|
|
|
ZEND_OP1(m).var == var) {
|
2015-02-17 14:03:50 +00:00
|
|
|
if (m->opcode == ZEND_CASE) {
|
|
|
|
zval old_val;
|
|
|
|
ZVAL_COPY_VALUE(&old_val, val);
|
|
|
|
zval_copy_ctor(val);
|
|
|
|
zend_optimizer_update_op1_const(op_array, m, val);
|
|
|
|
ZVAL_COPY_VALUE(val, &old_val);
|
|
|
|
} else if (m->opcode == ZEND_FREE) {
|
|
|
|
MAKE_NOP(m);
|
|
|
|
} else {
|
|
|
|
ZEND_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
zval_dtor(val);
|
|
|
|
return 1;
|
2014-09-23 21:57:40 +00:00
|
|
|
}
|
2015-07-22 14:43:30 +00:00
|
|
|
case ZEND_VERIFY_RETURN_TYPE: {
|
|
|
|
zend_arg_info *ret_info = op_array->arg_info - 1;
|
|
|
|
ZEND_ASSERT((opline + 1)->opcode == ZEND_RETURN || (opline + 1)->opcode == ZEND_RETURN_BY_REF);
|
|
|
|
if (ret_info->class_name
|
|
|
|
|| ret_info->type_hint == IS_CALLABLE
|
|
|
|
|| !ZEND_SAME_FAKE_TYPE(ret_info->type_hint, Z_TYPE_P(val))
|
|
|
|
|| (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
|
|
|
|
zval_dtor(val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MAKE_NOP(opline);
|
|
|
|
zend_optimizer_update_op1_const(op_array, opline + 1, val);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-01-03 09:22:58 +00:00
|
|
|
}
|
2015-11-07 10:48:21 +00:00
|
|
|
return zend_optimizer_update_op1_const(op_array, opline, val);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2014-09-23 21:57:40 +00:00
|
|
|
if (ZEND_OP2_TYPE(opline) == type &&
|
2013-12-30 02:51:47 +00:00
|
|
|
ZEND_OP2(opline).var == var) {
|
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_ASSIGN_REF:
|
2015-03-20 02:24:04 +00:00
|
|
|
zval_dtor(val);
|
2013-12-30 02:51:47 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-11-07 10:48:21 +00:00
|
|
|
return zend_optimizer_update_op2_const(op_array, opline, val);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:09:37 +00:00
|
|
|
static void zend_optimize(zend_op_array *op_array,
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_ctx *ctx)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
2014-08-25 21:45:02 +00:00
|
|
|
if (op_array->type == ZEND_EVAL_CODE) {
|
2013-12-30 02:51:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pass 1
|
|
|
|
* - substitute persistent constants (true, false, null, etc)
|
|
|
|
* - perform compile-time evaluation of constant binary and unary operations
|
|
|
|
* - optimize series of ADD_STRING and/or ADD_CHAR
|
|
|
|
* - convert CAST(IS_BOOL,x) into BOOL(x)
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_pass1(op_array, ctx);
|
2014-08-28 13:23:12 +00:00
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 2:
|
|
|
|
* - convert non-numeric constants to numeric constants in numeric operators
|
|
|
|
* - optimize constant conditional JMPs
|
|
|
|
* - optimize static BRKs and CONTs
|
|
|
|
* - pre-evaluate constant function calls
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_2 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_pass2(op_array);
|
2014-08-28 13:23:12 +00:00
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 3:
|
|
|
|
* - optimize $i = $i+expr to $i+=expr
|
|
|
|
* - optimize series of JMPs
|
|
|
|
* - change $i++ to ++$i where possible
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_pass3(op_array);
|
2014-08-28 13:23:12 +00:00
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 4:
|
|
|
|
* - INIT_FCALL_BY_NAME -> DO_FCALL
|
|
|
|
*/
|
|
|
|
if (ZEND_OPTIMIZER_PASS_4 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
optimize_func_calls(op_array, ctx);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pass 5:
|
|
|
|
* - CFG optimization
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_5 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
optimize_cfg(op_array, ctx);
|
2014-08-28 13:23:12 +00:00
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 9:
|
|
|
|
* - Optimize temp variables usage
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_9 & OPTIMIZATION_LEVEL) {
|
|
|
|
optimize_temporary_variables(op_array, ctx);
|
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 10:
|
|
|
|
* - remove NOPs
|
|
|
|
*/
|
2014-08-28 13:23:12 +00:00
|
|
|
if (((ZEND_OPTIMIZER_PASS_10|ZEND_OPTIMIZER_PASS_5) & OPTIMIZATION_LEVEL) == ZEND_OPTIMIZER_PASS_10) {
|
|
|
|
zend_optimizer_nop_removal(op_array);
|
|
|
|
}
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
/* pass 11:
|
2015-01-03 09:22:58 +00:00
|
|
|
* - Compact literals table
|
2013-12-30 02:51:47 +00:00
|
|
|
*/
|
|
|
|
if (ZEND_OPTIMIZER_PASS_11 & OPTIMIZATION_LEVEL) {
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_compact_literals(op_array, ctx);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:09:37 +00:00
|
|
|
static void zend_accel_optimize(zend_op_array *op_array,
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_optimizer_ctx *ctx)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
|
|
|
zend_op *opline, *end;
|
|
|
|
|
|
|
|
/* Revert pass_two() */
|
|
|
|
opline = op_array->opcodes;
|
|
|
|
end = opline + op_array->last;
|
|
|
|
while (opline < end) {
|
|
|
|
if (opline->op1_type == IS_CONST) {
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UNDO_CONSTANT(op_array, opline->op1);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
if (opline->op2_type == IS_CONST) {
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UNDO_CONSTANT(op_array, opline->op2);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_JMP:
|
|
|
|
case ZEND_FAST_CALL:
|
2015-04-27 09:24:39 +00:00
|
|
|
case ZEND_DECLARE_ANON_CLASS:
|
|
|
|
case ZEND_DECLARE_ANON_INHERITED_CLASS:
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, ZEND_OP1(opline));
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
2014-04-30 07:23:19 +00:00
|
|
|
case ZEND_JMPZNZ:
|
|
|
|
/* relative offset into absolute index */
|
2014-12-12 07:19:41 +00:00
|
|
|
opline->extended_value = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value);
|
2014-04-30 07:23:19 +00:00
|
|
|
/* break omitted intentionally */
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_JMPZ:
|
|
|
|
case ZEND_JMPNZ:
|
|
|
|
case ZEND_JMPZ_EX:
|
|
|
|
case ZEND_JMPNZ_EX:
|
|
|
|
case ZEND_JMP_SET:
|
2014-09-28 10:31:52 +00:00
|
|
|
case ZEND_COALESCE:
|
2014-06-11 07:39:42 +00:00
|
|
|
case ZEND_NEW:
|
2015-02-12 10:57:12 +00:00
|
|
|
case ZEND_FE_RESET_R:
|
|
|
|
case ZEND_FE_RESET_RW:
|
2015-03-02 09:25:40 +00:00
|
|
|
case ZEND_ASSERT_CHECK:
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, ZEND_OP2(opline));
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
2015-05-13 09:55:42 +00:00
|
|
|
case ZEND_FE_FETCH_R:
|
|
|
|
case ZEND_FE_FETCH_RW:
|
|
|
|
opline->extended_value = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value);
|
|
|
|
break;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do actual optimizations */
|
2015-01-03 09:22:58 +00:00
|
|
|
zend_optimize(op_array, ctx);
|
|
|
|
|
2013-12-30 02:51:47 +00:00
|
|
|
/* Redo pass_two() */
|
|
|
|
opline = op_array->opcodes;
|
|
|
|
end = opline + op_array->last;
|
|
|
|
while (opline < end) {
|
|
|
|
if (opline->op1_type == IS_CONST) {
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline->op1);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
if (opline->op2_type == IS_CONST) {
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline->op2);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_JMP:
|
|
|
|
case ZEND_FAST_CALL:
|
2015-04-27 09:24:39 +00:00
|
|
|
case ZEND_DECLARE_ANON_CLASS:
|
|
|
|
case ZEND_DECLARE_ANON_INHERITED_CLASS:
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, ZEND_OP1(opline));
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
2014-04-30 07:23:19 +00:00
|
|
|
case ZEND_JMPZNZ:
|
|
|
|
/* absolute index to relative offset */
|
2014-12-12 07:19:41 +00:00
|
|
|
opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value);
|
2014-04-30 07:23:19 +00:00
|
|
|
/* break omitted intentionally */
|
2013-12-30 02:51:47 +00:00
|
|
|
case ZEND_JMPZ:
|
|
|
|
case ZEND_JMPNZ:
|
|
|
|
case ZEND_JMPZ_EX:
|
|
|
|
case ZEND_JMPNZ_EX:
|
|
|
|
case ZEND_JMP_SET:
|
2014-09-28 10:31:52 +00:00
|
|
|
case ZEND_COALESCE:
|
2014-06-11 07:39:42 +00:00
|
|
|
case ZEND_NEW:
|
2015-02-12 10:57:12 +00:00
|
|
|
case ZEND_FE_RESET_R:
|
|
|
|
case ZEND_FE_RESET_RW:
|
2015-03-02 09:25:40 +00:00
|
|
|
case ZEND_ASSERT_CHECK:
|
2014-12-12 07:19:41 +00:00
|
|
|
ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, ZEND_OP2(opline));
|
2013-12-30 02:51:47 +00:00
|
|
|
break;
|
2015-05-13 09:55:42 +00:00
|
|
|
case ZEND_FE_FETCH_R:
|
|
|
|
case ZEND_FE_FETCH_RW:
|
|
|
|
opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value);
|
|
|
|
break;
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
ZEND_VM_SET_OPCODE_HANDLER(opline);
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 09:42:38 +00:00
|
|
|
static void zend_accel_adjust_fcall_stack_size(zend_op_array *op_array, zend_optimizer_ctx *ctx)
|
|
|
|
{
|
|
|
|
zend_function *func;
|
|
|
|
zend_op *opline, *end;
|
|
|
|
|
|
|
|
opline = op_array->opcodes;
|
|
|
|
end = opline + op_array->last;
|
|
|
|
while (opline < end) {
|
|
|
|
if (opline->opcode == ZEND_INIT_FCALL) {
|
|
|
|
func = zend_hash_find_ptr(
|
|
|
|
&ctx->script->function_table,
|
|
|
|
Z_STR_P(RT_CONSTANT(op_array, opline->op2)));
|
|
|
|
if (func) {
|
|
|
|
opline->op1.num = zend_vm_calc_used_stack(opline->extended_value, func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
int zend_accel_script_optimize(zend_persistent_script *script)
|
2013-12-30 02:51:47 +00:00
|
|
|
{
|
2014-02-10 06:04:30 +00:00
|
|
|
uint idx, j;
|
2013-12-30 02:51:47 +00:00
|
|
|
Bucket *p, *q;
|
2014-02-10 06:04:30 +00:00
|
|
|
zend_class_entry *ce;
|
|
|
|
zend_op_array *op_array;
|
2014-06-18 13:09:37 +00:00
|
|
|
zend_optimizer_ctx ctx;
|
2013-12-30 02:51:47 +00:00
|
|
|
|
2014-06-18 13:09:37 +00:00
|
|
|
ctx.arena = zend_arena_create(64 * 1024);
|
|
|
|
ctx.script = script;
|
|
|
|
ctx.constants = NULL;
|
|
|
|
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_accel_optimize(&script->main_op_array, &ctx);
|
2013-12-30 02:51:47 +00:00
|
|
|
|
2014-02-10 06:04:30 +00:00
|
|
|
for (idx = 0; idx < script->function_table.nNumUsed; idx++) {
|
|
|
|
p = script->function_table.arData + idx;
|
2014-03-28 19:34:49 +00:00
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
op_array = (zend_op_array*)Z_PTR(p->val);
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_accel_optimize(op_array, &ctx);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 06:04:30 +00:00
|
|
|
for (idx = 0; idx < script->class_table.nNumUsed; idx++) {
|
|
|
|
p = script->class_table.arData + idx;
|
2014-03-28 19:34:49 +00:00
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
ce = (zend_class_entry*)Z_PTR(p->val);
|
2014-02-10 06:04:30 +00:00
|
|
|
for (j = 0; j < ce->function_table.nNumUsed; j++) {
|
|
|
|
q = ce->function_table.arData + j;
|
2014-03-28 19:34:49 +00:00
|
|
|
if (Z_TYPE(q->val) == IS_UNDEF) continue;
|
|
|
|
op_array = (zend_op_array*)Z_PTR(q->val);
|
2013-12-30 02:51:47 +00:00
|
|
|
if (op_array->scope == ce) {
|
2014-12-13 22:06:14 +00:00
|
|
|
zend_accel_optimize(op_array, &ctx);
|
2013-12-30 02:51:47 +00:00
|
|
|
} else if (op_array->type == ZEND_USER_FUNCTION) {
|
|
|
|
zend_op_array *orig_op_array;
|
2014-03-28 19:34:49 +00:00
|
|
|
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, q->key)) != NULL) {
|
2013-12-30 02:51:47 +00:00
|
|
|
HashTable *ht = op_array->static_variables;
|
|
|
|
*op_array = *orig_op_array;
|
|
|
|
op_array->static_variables = ht;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 09:42:38 +00:00
|
|
|
if (ZEND_OPTIMIZER_PASS_12 & OPTIMIZATION_LEVEL) {
|
|
|
|
zend_accel_adjust_fcall_stack_size(&script->main_op_array, &ctx);
|
|
|
|
|
|
|
|
for (idx = 0; idx < script->function_table.nNumUsed; idx++) {
|
|
|
|
p = script->function_table.arData + idx;
|
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
op_array = (zend_op_array*)Z_PTR(p->val);
|
|
|
|
zend_accel_adjust_fcall_stack_size(op_array, &ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (idx = 0; idx < script->class_table.nNumUsed; idx++) {
|
|
|
|
p = script->class_table.arData + idx;
|
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
ce = (zend_class_entry*)Z_PTR(p->val);
|
|
|
|
for (j = 0; j < ce->function_table.nNumUsed; j++) {
|
|
|
|
q = ce->function_table.arData + j;
|
|
|
|
if (Z_TYPE(q->val) == IS_UNDEF) continue;
|
|
|
|
op_array = (zend_op_array*)Z_PTR(q->val);
|
|
|
|
if (op_array->scope == ce) {
|
|
|
|
zend_accel_adjust_fcall_stack_size(op_array, &ctx);
|
|
|
|
} else if (op_array->type == ZEND_USER_FUNCTION) {
|
|
|
|
zend_op_array *orig_op_array;
|
|
|
|
if ((orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, q->key)) != NULL) {
|
|
|
|
HashTable *ht = op_array->static_variables;
|
|
|
|
*op_array = *orig_op_array;
|
|
|
|
op_array->static_variables = ht;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:09:37 +00:00
|
|
|
if (ctx.constants) {
|
|
|
|
zend_hash_destroy(ctx.constants);
|
2013-12-30 02:51:47 +00:00
|
|
|
}
|
2014-06-18 13:09:37 +00:00
|
|
|
zend_arena_destroy(ctx.arena);
|
2013-12-30 02:51:47 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|