summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/block_pass.c59
-rw-r--r--ext/opcache/Optimizer/compact_literals.c41
-rw-r--r--ext/opcache/Optimizer/nop_removal.c23
-rw-r--r--ext/opcache/Optimizer/optimize_func_calls.c24
-rw-r--r--ext/opcache/Optimizer/optimize_temp_vars_5.c10
-rw-r--r--ext/opcache/Optimizer/pass10.c24
-rw-r--r--ext/opcache/Optimizer/pass1_5.c68
-rw-r--r--ext/opcache/Optimizer/pass2.c11
-rw-r--r--ext/opcache/Optimizer/pass3.c28
-rw-r--r--ext/opcache/Optimizer/pass5.c24
-rw-r--r--ext/opcache/Optimizer/pass9.c29
-rw-r--r--ext/opcache/Optimizer/zend_optimizer.c129
-rw-r--r--ext/opcache/Optimizer/zend_optimizer_internal.h56
-rw-r--r--ext/opcache/ZendAccelerator.c187
-rw-r--r--ext/opcache/ZendAccelerator.h46
-rw-r--r--ext/opcache/config.m410
-rw-r--r--ext/opcache/config.w322
-rw-r--r--ext/opcache/zend_accelerator_debug.c2
-rw-r--r--ext/opcache/zend_accelerator_hash.c12
-rw-r--r--ext/opcache/zend_accelerator_hash.h18
-rw-r--r--ext/opcache/zend_accelerator_module.c83
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c120
-rw-r--r--ext/opcache/zend_persist.c66
-rw-r--r--ext/opcache/zend_persist_calc.c31
-rw-r--r--ext/opcache/zend_shared_alloc.c10
-rw-r--r--ext/opcache/zend_shared_alloc.h2
26 files changed, 596 insertions, 519 deletions
diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c
index 32800a1399..42fc06853f 100644
--- a/ext/opcache/Optimizer/block_pass.c
+++ b/ext/opcache/Optimizer/block_pass.c
@@ -19,10 +19,18 @@
+----------------------------------------------------------------------+
*/
+#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"
+
#define DEBUG_BLOCKPASS 0
/* Checks if a constant (like "true") may be replaced by its value */
-static int zend_get_persistent_constant(zend_string *name, zval *result, int copy TSRMLS_DC ELS_DC)
+int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy TSRMLS_DC)
{
zend_constant *c;
char *lookup_name;
@@ -106,7 +114,7 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz
zend_op *opline;
zend_op *end = op_array->opcodes + op_array->last;
zend_code_block *blocks, *cur_block;
- zend_uint opno = 0;
+ uint32_t opno = 0;
memset(cfg, 0, sizeof(zend_cfg));
blocks = cfg->blocks = zend_arena_calloc(&ctx->arena, op_array->last + 2, sizeof(zend_code_block));
@@ -161,7 +169,6 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz
case ZEND_FE_RESET:
case ZEND_NEW:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
START_BLOCK_OP(ZEND_OP2(opline).opline_num);
START_BLOCK_OP(opno + 1);
break;
@@ -289,7 +296,6 @@ static int find_code_blocks(zend_op_array *op_array, zend_cfg *cfg, zend_optimiz
case ZEND_FE_RESET:
case ZEND_NEW:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
case ZEND_FE_FETCH:
cur_block->op2_to = &blocks[ZEND_OP2(opline).opline_num];
/* break missing intentionally */
@@ -606,7 +612,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
end = opline + block->len;
while ((op_array->T) && (opline < end)) {
/* strip X = QM_ASSIGN(const) */
- if (ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ if ((ZEND_OP1_TYPE(opline) & (IS_TMP_VAR|IS_VAR)) &&
VAR_SOURCE(opline->op1) &&
VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN &&
ZEND_OP1_TYPE(VAR_SOURCE(opline->op1)) == IS_CONST &&
@@ -619,13 +625,13 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
zval c = ZEND_OP1_LITERAL(src);
VAR_UNSET(opline->op1);
zval_copy_ctor(&c);
- update_op1_const(op_array, opline, &c TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, &c TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
}
/* T = QM_ASSIGN(C), F(T) => NOP, F(C) */
- if (ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
+ if ((ZEND_OP2_TYPE(opline) & (IS_TMP_VAR|IS_VAR)) &&
VAR_SOURCE(opline->op2) &&
VAR_SOURCE(opline->op2)->opcode == ZEND_QM_ASSIGN &&
ZEND_OP1_TYPE(VAR_SOURCE(opline->op2)) == IS_CONST) {
@@ -633,7 +639,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
zval c = ZEND_OP1_LITERAL(src);
VAR_UNSET(opline->op2);
zval_copy_ctor(&c);
- update_op2_const(op_array, opline, &c TSRMLS_CC);
+ zend_optimizer_update_op2_const(op_array, opline, &c TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(src));
MAKE_NOP(src);
}
@@ -713,7 +719,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
int flen = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].name_len;
if(flen == sizeof("defined")-1 && zend_binary_strcasecmp(fname, flen, "defined", sizeof("defined")-1) == 0) {
zval c;
- if(zend_get_persistent_constant(Z_STR_P(arg), &c, 0 TSRMLS_CC ELS_CC) != 0) {
+ if(zend_optimizer_get_persistent_constant(Z_STR_P(arg), &c, 0 TSRMLS_CC ELS_CC) != 0) {
literal_dtor(arg);
MAKE_NOP(sv);
MAKE_NOP(fcall);
@@ -733,7 +739,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
}
} else if(flen == sizeof("constant")-1 && zend_binary_strcasecmp(fname, flen, "constant", sizeof("constant")-1) == 0) {
zval c;
- if(zend_get_persistent_constant(Z_STR_P(arg), &c, 1 TSRMLS_CC ELS_CC) != 0) {
+ if(zend_optimizer_get_persistent_constant(Z_STR_P(arg), &c, 1 TSRMLS_CC ELS_CC) != 0) {
literal_dtor(arg);
MAKE_NOP(sv);
MAKE_NOP(fcall);
@@ -872,10 +878,10 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
opline->opcode == ZEND_JMPNZ_EX ||
opline->opcode == ZEND_JMPNZ ||
opline->opcode == ZEND_JMPZNZ) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ (ZEND_OP1_TYPE(opline) & (IS_TMP_VAR|IS_VAR)) &&
VAR_SOURCE(opline->op1) != NULL &&
(!used_ext[VAR_NUM(ZEND_OP1(opline).var)] ||
- (ZEND_RESULT_TYPE(opline) == IS_TMP_VAR &&
+ ((ZEND_RESULT_TYPE(opline) & (IS_TMP_VAR|IS_VAR)) &&
ZEND_RESULT(opline).var == ZEND_OP1(opline).var)) &&
(VAR_SOURCE(opline->op1)->opcode == ZEND_BOOL ||
VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN)) {
@@ -906,11 +912,11 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
old_len = Z_STRLEN(ZEND_OP1_LITERAL(last_op));
l = old_len + Z_STRLEN(ZEND_OP1_LITERAL(opline));
if (IS_INTERNED(Z_STR(ZEND_OP1_LITERAL(last_op)))) {
- zend_string *tmp = STR_ALLOC(l, 0);
+ zend_string *tmp = zend_string_alloc(l, 0);
memcpy(tmp->val, Z_STRVAL(ZEND_OP1_LITERAL(last_op)), old_len);
Z_STR(ZEND_OP1_LITERAL(last_op)) = tmp;
} else {
- Z_STR(ZEND_OP1_LITERAL(last_op)) = STR_REALLOC(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
+ Z_STR(ZEND_OP1_LITERAL(last_op)) = zend_string_realloc(Z_STR(ZEND_OP1_LITERAL(last_op)), l, 0);
}
Z_TYPE_INFO(ZEND_OP1_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP1_LITERAL(last_op)) + old_len, Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)));
@@ -950,16 +956,16 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
old_len = Z_STRLEN(ZEND_OP2_LITERAL(src));
l = old_len + Z_STRLEN(ZEND_OP2_LITERAL(opline));
if (IS_INTERNED(Z_STR(ZEND_OP2_LITERAL(src)))) {
- zend_string *tmp = STR_ALLOC(l, 0);
+ zend_string *tmp = zend_string_alloc(l, 0);
memcpy(tmp->val, Z_STRVAL(ZEND_OP2_LITERAL(src)), old_len);
Z_STR(ZEND_OP2_LITERAL(last_op)) = tmp;
} else {
- Z_STR(ZEND_OP2_LITERAL(src)) = STR_REALLOC(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
+ Z_STR(ZEND_OP2_LITERAL(src)) = zend_string_realloc(Z_STR(ZEND_OP2_LITERAL(src)), l, 0);
}
Z_TYPE_INFO(ZEND_OP2_LITERAL(last_op)) = IS_STRING_EX;
memcpy(Z_STRVAL(ZEND_OP2_LITERAL(src)) + old_len, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
Z_STRVAL(ZEND_OP2_LITERAL(src))[l] = '\0';
- STR_RELEASE(Z_STR(ZEND_OP2_LITERAL(opline)));
+ zend_string_release(Z_STR(ZEND_OP2_LITERAL(opline)));
Z_STR(ZEND_OP2_LITERAL(opline)) = zend_new_interned_string(Z_STR(ZEND_OP2_LITERAL(src)) TSRMLS_CC);
if (IS_INTERNED(Z_STR(ZEND_OP2_LITERAL(opline)))) {
Z_TYPE_FLAGS(ZEND_OP2_LITERAL(opline)) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
@@ -1019,7 +1025,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
literal_dtor(&ZEND_OP2_LITERAL(opline));
opline->opcode = ZEND_QM_ASSIGN;
SET_UNUSED(opline->op2);
- update_op1_const(op_array, opline, &result TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, &result TSRMLS_CC);
}
EG(error_reporting) = er;
} else if ((opline->opcode == ZEND_BOOL ||
@@ -1039,9 +1045,9 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
ZVAL_NULL(&ZEND_OP1_LITERAL(opline));
}
opline->opcode = ZEND_QM_ASSIGN;
- update_op1_const(op_array, opline, &result TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, &result TSRMLS_CC);
} else if ((opline->opcode == ZEND_RETURN || opline->opcode == ZEND_EXIT) &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
+ (ZEND_OP1_TYPE(opline) & (IS_TMP_VAR|IS_VAR)) &&
VAR_SOURCE(opline->op1) &&
VAR_SOURCE(opline->op1)->opcode == ZEND_QM_ASSIGN) {
/* T = QM_ASSIGN(X), RETURN(T) to RETURN(X) */
@@ -1125,8 +1131,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
opline->opcode = ZEND_CONCAT;
MAKE_NOP(src);
} else if (opline->opcode == ZEND_QM_ASSIGN &&
- ZEND_OP1_TYPE(opline) == IS_TMP_VAR &&
- ZEND_RESULT_TYPE(opline) == IS_TMP_VAR &&
+ ZEND_OP1_TYPE(opline) == ZEND_RESULT_TYPE(opline) &&
ZEND_OP1(opline).var == ZEND_RESULT(opline).var) {
/* strip T = QM_ASSIGN(T) */
MAKE_NOP(opline);
@@ -1264,8 +1269,8 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array)
op_array->opcodes = erealloc(new_opcodes, op_array->last * sizeof(zend_op));
/* adjust early binding list */
- if (op_array->early_binding != (zend_uint)-1) {
- zend_uint *opline_num = &op_array->early_binding;
+ if (op_array->early_binding != (uint32_t)-1) {
+ uint32_t *opline_num = &op_array->early_binding;
zend_op *end;
opline = op_array->opcodes;
@@ -1441,7 +1446,7 @@ static void zend_jmp_optimization(zend_code_block *block, zend_op_array *op_arra
if (block->op2_to) {
zend_uchar same_type = ZEND_OP1_TYPE(last_op);
- zend_uint same_var = VAR_NUM_EX(last_op->op1);
+ uint32_t same_var = VAR_NUM_EX(last_op->op1);
zend_op *target;
zend_op *target_end;
zend_code_block *target_block = block->op2_to;;
@@ -1939,7 +1944,7 @@ static void zend_t_usage(zend_code_block *block, zend_op_array *op_array, char *
#define PASSES 3
-static void zend_block_optimization(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
+void optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
{
zend_cfg cfg;
zend_code_block *cur_block;
@@ -1952,7 +1957,7 @@ static void zend_block_optimization(zend_op_array *op_array, zend_optimizer_ctx
fflush(stderr);
#endif
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
return;
}
diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c
index 551f439041..28e7a11314 100644
--- a/ext/opcache/Optimizer/compact_literals.c
+++ b/ext/opcache/Optimizer/compact_literals.c
@@ -20,6 +20,15 @@
/* pass 11
* - compact literals table
*/
+
+#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"
+
#define DEBUG_COMPACT_LITERALS 0
#define LITERAL_VALUE 0x0100
@@ -44,7 +53,7 @@
#define LITERAL_NUM_SLOTS(info) ((info & LITERAL_NUM_SLOTS_MASK) >> LITERAL_NUM_SLOTS_SHIFT)
typedef struct _literal_info {
- zend_uint flags; /* bitmask (see defines above) */
+ uint32_t flags; /* bitmask (see defines above) */
union {
int num; /* variable number or class name literal number */
} u;
@@ -71,9 +80,9 @@ static void optimizer_literal_obj_info(literal_info *info,
zend_uchar op_type,
znode_op op,
int constant,
- zend_uint kind,
- zend_uint slots,
- zend_uint related,
+ uint32_t kind,
+ uint32_t slots,
+ uint32_t related,
zend_op_array *op_array)
{
/* For now we merge only $this object properties and methods.
@@ -92,9 +101,9 @@ static void optimizer_literal_class_info(literal_info *info,
zend_uchar op_type,
znode_op op,
int constant,
- zend_uint kind,
- zend_uint slots,
- zend_uint related,
+ uint32_t kind,
+ uint32_t slots,
+ uint32_t related,
zend_op_array *op_array)
{
if (op_type == IS_CONST) {
@@ -104,7 +113,7 @@ static void optimizer_literal_class_info(literal_info *info,
}
}
-static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
+void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
{
zend_op *opline, *end;
int i, j, n, *map, cache_slots;
@@ -302,7 +311,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
/* Merge equal constants */
j = 0; cache_slots = 0;
- zend_hash_init(&hash, 16, NULL, NULL, 0);
+ zend_hash_init(&hash, op_array->last_literal, NULL, NULL, 0);
map = (int*)zend_arena_alloc(&ctx->arena, op_array->last_literal * sizeof(int));
memset(map, 0, op_array->last_literal * sizeof(int));
for (i = 0; i < op_array->last_literal; i++) {
@@ -351,7 +360,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
} else {
map[i] = j;
ZVAL_LONG(&zv, j);
- zend_hash_index_update(&hash, Z_LVAL(op_array->literals[i]), &zv);
+ zend_hash_index_add_new(&hash, Z_LVAL(op_array->literals[i]), &zv);
if (i != j) {
op_array->literals[j] = op_array->literals[i];
info[j] = info[i];
@@ -378,20 +387,20 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
if (info[i].flags & LITERAL_MAY_MERGE) {
if (info[i].flags & LITERAL_EX_OBJ) {
int key_len = MAX_LENGTH_OF_LONG + sizeof("->") + Z_STRLEN(op_array->literals[i]);
- key = STR_ALLOC(key_len, 0);
+ key = zend_string_alloc(key_len, 0);
key->len = snprintf(key->val, key->len-1, "%d->%s", info[i].u.num, Z_STRVAL(op_array->literals[i]));
} else if (info[i].flags & LITERAL_EX_CLASS) {
int key_len;
zval *class_name = &op_array->literals[(info[i].u.num < i) ? map[info[i].u.num] : info[i].u.num];
key_len = Z_STRLEN_P(class_name) + sizeof("::") + Z_STRLEN(op_array->literals[i]);
- key = STR_ALLOC(key_len, 0);
+ key = zend_string_alloc(key_len, 0);
memcpy(key->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name));
memcpy(key->val + Z_STRLEN_P(class_name), "::", sizeof("::") - 1);
memcpy(key->val + Z_STRLEN_P(class_name) + sizeof("::") - 1,
Z_STRVAL(op_array->literals[i]),
Z_STRLEN(op_array->literals[i]) + 1);
} else {
- key = STR_INIT(Z_STRVAL(op_array->literals[i]), Z_STRLEN(op_array->literals[i]), 0);
+ key = zend_string_init(Z_STRVAL(op_array->literals[i]), Z_STRLEN(op_array->literals[i]), 0);
}
key->h = zend_hash_func(key->val, key->len);
key->h += info[i].flags;
@@ -401,7 +410,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
Z_TYPE(op_array->literals[i]) == Z_TYPE(op_array->literals[Z_LVAL_P(pos)]) &&
info[i].flags == info[Z_LVAL_P(pos)].flags) {
- STR_RELEASE(key);
+ zend_string_release(key);
map[i] = Z_LVAL_P(pos);
zval_dtor(&op_array->literals[i]);
n = LITERAL_NUM_RELATED(info[i].flags);
@@ -414,8 +423,8 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
map[i] = j;
if (info[i].flags & LITERAL_MAY_MERGE) {
ZVAL_LONG(&zv, j);
- zend_hash_add(&hash, key, &zv);
- STR_RELEASE(key);
+ zend_hash_add_new(&hash, key, &zv);
+ zend_string_release(key);
}
if (i != j) {
op_array->literals[j] = op_array->literals[i];
diff --git a/ext/opcache/Optimizer/nop_removal.c b/ext/opcache/Optimizer/nop_removal.c
index 80da02ce32..17cc838990 100644
--- a/ext/opcache/Optimizer/nop_removal.c
+++ b/ext/opcache/Optimizer/nop_removal.c
@@ -23,15 +23,23 @@
* - remove NOPs
*/
-static void nop_removal(zend_op_array *op_array)
+#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"
+
+void zend_optimizer_nop_removal(zend_op_array *op_array)
{
zend_op *end, *opline;
- zend_uint new_count, i, shift;
+ uint32_t new_count, i, shift;
int j;
- zend_uint *shiftlist;
+ uint32_t *shiftlist;
ALLOCA_FLAG(use_heap);
- shiftlist = (zend_uint *)DO_ALLOCA(sizeof(zend_uint) * op_array->last);
+ shiftlist = (uint32_t *)DO_ALLOCA(sizeof(uint32_t) * op_array->last);
i = new_count = shift = 0;
end = op_array->opcodes + op_array->last;
for (opline = op_array->opcodes; opline < end; opline++) {
@@ -89,7 +97,6 @@ static void nop_removal(zend_op_array *op_array)
case ZEND_FE_RESET:
case ZEND_NEW:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
ZEND_OP2(opline).opline_num -= shiftlist[ZEND_OP2(opline).opline_num];
break;
case ZEND_JMPZNZ:
@@ -120,13 +127,13 @@ static void nop_removal(zend_op_array *op_array)
}
/* update early binding list */
- if (op_array->early_binding != (zend_uint)-1) {
- zend_uint *opline_num = &op_array->early_binding;
+ if (op_array->early_binding != (uint32_t)-1) {
+ uint32_t *opline_num = &op_array->early_binding;
do {
*opline_num -= shiftlist[*opline_num];
opline_num = &ZEND_RESULT(&op_array->opcodes[*opline_num]).opline_num;
- } while (*opline_num != (zend_uint)-1);
+ } while (*opline_num != (uint32_t)-1);
}
}
FREE_ALLOCA(shiftlist);
diff --git a/ext/opcache/Optimizer/optimize_func_calls.c b/ext/opcache/Optimizer/optimize_func_calls.c
index ead951ac73..aa62a4542d 100644
--- a/ext/opcache/Optimizer/optimize_func_calls.c
+++ b/ext/opcache/Optimizer/optimize_func_calls.c
@@ -20,12 +20,26 @@
/* pass 4
* - optimize INIT_FCALL_BY_NAME to DO_FCALL
*/
+
+#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"
+
+#define ZEND_OP2_IS_CONST_STRING(opline) \
+ (ZEND_OP2_TYPE(opline) == IS_CONST && \
+ Z_TYPE(op_array->literals[(opline)->op2.constant]) == IS_STRING)
+
typedef struct _optimizer_call_info {
zend_function *func;
zend_op *opline;
} optimizer_call_info;
-static void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC) {
+void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
+{
zend_op *opline = op_array->opcodes;
zend_op *end = opline + op_array->last;
int call = 0;
@@ -42,7 +56,7 @@ static void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx
switch (opline->opcode) {
case ZEND_INIT_FCALL_BY_NAME:
case ZEND_INIT_NS_FCALL_BY_NAME:
- if (ZEND_OP2_TYPE(opline) == IS_CONST) {
+ if (ZEND_OP2_IS_CONST_STRING(opline)) {
zend_function *func;
zval *function_name = &op_array->literals[opline->op2.constant + 1];
if ((func = zend_hash_find_ptr(&ctx->script->function_table,
@@ -78,10 +92,10 @@ static void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx
} else {
ZEND_ASSERT(0);
}
- } else if (opline->extended_value == 0 &&
- call_stack[call].opline &&
+ } else if (call_stack[call].opline &&
call_stack[call].opline->opcode == ZEND_INIT_FCALL_BY_NAME &&
- ZEND_OP2_TYPE(call_stack[call].opline) == IS_CONST) {
+ call_stack[call].opline->extended_value == 0 &&
+ ZEND_OP2_IS_CONST_STRING(call_stack[call].opline)) {
zend_op *fcall = call_stack[call].opline;
diff --git a/ext/opcache/Optimizer/optimize_temp_vars_5.c b/ext/opcache/Optimizer/optimize_temp_vars_5.c
index df5d00a366..a7838cb9dd 100644
--- a/ext/opcache/Optimizer/optimize_temp_vars_5.c
+++ b/ext/opcache/Optimizer/optimize_temp_vars_5.c
@@ -19,6 +19,14 @@
+----------------------------------------------------------------------+
*/
+#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"
+
#define GET_AVAILABLE_T() \
for (i = 0; i < T; i++) { \
if (!taken_T[i]) { \
@@ -30,7 +38,7 @@
max = i; \
}
-static void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx)
+void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx)
{
int T = op_array->T;
int offset = op_array->last_var;
diff --git a/ext/opcache/Optimizer/pass10.c b/ext/opcache/Optimizer/pass10.c
deleted file mode 100644
index 7f2004a7dc..0000000000
--- a/ext/opcache/Optimizer/pass10.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Zend OPcache |
- +----------------------------------------------------------------------+
- | Copyright (c) 1998-2014 The PHP Group |
- +----------------------------------------------------------------------+
- | 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> |
- +----------------------------------------------------------------------+
-*/
-
-if (((ZEND_OPTIMIZER_PASS_10|ZEND_OPTIMIZER_PASS_5) & OPTIMIZATION_LEVEL) == ZEND_OPTIMIZER_PASS_10) {
- nop_removal(op_array);
-}
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index ecbfb638a0..3f3e72dc31 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -27,9 +27,18 @@
* - pre-evaluate constant function calls
*/
+#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"
+
#define ZEND_IS_CONSTANT_TYPE(t) ((t) == IS_CONSTANT)
-if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
+void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC)
+{
int i = 0;
zend_op *opline = op_array->opcodes;
zend_op *end = opline + op_array->last;
@@ -60,7 +69,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
ZEND_OP2_TYPE(opline) == IS_CONST) {
/* binary operation with constant operands */
int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC) = get_binary_op(opline->opcode);
- zend_uint tv = ZEND_RESULT(opline).var; /* temporary variable */
+ uint32_t tv = ZEND_RESULT(opline).var; /* temporary variable */
zval result;
int er;
@@ -82,7 +91,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
- replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
}
break;
@@ -92,7 +101,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
opline->extended_value != IS_OBJECT &&
opline->extended_value != IS_RESOURCE) {
/* cast of constant operand */
- zend_uint tv = ZEND_RESULT(opline).var; /* temporary variable */
+ uint32_t tv = ZEND_RESULT(opline).var; /* temporary variable */
zval res;
res = ZEND_OP1_LITERAL(opline);
zval_copy_ctor(&res);
@@ -118,9 +127,9 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
MAKE_NOP(opline);
if (opline->result_type == IS_TMP_VAR) {
- replace_tmp_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
} else /* if (opline->result_type == IS_VAR) */ {
- replace_var_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
+ zend_optimizer_replace_var_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
}
} else if (opline->extended_value == _IS_BOOL) {
/* T = CAST(X, IS_BOOL) => T = BOOL(X) */
@@ -135,7 +144,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
/* unary operation on constant operand */
unary_op_type unary_op = get_unary_op(opline->opcode);
zval result;
- zend_uint tv = ZEND_RESULT(opline).var; /* temporary variable */
+ uint32_t tv = ZEND_RESULT(opline).var; /* temporary variable */
int er;
er = EG(error_reporting);
@@ -148,7 +157,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
literal_dtor(&ZEND_OP1_LITERAL(opline));
MAKE_NOP(opline);
- replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
}
break;
@@ -183,7 +192,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
}
last_op = next_op;
final_length += (requires_conversion? 1 : Z_STRLEN(ZEND_OP2_LITERAL(opline)));
- str = STR_ALLOC(final_length, 0);
+ str = zend_string_alloc(final_length, 0);
ptr = str->val;
ptr[final_length] = '\0';
if (requires_conversion) { /* ZEND_ADD_CHAR */
@@ -195,7 +204,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
ptr++;
} else { /* ZEND_ADD_STRING */
memcpy(ptr, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
- STR_RELEASE(Z_STR(ZEND_OP2_LITERAL(opline)));
+ zend_string_release(Z_STR(ZEND_OP2_LITERAL(opline)));
Z_STR(ZEND_OP2_LITERAL(opline)) = str;
ptr += Z_STRLEN(ZEND_OP2_LITERAL(opline));
}
@@ -238,11 +247,11 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
fake_execute_data.func = (zend_function*)op_array;
EG(current_execute_data) = &fake_execute_data;
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1 TSRMLS_CC)) != NULL) {
- zend_uint tv = ZEND_RESULT(opline).var;
+ uint32_t tv = ZEND_RESULT(opline).var;
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
- replace_tmp_by_const(op_array, opline, tv, offset TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline, tv, offset TSRMLS_CC);
}
EG(current_execute_data) = orig_execute_data;
break;
@@ -252,17 +261,17 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
ZEND_OP2_TYPE(opline) == IS_CONST &&
Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING) {
/* substitute persistent constants */
- zend_uint tv = ZEND_RESULT(opline).var;
+ uint32_t tv = ZEND_RESULT(opline).var;
zval c;
- if (!zend_get_persistent_constant(Z_STR(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC)) {
+ if (!zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC)) {
if (!ctx->constants || !zend_optimizer_get_collected_constant(ctx->constants, &ZEND_OP2_LITERAL(opline), &c)) {
break;
}
}
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
- replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
}
/* class constant */
@@ -300,14 +309,14 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
}
if (ce) {
- zend_uint tv = ZEND_RESULT(opline).var;
+ uint32_t tv = ZEND_RESULT(opline).var;
zval *c, t;
if ((c = zend_hash_find(&ce->constants_table,
Z_STR(ZEND_OP2_LITERAL(opline)))) != NULL) {
ZVAL_DEREF(c);
if (ZEND_IS_CONSTANT_TYPE(Z_TYPE_P(c))) {
- if (!zend_get_persistent_constant(Z_STR_P(c), &t, 1 TSRMLS_CC) ||
+ if (!zend_optimizer_get_persistent_constant(Z_STR_P(c), &t, 1 TSRMLS_CC) ||
ZEND_IS_CONSTANT_TYPE(Z_TYPE(t))) {
break;
}
@@ -323,7 +332,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
}
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
- replace_tmp_by_const(op_array, opline, tv, &t TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline, tv, &t TSRMLS_CC);
}
}
}
@@ -379,7 +388,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
func->module->type == MODULE_PERSISTENT) {
zval t;
ZVAL_BOOL(&t, 1);
- if (replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
+ if (zend_optimizer_replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
literal_dtor(&ZEND_OP1_LITERAL(opline + 1));
@@ -412,7 +421,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
}
}
- if (replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
+ if (zend_optimizer_replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
literal_dtor(&ZEND_OP1_LITERAL(opline + 1));
@@ -424,10 +433,10 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
"defined", sizeof("defined")-1)) {
zval t;
- if (zend_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline + 1)), &t, 0 TSRMLS_CC)) {
+ if (zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline + 1)), &t, 0 TSRMLS_CC)) {
ZVAL_BOOL(&t, 1);
- if (replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
+ if (zend_optimizer_replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
literal_dtor(&ZEND_OP1_LITERAL(opline + 1));
@@ -440,8 +449,8 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
"constant", sizeof("constant")-1)) {
zval t;
- if (zend_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline + 1)), &t, 1 TSRMLS_CC)) {
- if (replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
+ if (zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline + 1)), &t, 1 TSRMLS_CC)) {
+ if (zend_optimizer_replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
literal_dtor(&ZEND_OP1_LITERAL(opline + 1));
@@ -456,7 +465,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
zval t;
ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline + 1)));
- if (replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
+ if (zend_optimizer_replace_var_by_const(op_array, opline + 3, ZEND_RESULT(opline + 2).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP2_LITERAL(opline));
MAKE_NOP(opline);
literal_dtor(&ZEND_OP1_LITERAL(opline + 1));
@@ -472,7 +481,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
zval t;
ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline)));
- replace_tmp_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(opline));
MAKE_NOP(opline);
}
@@ -480,12 +489,12 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
case ZEND_DEFINED:
{
zval c;
- zend_uint tv = ZEND_RESULT(opline).var;
- if (!zend_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline)), &c, 0 TSRMLS_CC)) {
+ uint32_t tv = ZEND_RESULT(opline).var;
+ if (!zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(opline)), &c, 0 TSRMLS_CC)) {
break;
}
ZVAL_TRUE(&c);
- replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
+ zend_optimizer_replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
literal_dtor(&ZEND_OP1_LITERAL(opline));
MAKE_NOP(opline);
}
@@ -520,7 +529,6 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
case ZEND_NEW:
case ZEND_DO_FCALL:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
collect_constants = 0;
break;
case ZEND_FETCH_R:
diff --git a/ext/opcache/Optimizer/pass2.c b/ext/opcache/Optimizer/pass2.c
index 083a7b961b..5fa6560d48 100644
--- a/ext/opcache/Optimizer/pass2.c
+++ b/ext/opcache/Optimizer/pass2.c
@@ -25,7 +25,16 @@
* - optimize static BRKs and CONTs
*/
-if (ZEND_OPTIMIZER_PASS_2 & OPTIMIZATION_LEVEL) {
+#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"
+
+void zend_optimizer_pass2(zend_op_array *op_array TSRMLS_DC)
+{
zend_op *opline;
zend_op *end = op_array->opcodes + op_array->last;
diff --git a/ext/opcache/Optimizer/pass3.c b/ext/opcache/Optimizer/pass3.c
index 810eedb646..345e347a5b 100644
--- a/ext/opcache/Optimizer/pass3.c
+++ b/ext/opcache/Optimizer/pass3.c
@@ -25,6 +25,14 @@
* - change $i++ to ++$i where possible
*/
+#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"
+
/* compares opcodes with allowing oc1 be _EX of oc2 */
#define SAME_OPCODE_EX(oc1, oc2) ((oc1 == oc2) || (oc1 == ZEND_JMPZ_EX && oc2 == ZEND_JMPZ) || (oc1 == ZEND_JMPNZ_EX && oc2 == ZEND_JMPNZ))
@@ -45,16 +53,17 @@
} \
jmp_hitlist[jmp_hitlist_count++] = ZEND_OP2(&op_array->opcodes[target]).opline_num;
-if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
+void zend_optimizer_pass3(zend_op_array *op_array TSRMLS_DC)
+{
zend_op *opline;
zend_op *end = op_array->opcodes + op_array->last;
- zend_uint *jmp_hitlist;
+ uint32_t *jmp_hitlist;
int jmp_hitlist_count;
int i;
- zend_uint opline_num = 0;
+ uint32_t opline_num = 0;
ALLOCA_FLAG(use_heap);
- jmp_hitlist = (zend_uint *)DO_ALLOCA(sizeof(zend_uint)*op_array->last);
+ jmp_hitlist = (uint32_t *)DO_ALLOCA(sizeof(uint32_t)*op_array->last);
opline = op_array->opcodes;
while (opline < end) {
@@ -153,7 +162,7 @@ if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
break;
case ZEND_JMP:
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
break;
}
@@ -173,8 +182,7 @@ if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
break;
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
break;
}
@@ -189,7 +197,7 @@ if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
break;
case ZEND_JMPZ:
case ZEND_JMPNZ:
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
break;
}
@@ -245,7 +253,7 @@ if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
zend_uchar T_type = opline->result_type;
znode_op T = opline->result;
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
break;
}
@@ -379,7 +387,7 @@ continue_jmp_ex_optimization:
break;
case ZEND_JMPZNZ:
- if (op_array->has_finally_block) {
+ if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
break;
}
diff --git a/ext/opcache/Optimizer/pass5.c b/ext/opcache/Optimizer/pass5.c
deleted file mode 100644
index fffcf985d5..0000000000
--- a/ext/opcache/Optimizer/pass5.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Zend OPcache |
- +----------------------------------------------------------------------+
- | Copyright (c) 1998-2014 The PHP Group |
- +----------------------------------------------------------------------+
- | 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> |
- +----------------------------------------------------------------------+
-*/
-
-if (ZEND_OPTIMIZER_PASS_5 & OPTIMIZATION_LEVEL) {
- zend_block_optimization(op_array, ctx TSRMLS_CC);
-}
diff --git a/ext/opcache/Optimizer/pass9.c b/ext/opcache/Optimizer/pass9.c
deleted file mode 100644
index 42c2ae1f4d..0000000000
--- a/ext/opcache/Optimizer/pass9.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Zend OPcache |
- +----------------------------------------------------------------------+
- | Copyright (c) 1998-2014 The PHP Group |
- +----------------------------------------------------------------------+
- | 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> |
- +----------------------------------------------------------------------+
-*/
-
-/* pass 9
- *
- * - optimize usage of temporary variables
- */
-
-if (ZEND_OPTIMIZER_PASS_9 & OPTIMIZATION_LEVEL) {
- optimize_temporary_variables(op_array, ctx);
-}
diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c
index b783c3777b..f31ce38cfe 100644
--- a/ext/opcache/Optimizer/zend_optimizer.c
+++ b/ext/opcache/Optimizer/zend_optimizer.c
@@ -27,15 +27,12 @@
#include "zend_execute.h"
#include "zend_vm.h"
-#define OPTIMIZATION_LEVEL \
- ZCG(accel_directives).optimization_level
-
static void zend_optimizer_zval_dtor_wrapper(zval *zvalue)
{
zval_dtor(zvalue);
}
-static void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value)
+void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value)
{
zval val;
@@ -47,7 +44,7 @@ static void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name,
zend_hash_add(ctx->constants, Z_STR_P(name), &val);
}
-static int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value)
+int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value)
{
zval *val;
@@ -58,10 +55,10 @@ static int zend_optimizer_get_collected_constant(HashTable *constants, zval *nam
return 0;
}
-static int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name)
+int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name)
{
int i = 0;
- ulong hash_value = STR_HASH_VAL(name);
+ zend_ulong hash_value = zend_string_hash_val(name);
while (i < op_array->last_var) {
if (op_array->vars[i] == name ||
@@ -75,7 +72,7 @@ static int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name)
i = op_array->last_var;
op_array->last_var++;
op_array->vars = erealloc(op_array->vars, op_array->last_var * sizeof(zend_string*));
- op_array->vars[i] = STR_DUP(name, 0);
+ op_array->vars[i] = zend_string_dup(name, 0);
/* all IS_TMP_VAR and IS_VAR variable numbers have to be adjusted */
{
@@ -114,32 +111,9 @@ int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC)
return i;
}
-# define LITERAL_LONG(op, val) do { \
- zval _c; \
- ZVAL_LONG(&_c, val); \
- op.constant = zend_optimizer_add_literal(op_array, &_c TSRMLS_CC); \
- } while (0)
-
-# define LITERAL_BOOL(op, val) do { \
- zval _c; \
- ZVAL_BOOL(&_c, val); \
- op.constant = zend_optimizer_add_literal(op_array, &_c TSRMLS_CC); \
- } while (0)
-
-# define literal_dtor(zv) do { \
- zval_dtor(zv); \
- ZVAL_NULL(zv); \
- } while (0)
-
-#define COPY_NODE(target, src) do { \
- target ## _type = src ## _type; \
- target = src; \
- } while (0)
-
-
-static void update_op1_const(zend_op_array *op_array,
- zend_op *opline,
- zval *val TSRMLS_DC)
+void zend_optimizer_update_op1_const(zend_op_array *op_array,
+ zend_op *opline,
+ zval *val TSRMLS_DC)
{
if (opline->opcode == ZEND_FREE) {
MAKE_NOP(opline);
@@ -153,15 +127,15 @@ static void update_op1_const(zend_op_array *op_array,
case ZEND_FETCH_CONSTANT:
case ZEND_DEFINED:
opline->op1.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(ZEND_OP1_LITERAL(opline)));
+ zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline)));
Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->last_cache_slot++;
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(op_array->literals[opline->op1.constant+1]));
+ zend_string_hash_val(Z_STR(op_array->literals[opline->op1.constant+1]));
break;
default:
opline->op1.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(ZEND_OP1_LITERAL(opline)));
+ zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline)));
break;
}
} else {
@@ -170,21 +144,21 @@ static void update_op1_const(zend_op_array *op_array,
}
}
-static void update_op2_const(zend_op_array *op_array,
- zend_op *opline,
- zval *val TSRMLS_DC)
+void zend_optimizer_update_op2_const(zend_op_array *op_array,
+ zend_op *opline,
+ zval *val TSRMLS_DC)
{
ZEND_OP2_TYPE(opline) = IS_CONST;
if (opline->opcode == ZEND_INIT_FCALL) {
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
opline->op2.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(ZEND_OP2_LITERAL(opline)));
+ zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline)));
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->last_cache_slot++;
return;
}
opline->op2.constant = zend_optimizer_add_literal(op_array, val TSRMLS_CC);
if (Z_TYPE_P(val) == IS_STRING) {
- STR_HASH_VAL(Z_STR(ZEND_OP2_LITERAL(opline)));
+ zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline)));
switch (opline->opcode) {
case ZEND_FETCH_R:
case ZEND_FETCH_W:
@@ -202,13 +176,13 @@ static void update_op2_const(zend_op_array *op_array,
Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->last_cache_slot++;
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(op_array->literals[opline->op2.constant+1]));
+ zend_string_hash_val(Z_STR(op_array->literals[opline->op2.constant+1]));
break;
case ZEND_INIT_METHOD_CALL:
case ZEND_INIT_STATIC_METHOD_CALL:
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
zend_optimizer_add_literal(op_array, val TSRMLS_CC);
- STR_HASH_VAL(Z_STR(op_array->literals[opline->op2.constant+1]));
+ zend_string_hash_val(Z_STR(op_array->literals[opline->op2.constant+1]));
/* break missing intentionally */
/*case ZEND_FETCH_CONSTANT:*/
case ZEND_ASSIGN_OBJ:
@@ -273,7 +247,7 @@ static void update_op2_const(zend_op_array *op_array,
case ZEND_FETCH_DIM_TMP_VAR:
check_numeric:
{
- ulong index;
+ zend_ulong index;
if (ZEND_HANDLE_NUMERIC(Z_STR_P(val), index)) {
zval_dtor(val);
@@ -288,10 +262,10 @@ check_numeric:
}
}
-static int replace_var_by_const(zend_op_array *op_array,
- zend_op *opline,
- zend_uint var,
- zval *val TSRMLS_DC)
+int zend_optimizer_replace_var_by_const(zend_op_array *op_array,
+ zend_op *opline,
+ uint32_t var,
+ zval *val TSRMLS_DC)
{
zend_op *end = op_array->opcodes + op_array->last;
@@ -321,7 +295,7 @@ static int replace_var_by_const(zend_op_array *op_array,
default:
break;
}
- update_op1_const(op_array, opline, val TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, val TSRMLS_CC);
break;
}
@@ -333,7 +307,7 @@ static int replace_var_by_const(zend_op_array *op_array,
default:
break;
}
- update_op2_const(op_array, opline, val TSRMLS_CC);
+ zend_optimizer_update_op2_const(op_array, opline, val TSRMLS_CC);
break;
}
opline++;
@@ -342,11 +316,11 @@ static int replace_var_by_const(zend_op_array *op_array,
return 1;
}
-static void replace_tmp_by_const(zend_op_array *op_array,
- zend_op *opline,
- zend_uint var,
- zval *val
- TSRMLS_DC)
+void zend_optimizer_replace_tmp_by_const(zend_op_array *op_array,
+ zend_op *opline,
+ uint32_t var,
+ zval *val
+ TSRMLS_DC)
{
zend_op *end = op_array->opcodes + op_array->last;
@@ -364,13 +338,13 @@ static void replace_tmp_by_const(zend_op_array *op_array,
zval old_val;
ZVAL_COPY_VALUE(&old_val, val);
zval_copy_ctor(val);
- update_op1_const(op_array, opline, val TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, val TSRMLS_CC);
ZVAL_COPY_VALUE(val, &old_val);
} else if (opline->opcode == ZEND_FREE) {
MAKE_NOP(opline);
break;
} else {
- update_op1_const(op_array, opline, val TSRMLS_CC);
+ zend_optimizer_update_op1_const(op_array, opline, val TSRMLS_CC);
val = NULL;
break;
}
@@ -379,7 +353,7 @@ static void replace_tmp_by_const(zend_op_array *op_array,
if (ZEND_OP2_TYPE(opline) == IS_TMP_VAR &&
ZEND_OP2(opline).var == var) {
- update_op2_const(op_array, opline, val TSRMLS_CC);
+ zend_optimizer_update_op2_const(op_array, opline, val TSRMLS_CC);
/* TMP_VAR may be used only once */
val = NULL;
break;
@@ -391,17 +365,10 @@ static void replace_tmp_by_const(zend_op_array *op_array,
}
}
-#include "Optimizer/nop_removal.c"
-#include "Optimizer/block_pass.c"
-#include "Optimizer/optimize_temp_vars_5.c"
-#include "Optimizer/compact_literals.c"
-#include "Optimizer/optimize_func_calls.c"
-
static void zend_optimize(zend_op_array *op_array,
zend_optimizer_ctx *ctx TSRMLS_DC)
{
- if (op_array->type == ZEND_EVAL_CODE ||
- (op_array->fn_flags & ZEND_ACC_INTERACTIVE)) {
+ if (op_array->type == ZEND_EVAL_CODE) {
return;
}
@@ -411,7 +378,9 @@ static void zend_optimize(zend_op_array *op_array,
* - optimize series of ADD_STRING and/or ADD_CHAR
* - convert CAST(IS_BOOL,x) into BOOL(x)
*/
-#include "Optimizer/pass1_5.c"
+ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
+ zend_optimizer_pass1(op_array, ctx TSRMLS_CC);
+ }
/* pass 2:
* - convert non-numeric constants to numeric constants in numeric operators
@@ -419,14 +388,18 @@ static void zend_optimize(zend_op_array *op_array,
* - optimize static BRKs and CONTs
* - pre-evaluate constant function calls
*/
-#include "Optimizer/pass2.c"
+ if (ZEND_OPTIMIZER_PASS_2 & OPTIMIZATION_LEVEL) {
+ zend_optimizer_pass2(op_array TSRMLS_CC);
+ }
/* pass 3:
* - optimize $i = $i+expr to $i+=expr
* - optimize series of JMPs
* - change $i++ to ++$i where possible
*/
-#include "Optimizer/pass3.c"
+ if (ZEND_OPTIMIZER_PASS_3 & OPTIMIZATION_LEVEL) {
+ zend_optimizer_pass3(op_array TSRMLS_CC);
+ }
/* pass 4:
* - INIT_FCALL_BY_NAME -> DO_FCALL
@@ -438,23 +411,29 @@ static void zend_optimize(zend_op_array *op_array,
/* pass 5:
* - CFG optimization
*/
-#include "Optimizer/pass5.c"
+ if (ZEND_OPTIMIZER_PASS_5 & OPTIMIZATION_LEVEL) {
+ optimize_cfg(op_array, ctx TSRMLS_CC);
+ }
/* pass 9:
* - Optimize temp variables usage
*/
-#include "Optimizer/pass9.c"
+ if (ZEND_OPTIMIZER_PASS_9 & OPTIMIZATION_LEVEL) {
+ optimize_temporary_variables(op_array, ctx);
+ }
/* pass 10:
* - remove NOPs
*/
-#include "Optimizer/pass10.c"
+ if (((ZEND_OPTIMIZER_PASS_10|ZEND_OPTIMIZER_PASS_5) & OPTIMIZATION_LEVEL) == ZEND_OPTIMIZER_PASS_10) {
+ zend_optimizer_nop_removal(op_array);
+ }
/* pass 11:
* - Compact literals table
*/
if (ZEND_OPTIMIZER_PASS_11 & OPTIMIZATION_LEVEL) {
- optimizer_compact_literals(op_array, ctx TSRMLS_CC);
+ zend_optimizer_compact_literals(op_array, ctx TSRMLS_CC);
}
}
@@ -488,7 +467,6 @@ static void zend_accel_optimize(zend_op_array *op_array,
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
case ZEND_NEW:
case ZEND_FE_RESET:
case ZEND_FE_FETCH:
@@ -526,7 +504,6 @@ static void zend_accel_optimize(zend_op_array *op_array,
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
case ZEND_NEW:
case ZEND_FE_RESET:
case ZEND_FE_FETCH:
diff --git a/ext/opcache/Optimizer/zend_optimizer_internal.h b/ext/opcache/Optimizer/zend_optimizer_internal.h
index b0ba12abc7..ac87cf9f35 100644
--- a/ext/opcache/Optimizer/zend_optimizer_internal.h
+++ b/ext/opcache/Optimizer/zend_optimizer_internal.h
@@ -25,7 +25,7 @@
#include "ZendAccelerator.h"
#define VAR_NUM(v) EX_VAR_TO_NUM(v)
-#define NUM_VAR(v) ((zend_uint)(zend_uintptr_t)EX_VAR_NUM_2(0, v))
+#define NUM_VAR(v) ((uint32_t)(zend_uintptr_t)EX_VAR_NUM_2(0, v))
#define INV_COND(op) ((op) == ZEND_JMPZ ? ZEND_JMPNZ : ZEND_JMPZ)
#define INV_EX_COND(op) ((op) == ZEND_JMPZ_EX ? ZEND_JMPNZ : ZEND_JMPZ)
@@ -76,4 +76,58 @@ struct _zend_block_source {
zend_block_source *next;
};
+#define OPTIMIZATION_LEVEL \
+ ZCG(accel_directives).optimization_level
+
+#define LITERAL_LONG(op, val) do { \
+ zval _c; \
+ ZVAL_LONG(&_c, val); \
+ op.constant = zend_optimizer_add_literal(op_array, &_c TSRMLS_CC); \
+ } while (0)
+
+#define LITERAL_BOOL(op, val) do { \
+ zval _c; \
+ ZVAL_BOOL(&_c, val); \
+ op.constant = zend_optimizer_add_literal(op_array, &_c TSRMLS_CC); \
+ } while (0)
+
+#define literal_dtor(zv) do { \
+ zval_dtor(zv); \
+ ZVAL_NULL(zv); \
+ } while (0)
+
+#define COPY_NODE(target, src) do { \
+ target ## _type = src ## _type; \
+ target = src; \
+ } while (0)
+
+int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
+int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy TSRMLS_DC);
+void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value);
+int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value);
+int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name);
+void zend_optimizer_update_op1_const(zend_op_array *op_array,
+ zend_op *opline,
+ zval *val TSRMLS_DC);
+void zend_optimizer_update_op2_const(zend_op_array *op_array,
+ zend_op *opline,
+ zval *val TSRMLS_DC);
+int zend_optimizer_replace_var_by_const(zend_op_array *op_array,
+ zend_op *opline,
+ uint32_t var,
+ zval *val TSRMLS_DC);
+void zend_optimizer_replace_tmp_by_const(zend_op_array *op_array,
+ zend_op *opline,
+ uint32_t var,
+ zval *val TSRMLS_DC);
+
+void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC);
+void zend_optimizer_pass2(zend_op_array *op_array TSRMLS_DC);
+void zend_optimizer_pass3(zend_op_array *op_array TSRMLS_DC);
+void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC);
+void optimize_cfg(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC);
+void optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_ctx *ctx);
+void zend_optimizer_nop_removal(zend_op_array *op_array);
+void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx TSRMLS_DC);
+
#endif
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index ebd3844e38..e210a46210 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -107,8 +107,8 @@ static void (*orig_chdir)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
#ifdef ZEND_WIN32
-# define INCREMENT(v) InterlockedIncrement(&ZCSG(v))
-# define DECREMENT(v) InterlockedDecrement(&ZCSG(v))
+# define INCREMENT(v) InterlockedIncrement64(&ZCSG(v))
+# define DECREMENT(v) InterlockedDecrement64(&ZCSG(v))
# define LOCKVAL(v) (ZCSG(v))
#endif
@@ -192,13 +192,13 @@ void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason T
*/
static ZEND_INI_MH(accel_include_path_on_modify)
{
- int ret = orig_include_path_on_modify(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ int ret = orig_include_path_on_modify(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
ZCG(include_path_key) = NULL;
if (ret == SUCCESS) {
- ZCG(include_path) = new_value;
+ ZCG(include_path) = new_value->val;
if (ZCG(include_path) && *ZCG(include_path)) {
- ZCG(include_path_len) = new_value_length;
+ ZCG(include_path_len) = new_value->len;
if (ZCG(enabled) && accel_startup_ok &&
(ZCG(counted) || ZCSG(accelerator_enabled))) {
@@ -299,7 +299,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
{
/* for now interned strings are supported only for non-ZTS build */
#ifndef ZTS
- ulong h;
+ zend_ulong h;
uint nIndex;
uint idx;
Bucket *p;
@@ -309,7 +309,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
return str;
}
- h = STR_HASH_VAL(str);
+ h = zend_string_hash_val(str);
nIndex = h & ZCSG(interned_strings).nTableMask;
/* check for existing interned string */
@@ -318,7 +318,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
p = ZCSG(interned_strings).arData + idx;
if ((p->h == h) && (p->key->len == str->len)) {
if (!memcmp(p->key->val, str->val, str->len)) {
- STR_RELEASE(str);
+ zend_string_release(str);
return p->key;
}
}
@@ -354,7 +354,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
ZVAL_STR(&p->val, p->key);
Z_NEXT(p->val) = ZCSG(interned_strings).arHash[nIndex];
ZCSG(interned_strings).arHash[nIndex] = idx;
- STR_RELEASE(str);
+ zend_string_release(str);
return p->key;
#else
return str;
@@ -374,7 +374,7 @@ static void accel_use_shm_interned_strings(TSRMLS_D)
char s[2];
s[0] = j;
s[1] = 0;
- CG(one_char_string)[j] = accel_new_interned_string(STR_INIT(s, 1, 0) TSRMLS_CC);
+ CG(one_char_string)[j] = accel_new_interned_string(zend_string_init(s, 1, 0) TSRMLS_CC);
}
/* function table hash keys */
@@ -632,7 +632,7 @@ static inline int accel_is_inactive(TSRMLS_D)
return FAILURE;
}
-static int zend_get_stream_timestamp(const char *filename, struct stat *statbuf TSRMLS_DC)
+static int zend_get_stream_timestamp(const char *filename, zend_stat_t *statbuf TSRMLS_DC)
{
php_stream_wrapper *wrapper;
php_stream_statbuf stream_statbuf;
@@ -715,7 +715,7 @@ static accel_time_t zend_get_file_handle_timestamp_win(zend_file_handle *file_ha
static accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_t *size TSRMLS_DC)
{
- struct stat statbuf;
+ zend_stat_t statbuf;
#ifdef ZEND_WIN32
accel_time_t res;
#endif
@@ -724,7 +724,7 @@ static accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle
!EG(current_execute_data) &&
file_handle->filename == SG(request_info).path_translated) {
- struct stat *tmpbuf = sapi_module.get_stat(TSRMLS_C);
+ zend_stat_t *tmpbuf = sapi_module.get_stat(TSRMLS_C);
if (tmpbuf) {
if (size) {
@@ -743,12 +743,12 @@ static accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle
switch (file_handle->type) {
case ZEND_HANDLE_FD:
- if (fstat(file_handle->handle.fd, &statbuf) == -1) {
+ if (zend_fstat(file_handle->handle.fd, &statbuf) == -1) {
return 0;
}
break;
case ZEND_HANDLE_FP:
- if (fstat(fileno(file_handle->handle.fp), &statbuf) == -1) {
+ if (zend_fstat(fileno(file_handle->handle.fp), &statbuf) == -1) {
if (zend_get_stream_timestamp(file_handle->filename, &statbuf TSRMLS_CC) != SUCCESS) {
return 0;
}
@@ -1268,8 +1268,8 @@ static void zend_accel_init_auto_globals(TSRMLS_D)
int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0]));
for (i = 0; i < ag_size ; i++) {
- jit_auto_globals_str[i] = STR_INIT(jit_auto_globals_info[i].name, jit_auto_globals_info[i].len, 1);
- STR_HASH_VAL(jit_auto_globals_str[i]);
+ jit_auto_globals_str[i] = zend_string_init(jit_auto_globals_info[i].name, jit_auto_globals_info[i].len, 1);
+ zend_string_hash_val(jit_auto_globals_str[i]);
jit_auto_globals_str[i] = accel_new_interned_string(jit_auto_globals_str[i] TSRMLS_CC);
}
}
@@ -1283,7 +1283,7 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
zend_op_array *op_array;
int do_bailout = 0;
accel_time_t timestamp = 0;
- zend_uint orig_compiler_options = 0;
+ uint32_t orig_compiler_options = 0;
/* Try to open file */
if (file_handle->type == ZEND_HANDLE_FILENAME) {
@@ -1427,11 +1427,11 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
}
if (file_handle->opened_path) {
- new_persistent_script->full_path = STR_INIT(file_handle->opened_path, strlen(file_handle->opened_path), 0);
+ new_persistent_script->full_path = zend_string_init(file_handle->opened_path, strlen(file_handle->opened_path), 0);
} else {
- new_persistent_script->full_path = STR_INIT(file_handle->filename, strlen(file_handle->filename), 0);
+ new_persistent_script->full_path = zend_string_init(file_handle->filename, strlen(file_handle->filename), 0);
}
- STR_HASH_VAL(new_persistent_script->full_path);
+ zend_string_hash_val(new_persistent_script->full_path);
/* Now persistent_script structure is ready in process memory */
return cache_script_in_shared_memory(new_persistent_script, key, key_length, from_shared_memory TSRMLS_CC);
@@ -1448,7 +1448,6 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
if (!file_handle->filename ||
!ZCG(enabled) || !accel_startup_ok ||
(!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
- CG(interactive) ||
(ZCSG(restart_in_progress) && accel_restart_is_active(TSRMLS_C)) ||
(is_stream_path(file_handle->filename) &&
!is_cacheable_stream_path(file_handle->filename))) {
@@ -1581,7 +1580,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
/* If script was not found or invalidated by validate_timestamps */
if (!persistent_script) {
- zend_uint old_const_num = zend_hash_next_free_element(EG(zend_constants));
+ uint32_t old_const_num = zend_hash_next_free_element(EG(zend_constants));
zend_op_array *op_array;
/* Cache miss.. */
@@ -1608,7 +1607,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
}
if (from_shared_memory) {
/* Delete immutable arrays moved into SHM */
- zend_uint new_const_num = zend_hash_next_free_element(EG(zend_constants));
+ uint32_t new_const_num = zend_hash_next_free_element(EG(zend_constants));
while (new_const_num > old_const_num) {
new_const_num--;
zend_hash_index_del(EG(zend_constants), new_const_num);
@@ -1620,8 +1619,8 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
ZCSG(hits)++; /* TBFixed: may lose one hit */
persistent_script->dynamic_members.hits++; /* see above */
#else
- InterlockedIncrement(&ZCSG(hits));
- InterlockedIncrement(&persistent_script->dynamic_members.hits);
+ INCREMENT(hits);
+ InterlockedIncrement64(&persistent_script->dynamic_members.hits);
#endif
/* see bug #15471 (old BTS) */
@@ -1667,7 +1666,6 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
{
if (ZCG(enabled) && accel_startup_ok &&
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
- !CG(interactive) &&
!ZCSG(restart_in_progress)) {
/* check if callback is called from include_once or it's a main request */
@@ -1727,7 +1725,6 @@ static char* persistent_zend_resolve_path(const char *filename, int filename_len
{
if (ZCG(enabled) && accel_startup_ok &&
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
- !CG(interactive) &&
!ZCSG(restart_in_progress)) {
/* check if callback is called from include_once or it's a main request */
@@ -1916,6 +1913,7 @@ static void accel_activate(void)
* allocated block separately, but we like to call all the destructors and
* callbacks in exactly the same order.
*/
+static void accel_fast_zval_dtor(zval *zvalue);
static void accel_fast_hash_destroy(HashTable *ht)
{
@@ -1925,7 +1923,7 @@ static void accel_fast_hash_destroy(HashTable *ht)
for (idx = 0; idx < ht->nNumUsed; idx++) {
p = ht->arData + idx;
if (Z_TYPE(p->val) == IS_UNDEF) continue;
- ht->pDestructor(&p->val);
+ accel_fast_zval_dtor(&p->val);
}
}
@@ -1939,7 +1937,6 @@ static void accel_fast_zval_dtor(zval *zvalue)
if (Z_ARR_P(zvalue) != &EG(symbol_table)) {
/* break possible cycles */
ZVAL_NULL(zvalue);
- Z_ARRVAL_P(zvalue)->pDestructor = accel_fast_zval_dtor;
accel_fast_hash_destroy(Z_ARRVAL_P(zvalue));
}
}
@@ -1981,61 +1978,29 @@ static int accel_clean_non_persistent_function(zval *zv TSRMLS_DC)
return ZEND_HASH_APPLY_STOP;
} else {
if (function->op_array.static_variables) {
- function->op_array.static_variables->pDestructor = accel_fast_zval_dtor;
accel_fast_hash_destroy(function->op_array.static_variables);
function->op_array.static_variables = NULL;
}
- return (--(*function->op_array.refcount) <= 0) ?
- ZEND_HASH_APPLY_REMOVE :
- ZEND_HASH_APPLY_KEEP;
- }
-}
-
-static int accel_cleanup_function_data(zval *zv TSRMLS_DC)
-{
- zend_function *function = Z_PTR_P(zv);
-
- if (function->type == ZEND_USER_FUNCTION) {
- if (function->op_array.static_variables) {
- function->op_array.static_variables->pDestructor = accel_fast_zval_dtor;
- accel_fast_hash_destroy(function->op_array.static_variables);
- function->op_array.static_variables = NULL;
- }
- }
- return 0;
-}
-
-static int accel_clean_non_persistent_class(zval *zv TSRMLS_DC)
-{
- zend_class_entry *ce = Z_PTR_P(zv);
-
- if (ce->type == ZEND_INTERNAL_CLASS) {
- return ZEND_HASH_APPLY_STOP;
- } else {
- if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
- zend_hash_apply(&ce->function_table, (apply_func_t) accel_cleanup_function_data TSRMLS_CC);
- }
- if (ce->static_members_table) {
- int i;
-
- for (i = 0; i < ce->default_static_members_count; i++) {
- accel_fast_zval_dtor(&ce->static_members_table[i]);
- ZVAL_UNDEF(&ce->static_members_table[i]);
- }
- ce->static_members_table = NULL;
- }
return ZEND_HASH_APPLY_REMOVE;
}
}
-static int accel_clean_non_persistent_constant(zval *zv TSRMLS_DC)
+static inline void zend_accel_fast_del_bucket(HashTable *ht, uint32_t idx, Bucket *p)
{
- zend_constant *c = Z_PTR_P(zv);
+ uint32_t nIndex = p->h & ht->nTableMask;
+ uint32_t i = ht->arHash[nIndex];
- if (c->flags & CONST_PERSISTENT) {
- return ZEND_HASH_APPLY_STOP;
- } else {
- return ZEND_HASH_APPLY_REMOVE;
+ ht->nNumUsed--;
+ ht->nNumOfElements--;
+ if (idx != i) {
+ Bucket *prev = ht->arData + i;
+ while (Z_NEXT(prev->val) != idx) {
+ i = Z_NEXT(prev->val);
+ prev = ht->arData + i;
+ }
+ Z_NEXT(prev->val) = Z_NEXT(p->val);
+ } else {
+ ht->arHash[p->h & ht->nTableMask] = Z_NEXT(p->val);
}
}
@@ -2057,18 +2022,60 @@ static void zend_accel_fast_shutdown(TSRMLS_D)
EG(symbol_table).ht.pDestructor = old_destructor;
}
zend_hash_init(&EG(symbol_table).ht, 8, NULL, NULL, 0);
- old_destructor = EG(function_table)->pDestructor;
- EG(function_table)->pDestructor = NULL;
- zend_hash_reverse_apply(EG(function_table), (apply_func_t) accel_clean_non_persistent_function TSRMLS_CC);
- EG(function_table)->pDestructor = old_destructor;
- old_destructor = EG(class_table)->pDestructor;
- EG(class_table)->pDestructor = NULL;
- zend_hash_reverse_apply(EG(class_table), (apply_func_t) accel_clean_non_persistent_class TSRMLS_CC);
- EG(class_table)->pDestructor = old_destructor;
- old_destructor = EG(zend_constants)->pDestructor;
- EG(zend_constants)->pDestructor = NULL;
- zend_hash_reverse_apply(EG(zend_constants), (apply_func_t) accel_clean_non_persistent_constant TSRMLS_CC);
- EG(zend_constants)->pDestructor = old_destructor;
+
+ ZEND_HASH_REVERSE_FOREACH(EG(function_table), 0) {
+ zend_function *func = Z_PTR(_p->val);
+
+ if (func->type == ZEND_INTERNAL_FUNCTION) {
+ break;
+ } else {
+ if (func->op_array.static_variables) {
+ accel_fast_hash_destroy(func->op_array.static_variables);
+ }
+ zend_accel_fast_del_bucket(EG(function_table), _idx-1, _p);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ ZEND_HASH_REVERSE_FOREACH(EG(class_table), 0) {
+ zend_class_entry *ce = Z_PTR(_p->val);
+
+ if (ce->type == ZEND_INTERNAL_CLASS) {
+ break;
+ } else {
+ if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
+ zend_function *func;
+
+ ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
+ if (func->type == ZEND_USER_FUNCTION) {
+ if (func->op_array.static_variables) {
+ accel_fast_hash_destroy(func->op_array.static_variables);
+ func->op_array.static_variables = NULL;
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+ if (ce->static_members_table) {
+ int i;
+
+ for (i = 0; i < ce->default_static_members_count; i++) {
+ accel_fast_zval_dtor(&ce->static_members_table[i]);
+ ZVAL_UNDEF(&ce->static_members_table[i]);
+ }
+ ce->static_members_table = NULL;
+ }
+ zend_accel_fast_del_bucket(EG(class_table), _idx-1, _p);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ ZEND_HASH_REVERSE_FOREACH(EG(zend_constants), 0) {
+ zend_constant *c = Z_PTR(_p->val);
+
+ if (c->flags & CONST_PERSISTENT) {
+ break;
+ } else {
+ zend_accel_fast_del_bucket(EG(zend_constants), _idx-1, _p);
+ }
+ } ZEND_HASH_FOREACH_END();
}
CG(unclean_shutdown) = 1;
}
@@ -2185,13 +2192,13 @@ static int zend_accel_init_shm(TSRMLS_D)
if (ZCG(accel_directives).interned_strings_buffer) {
ZCSG(interned_strings).nTableMask = ZCSG(interned_strings).nTableSize - 1;
ZCSG(interned_strings).arData = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket));
- ZCSG(interned_strings).arHash = (zend_uint*)zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(zend_uint));
+ ZCSG(interned_strings).arHash = (uint32_t*)zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(uint32_t));
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
if (!ZCSG(interned_strings).arData || !ZCSG(interned_strings_start)) {
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
return FAILURE;
}
- memset(ZCSG(interned_strings).arHash, INVALID_IDX, ZCSG(interned_strings).nTableSize * sizeof(zend_uint));
+ memset(ZCSG(interned_strings).arHash, INVALID_IDX, ZCSG(interned_strings).nTableSize * sizeof(uint32_t));
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index 94c467e5fb..c3c7285c48 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -157,7 +157,7 @@ typedef struct _zend_persistent_script {
zend_op_array main_op_array;
HashTable function_table;
HashTable class_table;
- long compiler_halt_offset; /* position of __HALT_COMPILER or -1 */
+ zend_long compiler_halt_offset; /* position of __HALT_COMPILER or -1 */
int ping_auto_globals_mask; /* which autoglobals are used by the script */
accel_time_t timestamp; /* the script modification time */
zend_bool corrupted;
@@ -170,7 +170,11 @@ typedef struct _zend_persistent_script {
*/
struct zend_persistent_script_dynamic_members {
time_t last_used;
- ulong hits;
+#ifdef ZEND_WIN32
+ LONGLONG hits;
+#else
+ zend_ulong hits;
+#endif
unsigned int memory_consumption;
unsigned int checksum;
time_t revalidate;
@@ -178,12 +182,12 @@ typedef struct _zend_persistent_script {
} zend_persistent_script;
typedef struct _zend_accel_directives {
- long memory_consumption;
- long max_accelerated_files;
+ zend_long memory_consumption;
+ zend_long max_accelerated_files;
double max_wasted_percentage;
char *user_blacklist_filename;
- long consistency_checks;
- long force_restart_timeout;
+ zend_long consistency_checks;
+ zend_long force_restart_timeout;
zend_bool use_cwd;
zend_bool ignore_dups;
zend_bool validate_timestamps;
@@ -195,18 +199,18 @@ typedef struct _zend_accel_directives {
zend_bool file_override_enabled;
zend_bool inherited_hack;
zend_bool enable_cli;
- unsigned long revalidate_freq;
- unsigned long file_update_protection;
+ zend_ulong revalidate_freq;
+ zend_ulong file_update_protection;
char *error_log;
#ifdef ZEND_WIN32
char *mmap_base;
#endif
char *memory_model;
- long log_verbosity_level;
+ zend_long log_verbosity_level;
- long optimization_level;
- long max_file_size;
- long interned_strings_buffer;
+ zend_long optimization_level;
+ zend_long max_file_size;
+ zend_long interned_strings_buffer;
char *restrict_api;
} zend_accel_directives;
@@ -231,7 +235,7 @@ typedef struct _zend_accel_globals {
/* preallocated shared-memory block to save current script */
void *mem;
/* cache to save hash lookup on the same INCLUDE opcode */
- zend_op *cache_opline;
+ const zend_op *cache_opline;
zend_persistent_script *cache_persistent_script;
/* preallocated buffer for keys */
int key_len;
@@ -240,12 +244,12 @@ typedef struct _zend_accel_globals {
typedef struct _zend_accel_shared_globals {
/* Cache Data Structures */
- unsigned long hits;
- unsigned long misses;
- unsigned long blacklist_misses;
- unsigned long oom_restarts; /* number of restarts because of out of memory */
- unsigned long hash_restarts; /* number of restarts because of hash overflow */
- unsigned long manual_restarts; /* number of restarts scheduled by opcache_reset() */
+ zend_ulong hits;
+ zend_ulong misses;
+ zend_ulong blacklist_misses;
+ zend_ulong oom_restarts; /* number of restarts because of out of memory */
+ zend_ulong hash_restarts; /* number of restarts because of hash overflow */
+ zend_ulong manual_restarts; /* number of restarts scheduled by opcache_reset() */
zend_accel_hash hash; /* hash table for cached scripts */
zend_accel_hash include_paths; /* used "include_path" values */
@@ -258,8 +262,8 @@ typedef struct _zend_accel_shared_globals {
zend_accel_restart_reason restart_reason;
zend_bool cache_status_before_restart;
#ifdef ZEND_WIN32
- unsigned long mem_usage;
- unsigned long restart_in;
+ LONGLONG mem_usage;
+ LONGLONG restart_in;
#endif
zend_bool restart_in_progress;
time_t revalidate_at;
diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
index f6e6ca9444..793105b966 100644
--- a/ext/opcache/config.m4
+++ b/ext/opcache/config.m4
@@ -376,7 +376,15 @@ fi
shared_alloc_shm.c \
shared_alloc_mmap.c \
shared_alloc_posix.c \
- Optimizer/zend_optimizer.c,
+ Optimizer/zend_optimizer.c \
+ Optimizer/pass1_5.c \
+ Optimizer/pass2.c \
+ Optimizer/pass3.c \
+ Optimizer/optimize_func_calls.c \
+ Optimizer/block_pass.c \
+ Optimizer/optimize_temp_vars_5.c \
+ Optimizer/nop_removal.c \
+ Optimizer/compact_literals.c,
shared,,,,yes)
PHP_ADD_BUILD_DIR([$ext_builddir/Optimizer], 1)
diff --git a/ext/opcache/config.w32 b/ext/opcache/config.w32
index af160b207c..9a0713d608 100644
--- a/ext/opcache/config.w32
+++ b/ext/opcache/config.w32
@@ -16,7 +16,7 @@ if (PHP_OPCACHE != "no") {
zend_shared_alloc.c \
shared_alloc_win32.c", true);
- ADD_SOURCES(configure_module_dirname + "/Optimizer", "zend_optimizer.c", "opcache", "OptimizerObj");
+ ADD_SOURCES(configure_module_dirname + "/Optimizer", "zend_optimizer.c pass1_5.c pass2.c pass3.c optimize_func_calls.c block_pass.c optimize_temp_vars_5.c nop_removal.c compact_literals.c", "opcache", "OptimizerObj");
ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname);
diff --git a/ext/opcache/zend_accelerator_debug.c b/ext/opcache/zend_accelerator_debug.c
index d0198dccb3..2a386b812b 100644
--- a/ext/opcache/zend_accelerator_debug.c
+++ b/ext/opcache/zend_accelerator_debug.c
@@ -57,7 +57,7 @@ void zend_accel_error(int type, const char *format, ...)
}
#ifdef ZTS
- fprintf(fLog, "%s (%lu): ", time_string, (unsigned long)tsrm_thread_id());
+ fprintf(fLog, "%s (" ZEND_ULONG_FMT "): ", time_string, (zend_ulong)tsrm_thread_id());
#else
fprintf(fLog, "%s (%d): ", time_string, getpid());
#endif
diff --git a/ext/opcache/zend_accelerator_hash.c b/ext/opcache/zend_accelerator_hash.c
index b75377d61b..671792239b 100644
--- a/ext/opcache/zend_accelerator_hash.c
+++ b/ext/opcache/zend_accelerator_hash.c
@@ -36,7 +36,7 @@ void zend_accel_hash_clean(zend_accel_hash *accel_hash)
memset(accel_hash->hash_table, 0, sizeof(zend_accel_hash_entry *)*accel_hash->max_num_entries);
}
-void zend_accel_hash_init(zend_accel_hash *accel_hash, zend_uint hash_size)
+void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size)
{
uint i;
@@ -71,7 +71,7 @@ void zend_accel_hash_init(zend_accel_hash *accel_hash, zend_uint hash_size)
* Returns pointer the actual hash entry on success
* key needs to be already allocated as it is not copied
*/
-zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char *key, zend_uint key_length, zend_bool indirect, void *data)
+zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char *key, uint32_t key_length, zend_bool indirect, void *data)
{
zend_ulong hash_value;
zend_ulong index;
@@ -140,7 +140,7 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char
/* Returns the data associated with key on success
* Returns NULL if data doesn't exist
*/
-void* zend_accel_hash_find(zend_accel_hash *accel_hash, char *key, zend_uint key_length)
+void* zend_accel_hash_find(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
{
zend_ulong hash_value;
zend_ulong index;
@@ -168,7 +168,7 @@ void* zend_accel_hash_find(zend_accel_hash *accel_hash, char *key, zend_uint key
/* Returns the hash entry associated with key on success
* Returns NULL if it doesn't exist
*/
-zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, char *key, zend_uint key_length)
+zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
{
zend_ulong hash_value;
zend_ulong index;
@@ -193,9 +193,9 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, c
return NULL;
}
-int zend_accel_hash_unlink(zend_accel_hash *accel_hash, char *key, zend_uint key_length)
+int zend_accel_hash_unlink(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
{
- zend_ulong hash_value;
+ zend_ulong hash_value;
zend_ulong index;
zend_accel_hash_entry *entry, *last_entry=NULL;
diff --git a/ext/opcache/zend_accelerator_hash.h b/ext/opcache/zend_accelerator_hash.h
index 2de28bffa7..5c995b43ee 100644
--- a/ext/opcache/zend_accelerator_hash.h
+++ b/ext/opcache/zend_accelerator_hash.h
@@ -47,7 +47,7 @@ typedef struct _zend_accel_hash_entry zend_accel_hash_entry;
struct _zend_accel_hash_entry {
zend_ulong hash_value;
char *key;
- zend_uint key_length;
+ uint32_t key_length;
zend_accel_hash_entry *next;
void *data;
zend_bool indirect;
@@ -56,35 +56,35 @@ struct _zend_accel_hash_entry {
typedef struct _zend_accel_hash {
zend_accel_hash_entry **hash_table;
zend_accel_hash_entry *hash_entries;
- zend_uint num_entries;
- zend_uint max_num_entries;
- zend_uint num_direct_entries;
+ uint32_t num_entries;
+ uint32_t max_num_entries;
+ uint32_t num_direct_entries;
} zend_accel_hash;
-void zend_accel_hash_init(zend_accel_hash *accel_hash, zend_uint hash_size);
+void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size);
void zend_accel_hash_clean(zend_accel_hash *accel_hash);
zend_accel_hash_entry* zend_accel_hash_update(
zend_accel_hash *accel_hash,
char *key,
- zend_uint key_length,
+ uint32_t key_length,
zend_bool indirect,
void *data);
void* zend_accel_hash_find(
zend_accel_hash *accel_hash,
char *key,
- zend_uint key_length);
+ uint32_t key_length);
zend_accel_hash_entry* zend_accel_hash_find_entry(
zend_accel_hash *accel_hash,
char *key,
- zend_uint key_length);
+ uint32_t key_length);
int zend_accel_hash_unlink(
zend_accel_hash *accel_hash,
char *key,
- zend_uint key_length);
+ uint32_t key_length);
static inline zend_bool zend_accel_hash_is_full(zend_accel_hash *accel_hash)
{
diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c
index ff8ace863b..001c3ee9ed 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -100,8 +100,8 @@ static int validate_api_restriction(TSRMLS_D)
static ZEND_INI_MH(OnUpdateMemoryConsumption)
{
- long *p;
- long memsize;
+ zend_long *p;
+ zend_long memsize;
#ifndef ZTS
char *base = (char *) mh_arg2;
#else
@@ -109,10 +109,10 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
#endif
/* keep the compiler happy */
- (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
+ (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
- p = (long *) (base + (size_t)mh_arg1);
- memsize = atoi(new_value);
+ p = (zend_long *) (base + (size_t)mh_arg1);
+ memsize = atoi(new_value->val);
/* sanity check we must use at least 8 MB */
if (memsize < 8) {
const char *new_new_value = "8";
@@ -128,8 +128,7 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
return FAILURE;
}
- ini_entry->value = strdup(new_new_value);
- ini_entry->value_length = strlen(new_new_value);
+ ini_entry->value = zend_string_init(new_new_value, 1, 1);
}
*p = memsize * (1024 * 1024);
return SUCCESS;
@@ -137,8 +136,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
{
- long *p;
- long size;
+ zend_long *p;
+ zend_long size;
#ifndef ZTS
char *base = (char *) mh_arg2;
#else
@@ -146,10 +145,10 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
#endif
/* keep the compiler happy */
- (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
+ (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
- p = (long *) (base + (size_t)mh_arg1);
- size = atoi(new_value);
+ p = (zend_long *) (base + (size_t)mh_arg1);
+ size = atoi(new_value->val);
/* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) {
@@ -173,8 +172,7 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
sizeof("opcache.max_accelerated_files")-1)) == NULL) {
return FAILURE;
}
- ini_entry->value = strdup(new_new_value);
- ini_entry->value_length = strlen(new_new_value);
+ ini_entry->value = zend_string_init(new_new_value, strlen(new_new_value), 1);
}
*p = size;
return SUCCESS;
@@ -183,7 +181,7 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
{
double *p;
- long percentage;
+ zend_long percentage;
#ifndef ZTS
char *base = (char *) mh_arg2;
#else
@@ -191,10 +189,10 @@ static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
#endif
/* keep the compiler happy */
- (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
+ (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
p = (double *) (base + (size_t)mh_arg1);
- percentage = atoi(new_value);
+ percentage = atoi(new_value->val);
if (percentage <= 0 || percentage > 50) {
const char *new_new_value = "5";
@@ -208,8 +206,7 @@ static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
sizeof("opcache.max_wasted_percentage")-1)) == NULL) {
return FAILURE;
}
- ini_entry->value = strdup(new_new_value);
- ini_entry->value_length = strlen(new_new_value);
+ ini_entry->value = zend_string_init(new_new_value, strlen(new_new_value), 1);
}
*p = (double)percentage / 100.0;
return SUCCESS;
@@ -220,7 +217,7 @@ static ZEND_INI_MH(OnEnable)
if (stage == ZEND_INI_STAGE_STARTUP ||
stage == ZEND_INI_STAGE_SHUTDOWN ||
stage == ZEND_INI_STAGE_DEACTIVATE) {
- return OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+ return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
} else {
/* It may be only temporary disabled */
zend_bool *p;
@@ -231,10 +228,10 @@ static ZEND_INI_MH(OnEnable)
#endif
p = (zend_bool *) (base+(size_t) mh_arg1);
- if ((new_value_length == 2 && strcasecmp("on", new_value) == 0) ||
- (new_value_length == 3 && strcasecmp("yes", new_value) == 0) ||
- (new_value_length == 4 && strcasecmp("true", new_value) == 0) ||
- atoi(new_value) != 0) {
+ if ((new_value->len == 2 && strcasecmp("on", new_value->val) == 0) ||
+ (new_value->len == 3 && strcasecmp("yes", new_value->val) == 0) ||
+ (new_value->len == 4 && strcasecmp("true", new_value->val) == 0) ||
+ atoi(new_value->val) != 0) {
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
return FAILURE;
} else {
@@ -407,33 +404,33 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
char buf[32];
php_info_print_table_row(2, "Startup", "OK");
php_info_print_table_row(2, "Shared memory model", zend_accel_get_shared_model());
- snprintf(buf, sizeof(buf), "%ld", ZCSG(hits));
+ snprintf(buf, sizeof(buf), "%pd", (zend_ulong)ZCSG(hits));
php_info_print_table_row(2, "Cache hits", buf);
- snprintf(buf, sizeof(buf), "%ld", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses));
+ snprintf(buf, sizeof(buf), "%pd", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses));
php_info_print_table_row(2, "Cache misses", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory));
+ snprintf(buf, sizeof(buf), ZEND_LONG_FMT, ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory));
php_info_print_table_row(2, "Used memory", buf);
- snprintf(buf, sizeof(buf), "%ld", zend_shared_alloc_get_free_memory());
+ snprintf(buf, sizeof(buf), "%pd", zend_shared_alloc_get_free_memory());
php_info_print_table_row(2, "Free memory", buf);
- snprintf(buf, sizeof(buf), "%ld", ZSMMG(wasted_shared_memory));
+ snprintf(buf, sizeof(buf), "%pd", ZSMMG(wasted_shared_memory));
php_info_print_table_row(2, "Wasted memory", buf);
if (ZCSG(interned_strings_start) && ZCSG(interned_strings_end) && ZCSG(interned_strings_top)) {
- snprintf(buf, sizeof(buf), "%ld", ZCSG(interned_strings_top) - ZCSG(interned_strings_start));
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(interned_strings_top) - ZCSG(interned_strings_start));
php_info_print_table_row(2, "Interned Strings Used memory", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCSG(interned_strings_end) - ZCSG(interned_strings_top));
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(interned_strings_end) - ZCSG(interned_strings_top));
php_info_print_table_row(2, "Interned Strings Free memory", buf);
}
snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).num_direct_entries);
php_info_print_table_row(2, "Cached scripts", buf);
snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).num_entries);
php_info_print_table_row(2, "Cached keys", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).max_num_entries);
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(hash).max_num_entries);
php_info_print_table_row(2, "Max keys", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCSG(oom_restarts));
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(oom_restarts));
php_info_print_table_row(2, "OOM restarts", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCSG(hash_restarts));
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(hash_restarts));
php_info_print_table_row(2, "Hash keys restarts", buf);
- snprintf(buf, sizeof(buf), "%ld", ZCSG(manual_restarts));
+ snprintf(buf, sizeof(buf), "%pd", ZCSG(manual_restarts));
php_info_print_table_row(2, "Manual restarts", buf);
}
}
@@ -487,8 +484,8 @@ static int accelerator_get_scripts(zval *return_value TSRMLS_DC)
script = (zend_persistent_script *)cache_entry->data;
array_init(&persistent_script_report);
- add_assoc_str(&persistent_script_report, "full_path", STR_DUP(script->full_path, 0));
- add_assoc_long(&persistent_script_report, "hits", script->dynamic_members.hits);
+ add_assoc_str(&persistent_script_report, "full_path", zend_string_dup(script->full_path, 0));
+ add_assoc_long(&persistent_script_report, "hits", (zend_long)script->dynamic_members.hits);
add_assoc_long(&persistent_script_report, "memory_consumption", script->dynamic_members.memory_consumption);
ta = localtime(&script->dynamic_members.last_used);
str = asctime(ta);
@@ -497,7 +494,7 @@ static int accelerator_get_scripts(zval *return_value TSRMLS_DC)
add_assoc_stringl(&persistent_script_report, "last_used", str, len);
add_assoc_long(&persistent_script_report, "last_used_timestamp", script->dynamic_members.last_used);
if (ZCG(accel_directives).validate_timestamps) {
- add_assoc_long(&persistent_script_report, "timestamp", (long)script->timestamp);
+ add_assoc_long(&persistent_script_report, "timestamp", (zend_long)script->timestamp);
}
timerclear(&exec_time);
timerclear(&fetch_time);
@@ -514,7 +511,7 @@ static int accelerator_get_scripts(zval *return_value TSRMLS_DC)
Obtain statistics information regarding code acceleration */
static ZEND_FUNCTION(opcache_get_status)
{
- long reqs;
+ zend_long reqs;
zval memory_usage, statistics, scripts;
zend_bool fetch_scripts = 1;
@@ -562,7 +559,7 @@ static ZEND_FUNCTION(opcache_get_status)
add_assoc_long(&statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries);
add_assoc_long(&statistics, "num_cached_keys", ZCSG(hash).num_entries);
add_assoc_long(&statistics, "max_cached_keys", ZCSG(hash).max_num_entries);
- add_assoc_long(&statistics, "hits", ZCSG(hits));
+ add_assoc_long(&statistics, "hits", (zend_long)ZCSG(hits));
add_assoc_long(&statistics, "start_time", ZCSG(start_time));
add_assoc_long(&statistics, "last_restart_time", ZCSG(last_restart_time));
add_assoc_long(&statistics, "oom_restarts", ZCSG(oom_restarts));
@@ -674,7 +671,7 @@ static ZEND_FUNCTION(opcache_reset)
static ZEND_FUNCTION(opcache_invalidate)
{
char *script_name;
- int script_name_len;
+ size_t script_name_len;
zend_bool force = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &script_name, &script_name_len, &force) == FAILURE) {
@@ -695,7 +692,7 @@ static ZEND_FUNCTION(opcache_invalidate)
static ZEND_FUNCTION(opcache_compile_file)
{
char *script_name;
- int script_name_len;
+ size_t script_name_len;
zend_file_handle handle;
zend_op_array *op_array = NULL;
zend_execute_data *orig_execute_data = NULL;
@@ -738,7 +735,7 @@ static ZEND_FUNCTION(opcache_compile_file)
static ZEND_FUNCTION(opcache_is_script_cached)
{
char *script_name;
- int script_name_len;
+ size_t script_name_len;
if (!validate_api_restriction(TSRMLS_C)) {
RETURN_FALSE;
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index fc16fbeb24..e04b1ec7db 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -27,21 +27,21 @@
#define ZEND_PROTECTED_REFCOUNT (1<<30)
-static zend_uint zend_accel_refcount = ZEND_PROTECTED_REFCOUNT;
+static uint32_t zend_accel_refcount = ZEND_PROTECTED_REFCOUNT;
-#if SIZEOF_SIZE_T <= SIZEOF_LONG
+#if SIZEOF_SIZE_T <= SIZEOF_ZEND_LONG
/* If sizeof(void*) == sizeof(ulong) we can use zend_hash index functions */
-# define accel_xlat_set(old, new) zend_hash_index_update_ptr(&ZCG(bind_hash), (ulong)(zend_uintptr_t)(old), (new))
-# define accel_xlat_get(old) zend_hash_index_find_ptr(&ZCG(bind_hash), (ulong)(zend_uintptr_t)(old))
+# define accel_xlat_set(old, new) zend_hash_index_update_ptr(&ZCG(bind_hash), (zend_ulong)(zend_uintptr_t)(old), (new))
+# define accel_xlat_get(old) zend_hash_index_find_ptr(&ZCG(bind_hash), (zend_ulong)(zend_uintptr_t)(old))
#else
-# define accel_xlat_set(old, new) (zend_hash_str_add_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (ulong)(zend_uintptr_t)(old), (void**)&(new))
-# define accel_xlat_get(old, new) ((new) = zend_hash_str_find_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (ulong)(zend_uintptr_t)(old), (void**)&(new)))
+# define accel_xlat_set(old, new) (zend_hash_str_add_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (zend_ulong)(zend_uintptr_t)(old), (void**)&(new))
+# define accel_xlat_get(old, new) ((new) = zend_hash_str_find_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (zend_ulong)(zend_uintptr_t)(old), (void**)&(new)))
#endif
typedef int (*id_function_t)(void *, void *);
typedef void (*unique_copy_ctor_func_t)(void *pElement);
-static const zend_uint uninitialized_bucket = {INVALID_IDX};
+static const uint32_t uninitialized_bucket = {INVALID_IDX};
static int zend_prepare_function_for_execution(zend_op_array *op_array);
static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind);
@@ -113,7 +113,7 @@ static int compact_hash_table(HashTable *ht)
return 1;
}
- d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(zend_uint)), ht->u.flags & HASH_FLAG_PERSISTENT);
+ d = (Bucket *)pemalloc(nSize * (sizeof(Bucket) + sizeof(uint32_t)), ht->u.flags & HASH_FLAG_PERSISTENT);
if (!d) {
return 0;
}
@@ -129,7 +129,7 @@ static int compact_hash_table(HashTable *ht)
pefree(ht->arData, ht->u.flags & HASH_FLAG_PERSISTENT);
ht->arData = d;
- ht->arHash = (zend_uint *)(d + nSize);
+ ht->arHash = (uint32_t *)(d + nSize);
ht->nTableSize = nSize;
ht->nTableMask = ht->nTableSize - 1;
zend_hash_rehash(ht);
@@ -220,9 +220,9 @@ static void zend_destroy_property_info(zval *zv)
{
zend_property_info *property_info = Z_PTR_P(zv);
- STR_RELEASE(property_info->name);
+ zend_string_release(property_info->name);
if (property_info->doc_comment) {
- STR_RELEASE(property_info->doc_comment);
+ zend_string_release(property_info->doc_comment);
}
}
@@ -232,14 +232,14 @@ static inline zend_string *zend_clone_str(zend_string *str TSRMLS_DC)
if (IS_INTERNED(str)) {
ret = str;
- } else if (STR_REFCOUNT(str) <= 1 || (ret = accel_xlat_get(str)) == NULL) {
- ret = STR_DUP(str, 0);
+ } else if (zend_string_refcount(str) <= 1 || (ret = accel_xlat_get(str)) == NULL) {
+ ret = zend_string_dup(str, 0);
GC_FLAGS(ret) = GC_FLAGS(str);
- if (STR_REFCOUNT(str) > 1) {
+ if (zend_string_refcount(str) > 1) {
accel_xlat_set(str, ret);
}
} else {
- STR_ADDREF(ret);
+ zend_string_addref(ret);
}
return ret;
}
@@ -305,35 +305,51 @@ static inline void zend_clone_zval(zval *src, int bind TSRMLS_DC)
static zend_ast *zend_ast_clone(zend_ast *ast TSRMLS_DC)
{
- int i;
- zend_ast *node;
-
- if (ast->kind == ZEND_CONST) {
- node = emalloc(sizeof(zend_ast) + sizeof(zval));
- node->kind = ZEND_CONST;
- node->children = 0;
- ZVAL_COPY_VALUE(&node->u.val, &ast->u.val);
- zend_clone_zval(&node->u.val, 0 TSRMLS_CC);
+ uint32_t i;
+
+ if (ast->kind == ZEND_AST_ZVAL) {
+ zend_ast_zval *copy = emalloc(sizeof(zend_ast_zval));
+ copy->kind = ZEND_AST_ZVAL;
+ copy->attr = ast->attr;
+ ZVAL_COPY_VALUE(&copy->val, zend_ast_get_zval(ast));
+ zend_clone_zval(&copy->val, 0 TSRMLS_CC);
+ return (zend_ast *) copy;
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ zend_ast_list *copy = emalloc(
+ sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
+ copy->kind = list->kind;
+ copy->attr = list->attr;
+ copy->children = list->children;
+ for (i = 0; i < list->children; i++) {
+ if (list->child[i]) {
+ copy->child[i] = zend_ast_clone(list->child[i] TSRMLS_CC);
+ } else {
+ copy->child[i] = NULL;
+ }
+ }
+ return (zend_ast *) copy;
} else {
- node = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- node->kind = ast->kind;
- node->children = ast->children;
- for (i = 0; i < ast->children; i++) {
- if ((&ast->u.child)[i]) {
- (&node->u.child)[i] = zend_ast_clone((&ast->u.child)[i] TSRMLS_CC);
+ uint32_t children = zend_ast_get_num_children(ast);
+ zend_ast *copy = emalloc(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
+ copy->kind = ast->kind;
+ copy->attr = ast->attr;
+ for (i = 0; i < children; i++) {
+ if (ast->child[i]) {
+ copy->child[i] = zend_ast_clone(ast->child[i] TSRMLS_CC);
} else {
- (&node->u.child)[i] = NULL;
+ copy->child[i] = NULL;
}
}
+ return copy;
}
- return node;
}
static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind)
{
uint idx;
Bucket *p, *q, *r;
- ulong nIndex;
+ zend_ulong nIndex;
TSRMLS_FETCH();
ht->nTableSize = source->nTableSize;
@@ -348,14 +364,14 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind)
ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX;
if (!ht->nTableMask) {
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
return;
}
if (source->u.flags & HASH_FLAG_PACKED) {
ht->u.flags |= HASH_FLAG_PACKED;
ht->arData = (Bucket *) emalloc(ht->nTableSize * sizeof(Bucket));
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
for (idx = 0; idx < source->nNumUsed; idx++) {
p = source->arData + idx;
@@ -379,9 +395,9 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind)
zend_clone_zval(&q->val, bind TSRMLS_CC);
}
} else {
- ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(zend_uint)));
- ht->arHash = (zend_uint*)(ht->arData + ht->nTableSize);
- memset(ht->arHash, INVALID_IDX, sizeof(zend_uint) * ht->nTableSize);
+ ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(uint32_t)));
+ ht->arHash = (uint32_t*)(ht->arData + ht->nTableSize);
+ memset(ht->arHash, INVALID_IDX, sizeof(uint32_t) * ht->nTableSize);
for (idx = 0; idx < source->nNumUsed; idx++) {
p = source->arData + idx;
@@ -412,7 +428,7 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class
{
uint idx;
Bucket *p, *q;
- ulong nIndex;
+ zend_ulong nIndex;
zend_class_entry *new_ce;
zend_function *new_prototype;
zend_op_array *new_entry;
@@ -427,14 +443,14 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class
ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX;
if (!ht->nTableMask) {
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
return;
}
ZEND_ASSERT(!(source->u.flags & HASH_FLAG_PACKED));
- ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(zend_uint)));
- ht->arHash = (zend_uint *)(ht->arData + ht->nTableSize);
- memset(ht->arHash, INVALID_IDX, sizeof(zend_uint) * ht->nTableSize);
+ ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(uint32_t)));
+ ht->arHash = (uint32_t *)(ht->arData + ht->nTableSize);
+ memset(ht->arHash, INVALID_IDX, sizeof(uint32_t) * ht->nTableSize);
for (idx = 0; idx < source->nNumUsed; idx++) {
p = source->arData + idx;
@@ -490,7 +506,7 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla
{
uint idx;
Bucket *p, *q;
- ulong nIndex;
+ zend_ulong nIndex;
zend_class_entry *new_ce;
zend_property_info *prop_info;
@@ -504,14 +520,14 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla
ht->nInternalPointer = source->nNumOfElements ? 0 : INVALID_IDX;
if (!ht->nTableMask) {
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
return;
}
ZEND_ASSERT(!(source->u.flags & HASH_FLAG_PACKED));
- ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(zend_uint)));
- ht->arHash = (zend_uint*)(ht->arData + ht->nTableSize);
- memset(ht->arHash, INVALID_IDX, sizeof(zend_uint) * ht->nTableSize);
+ ht->arData = (Bucket *) emalloc(ht->nTableSize * (sizeof(Bucket) + sizeof(uint32_t)));
+ ht->arHash = (uint32_t*)(ht->arData + ht->nTableSize);
+ memset(ht->arHash, INVALID_IDX, sizeof(uint32_t) * ht->nTableSize);
for (idx = 0; idx < source->nNumUsed; idx++) {
p = source->arData + idx;
@@ -538,7 +554,7 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla
prop_info->name = zend_clone_str(prop_info->name TSRMLS_CC);
if (prop_info->doc_comment) {
if (ZCG(accel_directives).load_comments) {
- prop_info->doc_comment = STR_DUP(prop_info->doc_comment, 0);
+ prop_info->doc_comment = zend_string_dup(prop_info->doc_comment, 0);
} else {
prop_info->doc_comment = NULL;
}
@@ -642,7 +658,7 @@ static void zend_class_copy_ctor(zend_class_entry **pce)
}
if (ZEND_CE_DOC_COMMENT(ce)) {
if (ZCG(accel_directives).load_comments) {
- ZEND_CE_DOC_COMMENT(ce) = STR_DUP(ZEND_CE_DOC_COMMENT(ce), 0);
+ ZEND_CE_DOC_COMMENT(ce) = zend_string_dup(ZEND_CE_DOC_COMMENT(ce), 0);
} else {
ZEND_CE_DOC_COMMENT(ce) = NULL;
}
@@ -885,7 +901,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
if (!zend_hash_exists(EG(zend_constants), name)) {
zend_register_long_constant(name->val, name->len, persistent_script->compiler_halt_offset, CONST_CS, 0 TSRMLS_CC);
}
- STR_RELEASE(name);
+ zend_string_release(name);
}
zend_hash_destroy(&ZCG(bind_hash));
@@ -898,7 +914,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
}
}
- if (op_array->early_binding != (zend_uint)-1) {
+ if (op_array->early_binding != (uint32_t)-1) {
zend_string *orig_compiled_filename = CG(compiled_filename);
CG(compiled_filename) = persistent_script->full_path;
zend_do_delayed_early_binding(op_array TSRMLS_CC);
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index e87a942bfa..05fbd4fc75 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -36,19 +36,19 @@
#define zend_accel_store_string(str) do { \
zend_string *new_str = zend_shared_alloc_get_xlat_entry(str); \
if (new_str) { \
- STR_RELEASE(str); \
+ zend_string_release(str); \
str = new_str; \
} else { \
new_str = zend_accel_memdup((void*)str, _STR_HEADER_SIZE + (str)->len + 1); \
- STR_RELEASE(str); \
+ zend_string_release(str); \
str = new_str; \
- STR_HASH_VAL(str); \
+ zend_string_hash_val(str); \
GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
} \
} while (0)
#define zend_accel_memdup_string(str) do { \
str = zend_accel_memdup(str, _STR_HEADER_SIZE + (str)->len + 1); \
- STR_HASH_VAL(str); \
+ zend_string_hash_val(str); \
GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
} while (0)
#define zend_accel_store_interned_string(str) do { \
@@ -67,7 +67,7 @@ typedef void (*zend_persist_func_t)(zval* TSRMLS_DC);
static void zend_persist_zval(zval *z TSRMLS_DC);
static void zend_persist_zval_const(zval *z TSRMLS_DC);
-static const zend_uint uninitialized_bucket = {INVALID_IDX};
+static const uint32_t uninitialized_bucket = {INVALID_IDX};
static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement TSRMLS_DC)
{
@@ -75,19 +75,19 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
Bucket *p;
if (!ht->nTableMask) {
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
return;
}
if (ht->u.flags & HASH_FLAG_PACKED) {
zend_accel_store(ht->arData, sizeof(Bucket) * ht->nNumUsed);
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
} else {
Bucket *d = (Bucket*)ZCG(mem);
- zend_uint *h = (zend_uint*)(d + ht->nNumUsed);
+ uint32_t *h = (uint32_t*)(d + ht->nNumUsed);
ZCG(mem) = (void*)(h + ht->nTableSize);
memcpy(d, ht->arData, sizeof(Bucket) * ht->nNumUsed);
- memcpy(h, ht->arHash, sizeof(zend_uint) * ht->nTableSize);
+ memcpy(h, ht->arHash, sizeof(uint32_t) * ht->nTableSize);
efree(ht->arData);
ht->arData = d;
ht->arHash = h;
@@ -112,19 +112,19 @@ static void zend_hash_persist_immutable(HashTable *ht TSRMLS_DC)
Bucket *p;
if (!ht->nTableMask) {
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
return;
}
if (ht->u.flags & HASH_FLAG_PACKED) {
ht->arData = zend_accel_memdup(ht->arData, sizeof(Bucket) * ht->nNumUsed);
- ht->arHash = (zend_uint*)&uninitialized_bucket;
+ ht->arHash = (uint32_t*)&uninitialized_bucket;
} else {
Bucket *d = (Bucket*)ZCG(mem);
- zend_uint *h = (zend_uint*)(d + ht->nNumUsed);
+ uint32_t *h = (uint32_t*)(d + ht->nNumUsed);
ZCG(mem) = (void*)(h + ht->nTableSize);
memcpy(d, ht->arData, sizeof(Bucket) * ht->nNumUsed);
- memcpy(h, ht->arHash, sizeof(zend_uint) * ht->nTableSize);
+ memcpy(h, ht->arHash, sizeof(uint32_t) * ht->nTableSize);
ht->arData = d;
ht->arHash = h;
}
@@ -144,20 +144,33 @@ static void zend_hash_persist_immutable(HashTable *ht TSRMLS_DC)
static zend_ast *zend_persist_ast(zend_ast *ast TSRMLS_DC)
{
- int i;
+ uint32_t i;
zend_ast *node;
- if (ast->kind == ZEND_CONST) {
- node = zend_accel_memdup(ast, sizeof(zend_ast));
- zend_persist_zval(&node->u.val TSRMLS_CC);
+ if (ast->kind == ZEND_AST_ZVAL) {
+ zend_ast_zval *copy = zend_accel_memdup(ast, sizeof(zend_ast_zval));
+ zend_persist_zval(&copy->val TSRMLS_CC);
+ node = (zend_ast *) copy;
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ zend_ast_list *copy = zend_accel_memdup(ast,
+ sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
+ for (i = 0; i < list->children; i++) {
+ if (copy->child[i]) {
+ copy->child[i] = zend_persist_ast(copy->child[i] TSRMLS_CC);
+ }
+ }
+ node = (zend_ast *) copy;
} else {
- node = zend_accel_memdup(ast, sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- for (i = 0; i < ast->children; i++) {
- if ((&node->u.child)[i]) {
- (&node->u.child)[i] = zend_persist_ast((&node->u.child)[i] TSRMLS_CC);
+ uint32_t children = zend_ast_get_num_children(ast);
+ node = zend_accel_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
+ for (i = 0; i < children; i++) {
+ if (node->child[i]) {
+ node->child[i] = zend_persist_ast(node->child[i] TSRMLS_CC);
}
}
}
+
efree(ast);
return node;
}
@@ -185,6 +198,7 @@ static void zend_persist_zval(zval *z TSRMLS_DC)
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
zend_hash_persist_immutable(Z_ARRVAL_P(z) TSRMLS_CC);
} else {
+ GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval TSRMLS_CC);
/* make immutable array */
@@ -238,6 +252,7 @@ static void zend_persist_zval_const(zval *z TSRMLS_DC)
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
zend_hash_persist_immutable(Z_ARRVAL_P(z) TSRMLS_CC);
} else {
+ GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval TSRMLS_CC);
/* make immutable array */
@@ -358,7 +373,6 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
case ZEND_NEW:
case ZEND_FE_RESET:
case ZEND_FE_FETCH:
@@ -399,7 +413,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
ZEND_ASSERT(new_ptr != NULL);
op_array->arg_info = new_ptr;
} else {
- zend_uint i;
+ uint32_t i;
zend_accel_store(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
for (i = 0; i < op_array->num_args; i++) {
@@ -433,7 +447,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
}
} else {
if (!already_stored) {
- STR_RELEASE(op_array->doc_comment);
+ zend_string_release(op_array->doc_comment);
}
op_array->doc_comment = NULL;
}
@@ -488,7 +502,7 @@ static void zend_persist_property_info(zval *zv TSRMLS_DC)
if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
}
- STR_RELEASE(prop->doc_comment);
+ zend_string_release(prop->doc_comment);
prop->doc_comment = NULL;
}
}
@@ -532,7 +546,7 @@ static void zend_persist_class_entry(zval *zv TSRMLS_DC)
} else {
if (!zend_shared_alloc_get_xlat_entry(ZEND_CE_DOC_COMMENT(ce))) {
zend_shared_alloc_register_xlat_entry(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT(ce));
- STR_RELEASE(ZEND_CE_DOC_COMMENT(ce));
+ zend_string_release(ZEND_CE_DOC_COMMENT(ce));
}
ZEND_CE_DOC_COMMENT(ce) = NULL;
}
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 08e9211350..76d1b043b0 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -38,7 +38,7 @@
zend_string *tmp = accel_new_interned_string(str TSRMLS_CC); \
if (tmp != (str)) { \
if (do_free) { \
- /*STR_RELEASE(str);*/ \
+ /*zend_string_release(str);*/ \
} \
(str) = tmp; \
} else { \
@@ -61,7 +61,7 @@ static uint zend_hash_persist_calc(HashTable *ht, uint (*pPersistElement)(zval *
if (ht->u.flags & HASH_FLAG_PACKED) {
ADD_SIZE(sizeof(Bucket) * ht->nNumUsed);
} else {
- ADD_SIZE(sizeof(Bucket) * ht->nNumUsed + sizeof(zend_uint) * ht->nTableSize);
+ ADD_SIZE(sizeof(Bucket) * ht->nNumUsed + sizeof(uint32_t) * ht->nTableSize);
}
for (idx = 0; idx < ht->nNumUsed; idx++) {
@@ -83,17 +83,26 @@ static uint zend_hash_persist_calc(HashTable *ht, uint (*pPersistElement)(zval *
static uint zend_persist_ast_calc(zend_ast *ast TSRMLS_DC)
{
- int i;
+ uint32_t i;
START_SIZE();
- if (ast->kind == ZEND_CONST) {
- ADD_SIZE(sizeof(zend_ast));
- ADD_SIZE(zend_persist_zval_calc(&ast->u.val TSRMLS_CC));
+ if (ast->kind == ZEND_AST_ZVAL) {
+ ADD_SIZE(sizeof(zend_ast_zval));
+ ADD_SIZE(zend_persist_zval_calc(zend_ast_get_zval(ast) TSRMLS_CC));
+ } else if (zend_ast_is_list(ast)) {
+ zend_ast_list *list = zend_ast_get_list(ast);
+ ADD_SIZE(sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
+ for (i = 0; i < list->children; i++) {
+ if (list->child[i]) {
+ ADD_SIZE(zend_persist_ast_calc(list->child[i] TSRMLS_CC));
+ }
+ }
} else {
- ADD_SIZE(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
- for (i = 0; i < ast->children; i++) {
- if ((&ast->u.child)[i]) {
- ADD_SIZE(zend_persist_ast_calc((&ast->u.child)[i] TSRMLS_CC));
+ uint32_t children = zend_ast_get_num_children(ast);
+ ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
+ for (i = 0; i < children; i++) {
+ if (ast->child[i]) {
+ ADD_SIZE(zend_persist_ast_calc(ast->child[i] TSRMLS_CC));
}
}
}
@@ -194,7 +203,7 @@ static uint zend_persist_op_array_calc_ex(zend_op_array *op_array TSRMLS_DC)
}
if (op_array->arg_info) {
- zend_uint i;
+ uint32_t i;
ADD_DUP_SIZE(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
for (i = 0; i < op_array->num_args; i++) {
diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c
index 0faabee8b2..981829f5b7 100644
--- a/ext/opcache/zend_shared_alloc.c
+++ b/ext/opcache/zend_shared_alloc.c
@@ -288,7 +288,7 @@ static size_t zend_shared_alloc_get_largest_free_block(void)
#define MIN_FREE_MEMORY 64*1024
#define SHARED_ALLOC_FAILED() do { \
- zend_accel_error(ACCEL_LOG_WARNING, "Not enough free shared space to allocate %ld bytes (%ld bytes free)", (long)size, (long)ZSMMG(shared_free)); \
+ zend_accel_error(ACCEL_LOG_WARNING, "Not enough free shared space to allocate %pd bytes (%pd bytes free)", (zend_long)size, (zend_long)ZSMMG(shared_free)); \
if (zend_shared_alloc_get_largest_free_block() < MIN_FREE_MEMORY) { \
ZSMMG(memory_exhausted) = 1; \
} \
@@ -327,7 +327,7 @@ int zend_shared_memdup_size(void *source, size_t size)
{
void *old_p;
- if ((old_p = zend_hash_index_find_ptr(&xlat_table, (ulong)source)) != NULL) {
+ if ((old_p = zend_hash_index_find_ptr(&xlat_table, (zend_ulong)source)) != NULL) {
/* we already duplicated this pointer */
return 0;
}
@@ -339,7 +339,7 @@ void *_zend_shared_memdup(void *source, size_t size, zend_bool free_source TSRML
{
void *old_p, *retval;
- if ((old_p = zend_hash_index_find_ptr(&xlat_table, (ulong)source)) != NULL) {
+ if ((old_p = zend_hash_index_find_ptr(&xlat_table, (zend_ulong)source)) != NULL) {
/* we already duplicated this pointer */
return old_p;
}
@@ -431,14 +431,14 @@ void zend_shared_alloc_clear_xlat_table(void)
void zend_shared_alloc_register_xlat_entry(const void *old, const void *new)
{
- zend_hash_index_update_ptr(&xlat_table, (ulong)old, (void*)new);
+ zend_hash_index_update_ptr(&xlat_table, (zend_ulong)old, (void*)new);
}
void *zend_shared_alloc_get_xlat_entry(const void *old)
{
void *retval;
- if ((retval = zend_hash_index_find_ptr(&xlat_table, (ulong)old)) == NULL) {
+ if ((retval = zend_hash_index_find_ptr(&xlat_table, (zend_ulong)old)) == NULL) {
return NULL;
}
return retval;
diff --git a/ext/opcache/zend_shared_alloc.h b/ext/opcache/zend_shared_alloc.h
index 57ea8d3fdd..ec7cc14d07 100644
--- a/ext/opcache/zend_shared_alloc.h
+++ b/ext/opcache/zend_shared_alloc.h
@@ -130,7 +130,7 @@ int zend_shared_memdup_size(void *p, size_t size);
typedef union _align_test {
void *ptr;
double dbl;
- long lng;
+ zend_long lng;
} align_test;
#if ZEND_GCC_VERSION >= 2000