summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-08-16 21:55:08 +0200
committerNikita Popov <nikic@php.net>2014-08-16 21:55:08 +0200
commit71675a4bf830d7b9400663275fe48275480d34f4 (patch)
tree8ce9b1fdda30d26121334fb5c228df7884f6f7c2 /ext/opcache
parentf72d6f97ecf976f00abc0dc21b5d1ef4838de60a (diff)
parent8b66d64b2343bc4fd8aeabb690024edb850a0155 (diff)
downloadphp-git-71675a4bf830d7b9400663275fe48275480d34f4.tar.gz
Merge remote-tracking branch 'php-src/phpng' into ast
Conflicts: Zend/zend_ast.c Zend/zend_compile.c Zend/zend_language_parser.y Incomplete merge!
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/compact_literals.c4
-rw-r--r--ext/opcache/Optimizer/zend_optimizer.c3
-rw-r--r--ext/opcache/ZendAccelerator.c11
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c5
-rw-r--r--ext/opcache/zend_persist.c35
-rw-r--r--ext/opcache/zend_persist_calc.c4
6 files changed, 47 insertions, 15 deletions
diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c
index b97fda9ab1..f13bf50699 100644
--- a/ext/opcache/Optimizer/compact_literals.c
+++ b/ext/opcache/Optimizer/compact_literals.c
@@ -273,7 +273,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
for (i = 0; i < op_array->last_literal; i++) {
zval zv = op_array->literals[i].constant;
- use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv);
+ use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv TSRMLS_CC);
fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv));
if (use_copy) {
zval_dtor(&zv);
@@ -454,7 +454,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
for (i = 0; i < op_array->last_literal; i++) {
zval zv = op_array->literals[i].constant;
- use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv);
+ use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv TSRMLS_CC);
fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv));
if (use_copy) {
zval_dtor(&zv);
diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c
index e4e1f74acc..fd711cb9ee 100644
--- a/ext/opcache/Optimizer/zend_optimizer.c
+++ b/ext/opcache/Optimizer/zend_optimizer.c
@@ -110,9 +110,6 @@ int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC)
int i = op_array->last_literal;
op_array->last_literal++;
op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval));
- if (Z_TYPE_P(zv) == IS_ARRAY) {
- zend_make_immutable_array(zv TSRMLS_CC);
- }
ZVAL_COPY_VALUE(&op_array->literals[i], zv);
Z_CACHE_SLOT(op_array->literals[i]) = -1;
//??? Z_SET_REFCOUNT(op_array->literals[i].constant, 2);
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index df36b55b62..6228c827c9 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -719,7 +719,7 @@ static accel_time_t zend_get_file_handle_timestamp_win(zend_file_handle *file_ha
ftime /= 10000000L;
if (size) {
- *size = (size_t)(((unsigned __int64)fdata.nFileSizeHigh) << 32 + (unsigned __int64)fdata.nFileSizeLow);
+ *size = (size_t)((((unsigned __int64)fdata.nFileSizeHigh) << 32) + (unsigned __int64)fdata.nFileSizeLow);
}
return (accel_time_t)ftime;
}
@@ -1650,6 +1650,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));
zend_op_array *op_array;
/* Cache miss.. */
@@ -1674,6 +1675,14 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
SHM_PROTECT();
return op_array;
}
+ if (from_shared_memory) {
+ /* Delete immutable arrays moved into SHM */
+ zend_uint 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);
+ }
+ }
} else {
#if !ZEND_WIN32
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index 0c3b808c63..7c59d01254 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -988,7 +988,6 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
if (zend_hash_num_elements(&persistent_script->class_table) > 0) {
zend_accel_class_hash_copy(CG(class_table), &persistent_script->class_table, NULL TSRMLS_CC);
}
- free_persistent_script(persistent_script, 0); /* free only hashes */
}
#if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
@@ -1000,6 +999,10 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
}
#endif
+ if (!from_shared_memory) {
+ free_persistent_script(persistent_script, 0); /* free only hashes */
+ }
+
return op_array;
}
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 09bca802c6..d703235a5c 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -86,11 +86,18 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement
return;
}
if (ht->u.flags & HASH_FLAG_PACKED) {
- zend_accel_store(ht->arData, sizeof(Bucket) * ht->nTableSize);
+ zend_accel_store(ht->arData, sizeof(Bucket) * ht->nNumUsed);
ht->arHash = (zend_uint*)&uninitialized_bucket;
} else {
- zend_accel_store(ht->arData, (sizeof(Bucket) + sizeof(zend_uint)) * ht->nTableSize);
- ht->arHash = (zend_uint*)(ht->arData + ht->nTableSize);
+ Bucket *d = (Bucket*)ZCG(mem);
+ zend_uint *h = (zend_uint*)(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);
+ efree(ht->arData);
+ ht->arData = d;
+ ht->arHash = h;
}
for (idx = 0; idx < ht->nNumUsed; idx++) {
p = ht->arData + idx;
@@ -116,11 +123,17 @@ static void zend_hash_persist_immutable(HashTable *ht TSRMLS_DC)
return;
}
if (ht->u.flags & HASH_FLAG_PACKED) {
- ht->arData = zend_accel_memdup(ht->arData, sizeof(Bucket) * ht->nTableSize);
+ ht->arData = zend_accel_memdup(ht->arData, sizeof(Bucket) * ht->nNumUsed);
ht->arHash = (zend_uint*)&uninitialized_bucket;
} else {
- ht->arData = zend_accel_memdup(ht->arData, (sizeof(Bucket) + sizeof(zend_uint)) * ht->nTableSize);
- ht->arHash = (zend_uint*)(ht->arData + ht->nTableSize);
+ Bucket *d = (Bucket*)ZCG(mem);
+ zend_uint *h = (zend_uint*)(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);
+ ht->arData = d;
+ ht->arHash = h;
}
for (idx = 0; idx < ht->nNumUsed; idx++) {
p = ht->arData + idx;
@@ -195,6 +208,7 @@ static void zend_persist_zval(zval *z TSRMLS_DC)
new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
if (new_ptr) {
Z_ARR_P(z) = new_ptr;
+ Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
} else {
if (Z_IMMUTABLE_P(z)) {
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
@@ -202,6 +216,10 @@ static void zend_persist_zval(zval *z TSRMLS_DC)
} else {
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 */
+ Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
+ GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
+ Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
}
}
break;
@@ -252,6 +270,7 @@ static void zend_persist_zval_const(zval *z TSRMLS_DC)
new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
if (new_ptr) {
Z_ARR_P(z) = new_ptr;
+ Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
} else {
if (Z_IMMUTABLE_P(z)) {
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
@@ -259,6 +278,10 @@ static void zend_persist_zval_const(zval *z TSRMLS_DC)
} else {
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 */
+ Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
+ GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
+ Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
}
}
break;
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index dc7f96727c..f26a6fe195 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -63,9 +63,9 @@ static uint zend_hash_persist_calc(HashTable *ht, uint (*pPersistElement)(zval *
RETURN_SIZE();
}
if (ht->u.flags & HASH_FLAG_PACKED) {
- ADD_DUP_SIZE(ht->arData, sizeof(Bucket) * ht->nTableSize);
+ ADD_SIZE(sizeof(Bucket) * ht->nNumUsed);
} else {
- ADD_DUP_SIZE(ht->arData, (sizeof(Bucket) + sizeof(zend_uint)) * ht->nTableSize);
+ ADD_SIZE(sizeof(Bucket) * ht->nNumUsed + sizeof(zend_uint) * ht->nTableSize);
}
for (idx = 0; idx < ht->nNumUsed; idx++) {