From: Dmitry Stogov Date: Mon, 31 Mar 2014 09:11:58 +0000 (+0400) Subject: Make opcache work (incomplete - optimizer doesn't work yet; crashes on request shutdown) X-Git-Tag: POST_PHPNG_MERGE~412^2~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=292b8dffc81198ff343354ea2bb26ebd42ca2fa2;p=php Make opcache work (incomplete - optimizer doesn't work yet; crashes on request shutdown) --- diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 8853cc6879..85347be976 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -353,7 +353,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC) ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(sizeof(zend_string) + str->len); p->key->gc.refcount = 1; p->key->gc.u.v.type = IS_STRING; - p->key->gc.u.v.flags |= IS_STR_INTERNED; + p->key->gc.u.v.flags = IS_STR_INTERNED | IS_STR_PERMANENT; p->key->h = str->h; p->key->len = str->len; memcpy(p->key->val, str->val, str->len); diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index efda22fb29..3769e362fe 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -395,7 +395,7 @@ static void zend_hash_clone_zval(HashTable *ht, HashTable *source, int bind) if (!p->key) { q->key = NULL; } else { - q->key = STR_DUP(q->key, 0); + q->key = STR_DUP(p->key, 0); } /* Copy data */ @@ -467,7 +467,7 @@ static void zend_hash_clone_methods(HashTable *ht, HashTable *source, zend_class } /* Copy data */ - Z_PTR(q->val) = (void *) emalloc(sizeof(zend_function)); + ZVAL_PTR(&q->val, (void *) emalloc(sizeof(zend_op_array))); new_entry = (zend_op_array*)Z_PTR(q->val); *new_entry = *(zend_op_array*)Z_PTR(p->val); @@ -562,7 +562,7 @@ static void zend_hash_clone_prop_info(HashTable *ht, HashTable *source, zend_cla } /* Copy data */ - Z_PTR(q->val) = (void *) emalloc(sizeof(zend_property_info)); + ZVAL_PTR(&q->val, (void *) emalloc(sizeof(zend_property_info))); prop_info = Z_PTR(q->val); *prop_info = *(zend_property_info*)Z_PTR(p->val); @@ -636,9 +636,10 @@ static void zend_class_copy_ctor(zend_class_entry **pce) if (old_ce->default_properties_table) { int i; - ce->default_properties_table = emalloc(sizeof(zval*) * old_ce->default_properties_count); + ce->default_properties_table = emalloc(sizeof(zval) * old_ce->default_properties_count); for (i = 0; i < old_ce->default_properties_count; i++) { - zend_clone_zval(&old_ce->default_properties_table[i], 0 TSRMLS_CC); + ZVAL_COPY_VALUE(&ce->default_properties_table[i], &old_ce->default_properties_table[i]); + zend_clone_zval(&ce->default_properties_table[i], 0 TSRMLS_CC); } } #else @@ -652,9 +653,10 @@ static void zend_class_copy_ctor(zend_class_entry **pce) if (old_ce->default_static_members_table) { int i; - ce->default_static_members_table = emalloc(sizeof(zval*) * old_ce->default_static_members_count); + ce->default_static_members_table = emalloc(sizeof(zval) * old_ce->default_static_members_count); for (i = 0; i < old_ce->default_static_members_count; i++) { - zend_clone_zval(&old_ce->default_static_members_table[i], 1 TSRMLS_CC); + ZVAL_COPY_VALUE(&ce->default_static_members_table[i], &old_ce->default_static_members_table[i]); + zend_clone_zval(&ce->default_static_members_table[i], 1 TSRMLS_CC); } } ce->static_members_table = ce->default_static_members_table; @@ -851,15 +853,15 @@ static int zend_hash_unique_copy_ptr(HashTable *target, HashTable *source, uniqu { uint idx; Bucket *p; - void *t; + zval *t; for (idx = 0; idx < source->nNumUsed; idx++) { p = source->arData + idx; if (Z_TYPE(p->val) == IS_UNDEF) continue; if (p->key) { - if ((t = zend_hash_add_ptr(target, p->key, Z_PTR(p->val))) != NULL) { + if ((t = zend_hash_add(target, p->key, &p->val)) != NULL) { if (pCopyConstructor) { - pCopyConstructor(t); + pCopyConstructor(&Z_PTR_P(t)); } } else { if (p->key->len > 0 && p->key->val[0] == 0) { @@ -867,29 +869,29 @@ static int zend_hash_unique_copy_ptr(HashTable *target, HashTable *source, uniqu #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO if (((zend_function*)Z_PTR(p->val))->common.fn_flags & ZEND_ACC_CLOSURE) { /* update closure */ - if ((t = zend_hash_update_ptr(target, p->key, Z_PTR(p->val))) != NULL) { + if ((t = zend_hash_update(target, p->key, &p->val)) != NULL) { if (pCopyConstructor) { - pCopyConstructor(t); + pCopyConstructor(&Z_PTR_P(t)); } } } else { /* ignore and wait for runtime */ } #endif - } else if (!ignore_dups && (t = zend_hash_find_ptr(target, p->key)) != NULL) { + } else if (!ignore_dups && (t = zend_hash_find(target, p->key)) != NULL) { *fail_data = Z_PTR(p->val); - *conflict_data = t; + *conflict_data = Z_PTR_P(t); return FAILURE; } } } else { - if (!zend_hash_index_exists(target, p->h) && (t = zend_hash_index_update_ptr(target, p->h, Z_PTR(p->val))) != NULL) { + if (!zend_hash_index_exists(target, p->h) && (t = zend_hash_index_update(target, p->h, &p->val)) != NULL) { if (pCopyConstructor) { - pCopyConstructor(t); + pCopyConstructor(&Z_PTR_P(t)); } - } else if (!ignore_dups && (t = zend_hash_index_find_ptr(target,p->h)) != NULL) { + } else if (!ignore_dups && (t = zend_hash_index_find(target,p->h)) != NULL) { *fail_data = Z_PTR(p->val); - *conflict_data = t; + *conflict_data = Z_PTR_P(t); return FAILURE; } } diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index bcec15c03b..cfac1960a2 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -339,7 +339,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc if ((new_name = zend_shared_alloc_get_xlat_entry(op_array->function_name))) { op_array->function_name = new_name; } else { - zend_accel_store_string(op_array->function_name); + zend_accel_store_interned_string(op_array->function_name); } } @@ -453,7 +453,7 @@ static void zend_persist_class_entry(zval *zv TSRMLS_DC) if (ce->default_properties_table) { int i; - zend_accel_store(ce->default_properties_table, sizeof(zval*) * ce->default_properties_count); + zend_accel_store(ce->default_properties_table, sizeof(zval) * ce->default_properties_count); for (i = 0; i < ce->default_properties_count; i++) { zend_persist_zval(&ce->default_properties_table[i] TSRMLS_CC); } @@ -461,7 +461,7 @@ static void zend_persist_class_entry(zval *zv TSRMLS_DC) if (ce->default_static_members_table) { int i; - zend_accel_store(ce->default_static_members_table, sizeof(zval*) * ce->default_static_members_count); + zend_accel_store(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count); for (i = 0; i < ce->default_static_members_count; i++) { zend_persist_zval(&ce->default_static_members_table[i] TSRMLS_CC); } @@ -564,15 +564,17 @@ static void zend_persist_class_entry(zval *zv TSRMLS_DC) } } -static int zend_update_property_info_ce(zend_property_info *prop TSRMLS_DC) +static int zend_update_property_info_ce(zval *zv TSRMLS_DC) { + zend_property_info *prop = Z_PTR_P(zv); + prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce); return 0; } -static int zend_update_parent_ce(zend_class_entry **pce TSRMLS_DC) +static int zend_update_parent_ce(zval *zv TSRMLS_DC) { - zend_class_entry *ce = *pce; + zend_class_entry *ce = Z_PTR_P(zv); if (ce->parent) { ce->parent = zend_shared_alloc_get_xlat_entry(ce->parent); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index f5aa322b2c..51b48ecee0 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -272,7 +272,7 @@ static uint zend_persist_class_entry_calc(zval *zv TSRMLS_DC) if (ce->default_properties_table) { int i; - ADD_SIZE(sizeof(zval*) * ce->default_properties_count); + ADD_SIZE(sizeof(zval) * ce->default_properties_count); for (i = 0; i < ce->default_properties_count; i++) { ADD_SIZE(zend_persist_zval_calc(&ce->default_properties_table[i] TSRMLS_CC)); } @@ -280,7 +280,7 @@ static uint zend_persist_class_entry_calc(zval *zv TSRMLS_DC) if (ce->default_static_members_table) { int i; - ADD_SIZE(sizeof(zval*) * ce->default_static_members_count); + ADD_SIZE(sizeof(zval) * ce->default_static_members_count); for (i = 0; i < ce->default_static_members_count; i++) { ADD_SIZE(zend_persist_zval_calc(&ce->default_static_members_table[i] TSRMLS_CC)); }