com php-src: Avoid useless op_array duplication: ext/op cache/zend_accelerator_util_funcs.c ext/opcache/zend _persist.c
ext/opcache/zend_persist_calc.c
| From: | Dmitry Stogov | Date: | Thu, 05 Mar 2015 11:23:48 +0000 |
| Subject: | com php-src: Avoid useless op_array duplication: ext/op cache/zend_accelerator_util_funcs.c ext/opcache/zend _persist.c ext/opcache/zend_persist_calc.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85253@lists.php.net to get a copy of this message | ||
Commit: 8e3643a8fcf9f901d0990937fa332e22607ce0f1
Author: Dmitry Stogov <dmitry@zend.com> Thu, 5 Mar 2015 14:23:48 +0300
Parents: eec5ab7672b0b14d31c3f9f6ce6f4e52c22f76cb
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8e3643a8fcf9f901d0990937fa332e22607ce0f1
Log:
Avoid useless op_array duplication
Changed paths:
M ext/opcache/zend_accelerator_util_funcs.c
M ext/opcache/zend_persist.c
M ext/opcache/zend_persist_calc.c
Diff:
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index e4430bf..8c89a8d 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -401,11 +401,15 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source,
zend_class
ZVAL_PTR(&q->val, ARENA_REALLOC(Z_PTR(p->val)));
new_entry = (zend_op_array*)Z_PTR(q->val);
- new_entry->scope = ARENA_REALLOC(new_entry->scope);
+ if ((void*)new_entry->scope >= ZCG(current_persistent_script)->arena_mem &&
+ (void*)new_entry->scope < (void*)((char*)ZCG(current_persistent_script)->arena_mem +
ZCG(current_persistent_script)->arena_size)) {
- /* update prototype */
- if (new_entry->prototype) {
- new_entry->prototype = ARENA_REALLOC(new_entry->prototype);
+ new_entry->scope = ARENA_REALLOC(new_entry->scope);
+
+ /* update prototype */
+ if (new_entry->prototype) {
+ new_entry->prototype = ARENA_REALLOC(new_entry->prototype);
+ }
}
}
}
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index fdba506..43376ed 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -572,6 +572,15 @@ static void zend_persist_op_array_ex(zend_op_array *op_array,
zend_persistent_sc
static void zend_persist_op_array(zval *zv)
{
+ zend_op_array *op_array = Z_PTR_P(zv);
+ zend_op_array *old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
+ if (old_op_array) {
+ Z_PTR_P(zv) = old_op_array;
+ if (op_array->refcount && --(*op_array->refcount) == 0) {
+ efree(op_array->refcount);
+ }
+ return;
+ }
memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_op_array));
zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
Z_PTR_P(zv) = ZCG(arena_mem);
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index d7fbaa2..bfc3079 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -247,8 +247,22 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
static void zend_persist_op_array_calc(zval *zv)
{
- ADD_ARENA_SIZE(sizeof(zend_op_array));
- zend_persist_op_array_calc_ex(Z_PTR_P(zv));
+ zend_op_array *op_array = Z_PTR_P(zv);
+
+ if (op_array->type == ZEND_USER_FUNCTION/* &&
+ (!op_array->refcount || *(op_array->refcount) > 1)*/) {
+ zend_op_array *old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
+ if (old_op_array) {
+ Z_PTR_P(zv) = old_op_array;
+ } else {
+ ADD_ARENA_SIZE(sizeof(zend_op_array));
+ zend_persist_op_array_calc_ex(Z_PTR_P(zv));
+ zend_shared_alloc_register_xlat_entry(op_array, Z_PTR_P(zv));
+ }
+ } else {
+ ADD_ARENA_SIZE(sizeof(zend_op_array));
+ zend_persist_op_array_calc_ex(Z_PTR_P(zv));
+ }
}
static void zend_persist_property_info_calc(zval *zv)