PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/opcache - zend_persist.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 252 494 51.0 %
Date: 2016-07-01 Functions: 12 15 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend OPcache                                                         |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          Stanislav Malyshev <stas@zend.com>                          |
      18             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      19             :    +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : #include "zend.h"
      23             : #include "ZendAccelerator.h"
      24             : #include "zend_persist.h"
      25             : #include "zend_extensions.h"
      26             : #include "zend_shared_alloc.h"
      27             : #include "zend_vm.h"
      28             : #include "zend_constants.h"
      29             : #include "zend_operators.h"
      30             : 
      31             : #define zend_accel_store(p, size) \
      32             :             (p = _zend_shared_memdup((void*)p, size, 1))
      33             : #define zend_accel_memdup(p, size) \
      34             :             _zend_shared_memdup((void*)p, size, 0)
      35             : 
      36             : #define zend_accel_store_string(str) do { \
      37             :                 zend_string *new_str = zend_shared_alloc_get_xlat_entry(str); \
      38             :                 if (new_str) { \
      39             :                         zend_string_release(str); \
      40             :                         str = new_str; \
      41             :                 } else { \
      42             :                 new_str = zend_accel_memdup((void*)str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
      43             :                         zend_string_release(str); \
      44             :                 str = new_str; \
      45             :                 zend_string_hash_val(str); \
      46             :                 GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
      47             :                 } \
      48             :     } while (0)
      49             : #define zend_accel_memdup_string(str) do { \
      50             :                 str = zend_accel_memdup(str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
      51             :         zend_string_hash_val(str); \
      52             :                 GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
      53             :         } while (0)
      54             : #define zend_accel_store_interned_string(str) do { \
      55             :                 if (!IS_ACCEL_INTERNED(str)) { \
      56             :                         zend_accel_store_string(str); \
      57             :                 } \
      58             :         } while (0)
      59             : #define zend_accel_memdup_interned_string(str) do { \
      60             :                 if (!IS_ACCEL_INTERNED(str)) { \
      61             :                         zend_accel_memdup_string(str); \
      62             :                 } \
      63             :         } while (0)
      64             : 
      65             : typedef void (*zend_persist_func_t)(zval*);
      66             : 
      67             : static void zend_persist_zval(zval *z);
      68             : static void zend_persist_zval_const(zval *z);
      69             : 
      70             : static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
      71             :         {HT_INVALID_IDX, HT_INVALID_IDX};
      72             : 
      73         968 : static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement)
      74             : {
      75             :         uint32_t idx, nIndex;
      76             :         Bucket *p;
      77             : 
      78         968 :         if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
      79         469 :                 HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
      80         469 :                 return;
      81             :         }
      82         499 :         if (ht->nNumUsed == 0) {
      83         406 :                 efree(HT_GET_DATA_ADDR(ht));
      84         406 :                 ht->nTableMask = HT_MIN_MASK;
      85         406 :                 HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
      86         406 :                 ht->u.flags &= ~HASH_FLAG_INITIALIZED;
      87         406 :                 return;
      88             :         }
      89          93 :         if (ht->u.flags & HASH_FLAG_PACKED) {
      90          12 :                 void *data = HT_GET_DATA_ADDR(ht);
      91          12 :                 zend_accel_store(data, HT_USED_SIZE(ht));
      92          12 :                 HT_SET_DATA_ADDR(ht, data);
      93          81 :         } else if (ht->nNumUsed < -(int32_t)ht->nTableMask / 2) {
      94             :                 /* compact table */
      95          77 :                 void *old_data = HT_GET_DATA_ADDR(ht);
      96          77 :                 Bucket *old_buckets = ht->arData;
      97             :                 int32_t hash_size;
      98             : 
      99          77 :                 if (ht->nNumUsed <= HT_MIN_SIZE) {
     100          77 :                         hash_size = HT_MIN_SIZE;
     101             :                 } else {
     102           0 :                         hash_size = -(int32_t)ht->nTableMask;
     103           0 :                         while (hash_size >> 1 > ht->nNumUsed) {
     104           0 :                                 hash_size >>= 1;
     105             :                         }
     106             :                 }
     107          77 :                 ht->nTableMask = -hash_size;
     108             :                 ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     109          77 :                 HT_SET_DATA_ADDR(ht, ZCG(mem));
     110          77 :                 ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE((hash_size * sizeof(uint32_t)) + (ht->nNumUsed * sizeof(Bucket))));
     111          77 :                 HT_HASH_RESET(ht);
     112          77 :                 memcpy(ht->arData, old_buckets, ht->nNumUsed * sizeof(Bucket));
     113          77 :                 efree(old_data);
     114             : 
     115         167 :                 for (idx = 0; idx < ht->nNumUsed; idx++) {
     116          90 :                         p = ht->arData + idx;
     117         180 :                         if (Z_TYPE(p->val) == IS_UNDEF) continue;
     118             : 
     119             :                         /* persist bucket and key */
     120          83 :                         if (p->key) {
     121          83 :                                 zend_accel_store_interned_string(p->key);
     122             :                         }
     123             : 
     124             :                         /* persist the data itself */
     125          83 :                         pPersistElement(&p->val);
     126             : 
     127          83 :                         nIndex = p->h | ht->nTableMask;
     128          83 :                         Z_NEXT(p->val) = HT_HASH(ht, nIndex);
     129          83 :                         HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
     130             :                 }
     131          77 :                 return;
     132             :         } else {
     133           4 :                 void *data = ZCG(mem);
     134           4 :                 void *old_data = HT_GET_DATA_ADDR(ht);
     135             : 
     136             :                 ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     137           4 :                 ZCG(mem) = (void*)((char*)data + HT_USED_SIZE(ht));
     138           4 :                 memcpy(data, old_data, HT_USED_SIZE(ht));
     139           4 :                 efree(old_data);
     140           4 :                 HT_SET_DATA_ADDR(ht, data);
     141             :         }
     142             : 
     143         111 :         for (idx = 0; idx < ht->nNumUsed; idx++) {
     144          95 :                 p = ht->arData + idx;
     145         190 :                 if (Z_TYPE(p->val) == IS_UNDEF) continue;
     146             : 
     147             :                 /* persist bucket and key */
     148          95 :                 if (p->key) {
     149          58 :                         zend_accel_store_interned_string(p->key);
     150             :                 }
     151             : 
     152             :                 /* persist the data itself */
     153          95 :                 pPersistElement(&p->val);
     154             :         }
     155             : }
     156             : 
     157           0 : static void zend_hash_persist_immutable(HashTable *ht)
     158             : {
     159             :         uint32_t idx, nIndex;
     160             :         Bucket *p;
     161             : 
     162           0 :         if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
     163           0 :                 HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
     164           0 :                 return;
     165             :         }
     166           0 :         if (ht->nNumUsed == 0) {
     167           0 :                 efree(HT_GET_DATA_ADDR(ht));
     168           0 :                 ht->nTableMask = HT_MIN_MASK;
     169           0 :                 HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
     170           0 :                 ht->u.flags &= ~HASH_FLAG_INITIALIZED;
     171           0 :                 return;
     172             :         }
     173           0 :         if (ht->u.flags & HASH_FLAG_PACKED) {
     174           0 :                 HT_SET_DATA_ADDR(ht, zend_accel_memdup(HT_GET_DATA_ADDR(ht), HT_USED_SIZE(ht)));
     175           0 :         } else if (ht->nNumUsed < -(int32_t)ht->nTableMask / 2) {
     176             :                 /* compact table */
     177           0 :                 void *old_data = HT_GET_DATA_ADDR(ht);
     178           0 :                 Bucket *old_buckets = ht->arData;
     179             :                 int32_t hash_size;
     180             : 
     181           0 :                 if (ht->nNumUsed <= HT_MIN_SIZE) {
     182           0 :                         hash_size = HT_MIN_SIZE;
     183             :                 } else {
     184           0 :                         hash_size = -(int32_t)ht->nTableMask;
     185           0 :                         while (hash_size >> 1 > ht->nNumUsed) {
     186           0 :                                 hash_size >>= 1;
     187             :                         }
     188             :                 }
     189           0 :                 ht->nTableMask = -hash_size;
     190             :                 ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     191           0 :                 HT_SET_DATA_ADDR(ht, ZCG(mem));
     192           0 :                 ZCG(mem) = (void*)((char*)ZCG(mem) + (hash_size * sizeof(uint32_t)) + (ht->nNumUsed * sizeof(Bucket)));
     193           0 :                 HT_HASH_RESET(ht);
     194           0 :                 memcpy(ht->arData, old_buckets, ht->nNumUsed * sizeof(Bucket));
     195           0 :                 efree(old_data);
     196             : 
     197           0 :                 for (idx = 0; idx < ht->nNumUsed; idx++) {
     198           0 :                         p = ht->arData + idx;
     199           0 :                         if (Z_TYPE(p->val) == IS_UNDEF) continue;
     200             : 
     201             :                         /* persist bucket and key */
     202           0 :                         if (p->key) {
     203           0 :                                 zend_accel_memdup_interned_string(p->key);
     204             :                         }
     205             : 
     206             :                         /* persist the data itself */
     207           0 :                         zend_persist_zval_const(&p->val);
     208             : 
     209           0 :                         nIndex = p->h | ht->nTableMask;
     210           0 :                         Z_NEXT(p->val) = HT_HASH(ht, nIndex);
     211           0 :                         HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
     212             :                 }
     213           0 :                 return;
     214             :         } else {
     215           0 :                 void *data = ZCG(mem);
     216             : 
     217             :                 ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     218           0 :                 ZCG(mem) = (void*)((char*)data + HT_USED_SIZE(ht));
     219           0 :                 memcpy(data, HT_GET_DATA_ADDR(ht), HT_USED_SIZE(ht));
     220           0 :                 HT_SET_DATA_ADDR(ht, data);
     221             :         }
     222           0 :         for (idx = 0; idx < ht->nNumUsed; idx++) {
     223           0 :                 p = ht->arData + idx;
     224           0 :                 if (Z_TYPE(p->val) == IS_UNDEF) continue;
     225             : 
     226             :                 /* persist bucket and key */
     227           0 :                 if (p->key) {
     228           0 :                         zend_accel_memdup_interned_string(p->key);
     229             :                 }
     230             : 
     231             :                 /* persist the data itself */
     232           0 :                 zend_persist_zval_const(&p->val);
     233             :         }
     234             : }
     235             : 
     236           0 : static zend_ast *zend_persist_ast(zend_ast *ast)
     237             : {
     238             :         uint32_t i;
     239             :         zend_ast *node;
     240             : 
     241           0 :         if (ast->kind == ZEND_AST_ZVAL) {
     242           0 :                 zend_ast_zval *copy = zend_accel_memdup(ast, sizeof(zend_ast_zval));
     243           0 :                 zend_persist_zval(&copy->val);
     244           0 :                 node = (zend_ast *) copy;
     245           0 :         } else if (zend_ast_is_list(ast)) {
     246           0 :                 zend_ast_list *list = zend_ast_get_list(ast);
     247           0 :                 zend_ast_list *copy = zend_accel_memdup(ast,
     248             :                         sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
     249           0 :                 for (i = 0; i < list->children; i++) {
     250           0 :                         if (copy->child[i]) {
     251           0 :                                 copy->child[i] = zend_persist_ast(copy->child[i]);
     252             :                         }
     253             :                 }
     254           0 :                 node = (zend_ast *) copy;
     255             :         } else {
     256           0 :                 uint32_t children = zend_ast_get_num_children(ast);
     257           0 :                 node = zend_accel_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
     258           0 :                 for (i = 0; i < children; i++) {
     259           0 :                         if (node->child[i]) {
     260           0 :                                 node->child[i] = zend_persist_ast(node->child[i]);
     261             :                         }
     262             :                 }
     263             :         }
     264             : 
     265           0 :         efree(ast);
     266           0 :         return node;
     267             : }
     268             : 
     269        3112 : static void zend_persist_zval(zval *z)
     270             : {
     271             :         zend_uchar flags;
     272             :         void *new_ptr;
     273             : 
     274        3112 :         switch (Z_TYPE_P(z)) {
     275             :                 case IS_STRING:
     276             :                 case IS_CONSTANT:
     277        2406 :                         flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT);
     278        2406 :                         zend_accel_store_interned_string(Z_STR_P(z));
     279        2406 :                         Z_GC_FLAGS_P(z) |= flags;
     280        2406 :                         Z_TYPE_FLAGS_P(z) &= ~(IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     281        2406 :                         break;
     282             :                 case IS_ARRAY:
     283          62 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
     284          62 :                         if (new_ptr) {
     285           0 :                                 Z_ARR_P(z) = new_ptr;
     286           0 :                                 Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     287             :                         } else {
     288          62 :                                 if (Z_IMMUTABLE_P(z)) {
     289           0 :                                         Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
     290           0 :                                         zend_hash_persist_immutable(Z_ARRVAL_P(z));
     291             :                                 } else {
     292          62 :                                         GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
     293          62 :                                         zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
     294          62 :                                         zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
     295             :                                         /* make immutable array */
     296          62 :                                         Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     297          62 :                                         GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
     298          62 :                                         GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
     299          62 :                                         Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;
     300          62 :                                         Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
     301             :                                 }
     302             :                         }
     303          62 :                         break;
     304             :                 case IS_REFERENCE:
     305           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_REF_P(z));
     306           0 :                         if (new_ptr) {
     307           0 :                                 Z_REF_P(z) = new_ptr;
     308             :                         } else {
     309           0 :                                 zend_accel_store(Z_REF_P(z), sizeof(zend_reference));
     310           0 :                                 zend_persist_zval(Z_REFVAL_P(z));
     311             :                         }
     312           0 :                         break;
     313             :                 case IS_CONSTANT_AST:
     314           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
     315           0 :                         if (new_ptr) {
     316           0 :                                 Z_AST_P(z) = new_ptr;
     317             :                         } else {
     318           0 :                                 zend_accel_store(Z_AST_P(z), sizeof(zend_ast_ref));
     319           0 :                                 Z_ASTVAL_P(z) = zend_persist_ast(Z_ASTVAL_P(z));
     320             :                         }
     321             :                         break;
     322             :         }
     323        3112 : }
     324             : 
     325          13 : static void zend_persist_zval_static(zval *z)
     326             : {
     327             :         zend_uchar flags;
     328             :         void *new_ptr;
     329             : 
     330             :         switch (Z_TYPE_P(z)) {
     331             :                 case IS_STRING:
     332             :                 case IS_CONSTANT:
     333           0 :                         flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT);
     334           0 :                         zend_accel_store_interned_string(Z_STR_P(z));
     335           0 :                         Z_GC_FLAGS_P(z) |= flags;
     336           0 :                         Z_TYPE_FLAGS_P(z) &= ~(IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     337           0 :                         break;
     338             :                 case IS_ARRAY:
     339          12 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
     340          12 :                         if (new_ptr) {
     341           0 :                                 Z_ARR_P(z) = new_ptr;
     342           0 :                                 Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     343             :                         } else {
     344          12 :                                 if (Z_IMMUTABLE_P(z)) {
     345           0 :                                         Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
     346           0 :                                         zend_hash_persist_immutable(Z_ARRVAL_P(z));
     347             :                                 } else {
     348          12 :                                         GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
     349          12 :                                         zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
     350          12 :                                         zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
     351             :                                         /* make immutable array */
     352          12 :                                         Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     353          12 :                                         GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
     354          12 :                                         GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
     355          12 :                                         Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;
     356          12 :                                         Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
     357             :                                 }
     358             :                         }
     359          12 :                         break;
     360             :                 case IS_REFERENCE:
     361           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_REF_P(z));
     362           0 :                         if (new_ptr) {
     363           0 :                                 Z_REF_P(z) = new_ptr;
     364             :                         } else {
     365           0 :                                 zend_accel_store(Z_REF_P(z), sizeof(zend_reference));
     366           0 :                                 zend_persist_zval(Z_REFVAL_P(z));
     367             :                         }
     368           0 :                         break;
     369             :                 case IS_CONSTANT_AST:
     370           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
     371           0 :                         if (new_ptr) {
     372           0 :                                 Z_AST_P(z) = new_ptr;
     373           0 :                                 Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_IMMUTABLE;
     374             :                         } else {
     375           0 :                                 zend_accel_store(Z_AST_P(z), sizeof(zend_ast_ref));
     376           0 :                                 Z_ASTVAL_P(z) = zend_persist_ast(Z_ASTVAL_P(z));
     377           0 :                                 Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_IMMUTABLE;
     378           0 :                                 GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
     379             :                         }
     380             :                         break;
     381             :         }
     382          13 : }
     383             : 
     384           0 : static void zend_persist_zval_const(zval *z)
     385             : {
     386             :         zend_uchar flags;
     387             :         void *new_ptr;
     388             : 
     389           0 :         switch (Z_TYPE_P(z)) {
     390             :                 case IS_STRING:
     391             :                 case IS_CONSTANT:
     392           0 :                         flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT);
     393           0 :                         zend_accel_memdup_interned_string(Z_STR_P(z));
     394           0 :                         Z_GC_FLAGS_P(z) |= flags;
     395           0 :                         Z_TYPE_FLAGS_P(z) &= ~(IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     396           0 :                         break;
     397             :                 case IS_ARRAY:
     398           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
     399           0 :                         if (new_ptr) {
     400           0 :                                 Z_ARR_P(z) = new_ptr;
     401           0 :                                 Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     402             :                         } else {
     403           0 :                                 if (Z_IMMUTABLE_P(z)) {
     404           0 :                                         Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
     405           0 :                                         zend_hash_persist_immutable(Z_ARRVAL_P(z));
     406             :                                 } else {
     407           0 :                                         GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
     408           0 :                                         zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
     409           0 :                                         zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
     410             :                                         /* make immutable array */
     411           0 :                                         Z_TYPE_FLAGS_P(z) = IS_TYPE_IMMUTABLE;
     412           0 :                                         GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
     413           0 :                                         GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
     414           0 :                                         Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;
     415           0 :                                         Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
     416             :                                 }
     417             :                         }
     418           0 :                         break;
     419             :                 case IS_REFERENCE:
     420           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_REF_P(z));
     421           0 :                         if (new_ptr) {
     422           0 :                                 Z_REF_P(z) = new_ptr;
     423             :                         } else {
     424           0 :                                 zend_accel_store(Z_REF_P(z), sizeof(zend_reference));
     425           0 :                                 zend_persist_zval(Z_REFVAL_P(z));
     426             :                         }
     427           0 :                         break;
     428             :                 case IS_CONSTANT_AST:
     429           0 :                         new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
     430           0 :                         if (new_ptr) {
     431           0 :                                 Z_AST_P(z) = new_ptr;
     432             :                         } else {
     433           0 :                                 zend_accel_store(Z_AST_P(z), sizeof(zend_ast_ref));
     434           0 :                                 Z_ASTVAL_P(z) = zend_persist_ast(Z_ASTVAL_P(z));
     435             :                         }
     436             :                         break;
     437             :         }
     438           0 : }
     439             : 
     440         463 : static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_script* main_persistent_script)
     441             : {
     442         463 :         int already_stored = 0;
     443             :         zend_op *persist_ptr;
     444         463 :         zval *orig_literals = NULL;
     445             : 
     446         463 :         if (op_array->type != ZEND_USER_FUNCTION) {
     447           0 :                 return;
     448             :         }
     449             : 
     450         463 :         if (op_array->refcount && --(*op_array->refcount) == 0) {
     451         463 :                 efree(op_array->refcount);
     452             :         }
     453         463 :         op_array->refcount = NULL;
     454             : 
     455         463 :         if (main_persistent_script) {
     456         430 :                 zend_execute_data *orig_execute_data = EG(current_execute_data);
     457             :                 zend_execute_data fake_execute_data;
     458             :                 zval *offset;
     459             : 
     460         430 :                 memset(&fake_execute_data, 0, sizeof(fake_execute_data));
     461         430 :                 fake_execute_data.func = (zend_function*)op_array;
     462         430 :                 EG(current_execute_data) = &fake_execute_data;
     463         430 :                 if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
     464          95 :                         main_persistent_script->compiler_halt_offset = Z_LVAL_P(offset);
     465             :                 }
     466         430 :                 EG(current_execute_data) = orig_execute_data;
     467             :         }
     468             : 
     469         463 :         if (op_array->static_variables) {
     470          13 :                 HashTable *stored = zend_shared_alloc_get_xlat_entry(op_array->static_variables);
     471             : 
     472          13 :                 if (stored) {
     473           0 :                         op_array->static_variables = stored;
     474             :                 } else {
     475          13 :                         zend_hash_persist(op_array->static_variables, zend_persist_zval_static);
     476          13 :                         zend_accel_store(op_array->static_variables, sizeof(HashTable));
     477             :                         /* make immutable array */
     478          13 :                         GC_REFCOUNT(op_array->static_variables) = 2;
     479          13 :                         GC_TYPE_INFO(op_array->static_variables) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
     480          13 :                         op_array->static_variables->u.flags |= HASH_FLAG_STATIC_KEYS;
     481          13 :                         op_array->static_variables->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
     482             :                 }
     483             :         }
     484             : 
     485         463 :         if (zend_shared_alloc_get_xlat_entry(op_array->opcodes)) {
     486           0 :                 already_stored = 1;
     487             :         }
     488             : 
     489         463 :         if (op_array->literals) {
     490         463 :                 if (already_stored) {
     491           0 :                         orig_literals = zend_shared_alloc_get_xlat_entry(op_array->literals);
     492             :                         ZEND_ASSERT(orig_literals != NULL);
     493           0 :                         op_array->literals = orig_literals;
     494             :                 } else {
     495         463 :                         zval *p = zend_accel_memdup(op_array->literals, sizeof(zval) * op_array->last_literal);
     496         463 :                         zval *end = p + op_array->last_literal;
     497         463 :                         orig_literals = op_array->literals;
     498         463 :                         op_array->literals = p;
     499        3913 :                         while (p < end) {
     500        2987 :                                 zend_persist_zval(p);
     501        2987 :                                 p++;
     502             :                         }
     503         463 :                         efree(orig_literals);
     504             :                 }
     505             :         }
     506             : 
     507         463 :         if (already_stored) {
     508           0 :                 persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
     509             :                 ZEND_ASSERT(persist_ptr != NULL);
     510           0 :                 op_array->opcodes = persist_ptr;
     511             :         } else {
     512         463 :                 zend_op *new_opcodes = zend_accel_memdup(op_array->opcodes, sizeof(zend_op) * op_array->last);
     513             : #if ZEND_USE_ABS_CONST_ADDR || ZEND_USE_ABS_JMP_ADDR
     514             :                 zend_op *opline = new_opcodes;
     515             :                 zend_op *end = new_opcodes + op_array->last;
     516             :                 int offset = 0;
     517             : 
     518             :                 for (; opline < end ; opline++, offset++) {
     519             : # if ZEND_USE_ABS_CONST_ADDR
     520             :                         if (opline->op1_type == IS_CONST) {
     521             :                                 opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
     522             :                         }
     523             :                         if (opline->op2_type == IS_CONST) {
     524             :                                 opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
     525             :                         }
     526             : # endif
     527             : # if ZEND_USE_ABS_JMP_ADDR
     528             :                         if (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO) {
     529             :                                 /* fix jumps to point to new array */
     530             :                                 switch (opline->opcode) {
     531             :                                         case ZEND_JMP:
     532             :                                         case ZEND_FAST_CALL:
     533             :                                                 opline->op1.jmp_addr = &new_opcodes[opline->op1.jmp_addr - op_array->opcodes];
     534             :                                                 break;
     535             :                                         case ZEND_JMPZNZ:
     536             :                                                 /* relative extended_value don't have to be changed */
     537             :                                                 /* break omitted intentionally */
     538             :                                         case ZEND_JMPZ:
     539             :                                         case ZEND_JMPNZ:
     540             :                                         case ZEND_JMPZ_EX:
     541             :                                         case ZEND_JMPNZ_EX:
     542             :                                         case ZEND_JMP_SET:
     543             :                                         case ZEND_COALESCE:
     544             :                                         case ZEND_NEW:
     545             :                                         case ZEND_FE_RESET_R:
     546             :                                         case ZEND_FE_RESET_RW:
     547             :                                         case ZEND_ASSERT_CHECK:
     548             :                                                 opline->op2.jmp_addr = &new_opcodes[opline->op2.jmp_addr - op_array->opcodes];
     549             :                                                 break;
     550             :                                         case ZEND_DECLARE_ANON_CLASS:
     551             :                                         case ZEND_DECLARE_ANON_INHERITED_CLASS:
     552             :                                         case ZEND_FE_FETCH_R:
     553             :                                         case ZEND_FE_FETCH_RW:
     554             :                                                 /* relative extended_value don't have to be changed */
     555             :                                                 break;
     556             :                                 }
     557             :                         }
     558             : # endif
     559             :                 }
     560             : #endif
     561             : 
     562         463 :                 efree(op_array->opcodes);
     563         463 :                 op_array->opcodes = new_opcodes;
     564             : 
     565         463 :                 if (op_array->run_time_cache) {
     566           0 :                         efree(op_array->run_time_cache);
     567           0 :                         op_array->run_time_cache = NULL;
     568             :                 }
     569             :         }
     570             : 
     571         463 :         if (op_array->function_name && !IS_ACCEL_INTERNED(op_array->function_name)) {
     572             :                 zend_string *new_name;
     573           0 :                 if (already_stored) {
     574           0 :                         new_name = zend_shared_alloc_get_xlat_entry(op_array->function_name);
     575             :                         ZEND_ASSERT(new_name != NULL);
     576           0 :                         op_array->function_name = new_name;
     577             :                 } else {
     578           0 :                         zend_accel_store_string(op_array->function_name);
     579             :                 }
     580             :         }
     581             : 
     582         463 :         if (op_array->filename) {
     583             :                 /* do not free! PHP has centralized filename storage, compiler will free it */
     584         926 :                 zend_accel_memdup_string(op_array->filename);
     585             :         }
     586             : 
     587         463 :         if (op_array->arg_info) {
     588          29 :                 zend_arg_info *arg_info = op_array->arg_info;
     589          29 :                 uint32_t num_args = op_array->num_args;
     590             : 
     591          29 :                 if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
     592           4 :                         arg_info--;
     593           4 :                         num_args++;
     594             :                 }
     595          29 :                 if (already_stored) {
     596           0 :                         arg_info = zend_shared_alloc_get_xlat_entry(arg_info);
     597             :                         ZEND_ASSERT(arg_info != NULL);
     598             :                 } else {
     599             :                         uint32_t i;
     600             : 
     601          29 :                         if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
     602           0 :                                 num_args++;
     603             :                         }
     604          29 :                         zend_accel_store(arg_info, sizeof(zend_arg_info) * num_args);
     605          63 :                         for (i = 0; i < num_args; i++) {
     606          34 :                                 if (arg_info[i].name) {
     607          30 :                                         zend_accel_store_interned_string(arg_info[i].name);
     608             :                                 }
     609          34 :                                 if (arg_info[i].class_name) {
     610           4 :                                         zend_accel_store_interned_string(arg_info[i].class_name);
     611             :                                 }
     612             :                         }
     613             :                 }
     614          29 :                 if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
     615           4 :                         arg_info++;
     616             :                 }
     617          29 :                 op_array->arg_info = arg_info;
     618             :         }
     619             : 
     620         463 :         if (op_array->live_range) {
     621          71 :                 zend_accel_store(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
     622             :         }
     623             : 
     624         463 :         if (op_array->scope) {
     625           9 :                 op_array->scope = zend_shared_alloc_get_xlat_entry(op_array->scope);
     626             :         }
     627             : 
     628         463 :         if (op_array->doc_comment) {
     629           0 :                 if (ZCG(accel_directives).save_comments) {
     630           0 :                         if (already_stored) {
     631           0 :                                 op_array->doc_comment = zend_shared_alloc_get_xlat_entry(op_array->doc_comment);
     632             :                                 ZEND_ASSERT(op_array->doc_comment != NULL);
     633             :                         } else {
     634           0 :                                 zend_accel_store_string(op_array->doc_comment);
     635             :                         }
     636             :                 } else {
     637           0 :                         if (!already_stored) {
     638           0 :                                 zend_string_release(op_array->doc_comment);
     639             :                         }
     640           0 :                         op_array->doc_comment = NULL;
     641             :                 }
     642             :         }
     643             : 
     644         463 :         if (op_array->try_catch_array) {
     645           8 :                 zend_accel_store(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
     646             :         }
     647             : 
     648         463 :         if (op_array->vars) {
     649          72 :                 if (already_stored) {
     650           0 :                         persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->vars);
     651             :                         ZEND_ASSERT(persist_ptr != NULL);
     652           0 :                         op_array->vars = (zend_string**)persist_ptr;
     653             :                 } else {
     654             :                         int i;
     655          72 :                         zend_accel_store(op_array->vars, sizeof(zend_string*) * op_array->last_var);
     656         241 :                         for (i = 0; i < op_array->last_var; i++) {
     657         169 :                                 zend_accel_store_interned_string(op_array->vars[i]);
     658             :                         }
     659             :                 }
     660             :         }
     661             : 
     662             :         /* "prototype" may be undefined if "scope" isn't set */
     663         465 :         if (op_array->scope && op_array->prototype) {
     664           2 :                 if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) {
     665           2 :                         op_array->prototype = (union _zend_function*)persist_ptr;
     666             :                 }
     667             :         } else {
     668         461 :                 op_array->prototype = NULL;
     669             :         }
     670             : 
     671         463 :         ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist(op_array, ZCG(mem))));
     672             : }
     673             : 
     674          33 : static void zend_persist_op_array(zval *zv)
     675             : {
     676          33 :         zend_op_array *op_array = Z_PTR_P(zv);
     677          33 :         zend_op_array *old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
     678          33 :         if (old_op_array) {
     679           0 :                 Z_PTR_P(zv) = old_op_array;
     680           0 :                 if (op_array->refcount && --(*op_array->refcount) == 0) {
     681           0 :                         efree(op_array->refcount);
     682             :                 }
     683           0 :                 return;
     684             :         }
     685          33 :         memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_op_array));
     686          33 :         zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
     687          33 :         Z_PTR_P(zv) = ZCG(arena_mem);
     688          33 :         ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_op_array)));
     689          33 :         zend_persist_op_array_ex(Z_PTR_P(zv), NULL);
     690             : }
     691             : 
     692           2 : static void zend_persist_property_info(zval *zv)
     693             : {
     694           2 :         zend_property_info *prop = zend_shared_alloc_get_xlat_entry(Z_PTR_P(zv));
     695             : 
     696           2 :         if (prop) {
     697           0 :                 Z_PTR_P(zv) = prop;
     698           0 :                 return;
     699             :         }
     700           2 :         memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_property_info));
     701           2 :         zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
     702           2 :         prop = Z_PTR_P(zv) = ZCG(arena_mem);
     703           2 :         ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_property_info)));
     704           2 :         prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce);
     705           2 :         zend_accel_store_interned_string(prop->name);
     706           2 :         if (prop->doc_comment) {
     707           0 :                 if (ZCG(accel_directives).save_comments) {
     708           0 :                         zend_accel_store_string(prop->doc_comment);
     709             :                 } else {
     710           0 :                         if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
     711           0 :                                 zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
     712             :                         }
     713           0 :                         zend_string_release(prop->doc_comment);
     714           0 :                         prop->doc_comment = NULL;
     715             :                 }
     716             :         }
     717             : }
     718             : 
     719           5 : static void zend_persist_class_constant(zval *zv)
     720             : {
     721           5 :         zend_class_constant *c = zend_shared_alloc_get_xlat_entry(Z_PTR_P(zv));
     722             : 
     723           5 :         if (c) {
     724           0 :                 Z_PTR_P(zv) = c;
     725           0 :                 return;
     726             :         }
     727           5 :         memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_class_constant));
     728           5 :         zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
     729           5 :         c = Z_PTR_P(zv) = ZCG(arena_mem);
     730           5 :         ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_class_constant)));
     731           5 :         zend_persist_zval(&c->value);
     732           5 :         c->ce = zend_shared_alloc_get_xlat_entry(c->ce);
     733           5 :         if (c->doc_comment) {
     734           0 :                 if (ZCG(accel_directives).save_comments) {
     735           0 :                         zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
     736           0 :                         if (doc_comment) {
     737           0 :                                 c->doc_comment = doc_comment;
     738             :                         } else {
     739           0 :                                 zend_accel_store_string(c->doc_comment);
     740             :                         }
     741             :                 } else {
     742           0 :                         zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
     743           0 :                         if (!doc_comment) {
     744           0 :                                 zend_shared_alloc_register_xlat_entry(c->doc_comment, c->doc_comment);
     745           0 :                                 zend_string_release(c->doc_comment);
     746             :                         }
     747           0 :                         c->doc_comment = NULL;
     748             :                 }
     749             :         }
     750             : }
     751             : 
     752           7 : static void zend_persist_class_entry(zval *zv)
     753             : {
     754           7 :         zend_class_entry *ce = Z_PTR_P(zv);
     755             : 
     756           7 :         if (ce->type == ZEND_USER_CLASS) {
     757           7 :                 memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_class_entry));
     758           7 :                 zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
     759           7 :                 ce = Z_PTR_P(zv) = ZCG(arena_mem);
     760           7 :                 ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_class_entry)));
     761           7 :                 zend_accel_store_interned_string(ce->name);
     762           7 :                 zend_hash_persist(&ce->function_table, zend_persist_op_array);
     763           7 :                 if (ce->default_properties_table) {
     764             :                     int i;
     765             : 
     766           0 :                         zend_accel_store(ce->default_properties_table, sizeof(zval) * ce->default_properties_count);
     767           0 :                         for (i = 0; i < ce->default_properties_count; i++) {
     768           0 :                                 zend_persist_zval(&ce->default_properties_table[i]);
     769             :                         }
     770             :                 }
     771           7 :                 if (ce->default_static_members_table) {
     772             :                     int i;
     773             : 
     774           1 :                         zend_accel_store(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count);
     775           3 :                         for (i = 0; i < ce->default_static_members_count; i++) {
     776           2 :                                 zend_persist_zval(&ce->default_static_members_table[i]);
     777             :                         }
     778             :                 }
     779           7 :                 ce->static_members_table = NULL;
     780             : 
     781           7 :                 zend_hash_persist(&ce->constants_table, zend_persist_class_constant);
     782             : 
     783           7 :                 if (ce->info.user.filename) {
     784             :                         /* do not free! PHP has centralized filename storage, compiler will free it */
     785          14 :                         zend_accel_memdup_string(ce->info.user.filename);
     786             :                 }
     787           7 :                 if (ce->info.user.doc_comment) {
     788           0 :                         if (ZCG(accel_directives).save_comments) {
     789           0 :                                 zend_accel_store_string(ce->info.user.doc_comment);
     790             :                         } else {
     791           0 :                                 if (!zend_shared_alloc_get_xlat_entry(ce->info.user.doc_comment)) {
     792           0 :                                         zend_shared_alloc_register_xlat_entry(ce->info.user.doc_comment, ce->info.user.doc_comment);
     793           0 :                                         zend_string_release(ce->info.user.doc_comment);
     794             :                                 }
     795           0 :                                 ce->info.user.doc_comment = NULL;
     796             :                         }
     797             :                 }
     798           7 :                 zend_hash_persist(&ce->properties_info, zend_persist_property_info);
     799           7 :                 if (ce->num_interfaces && ce->interfaces) {
     800           0 :                         efree(ce->interfaces);
     801             :                 }
     802           7 :                 ce->interfaces = NULL; /* will be filled in on fetch */
     803             : 
     804           7 :                 if (ce->num_traits && ce->traits) {
     805           0 :                         efree(ce->traits);
     806             :                 }
     807           7 :                 ce->traits = NULL;
     808             : 
     809           7 :                 if (ce->trait_aliases) {
     810           0 :                         int i = 0;
     811           0 :                         while (ce->trait_aliases[i]) {
     812           0 :                                 if (ce->trait_aliases[i]->trait_method) {
     813           0 :                                         if (ce->trait_aliases[i]->trait_method->method_name) {
     814           0 :                                                 zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method->method_name);
     815             :                                         }
     816           0 :                                         if (ce->trait_aliases[i]->trait_method->class_name) {
     817           0 :                                                 zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method->class_name);
     818             :                                         }
     819           0 :                                         ce->trait_aliases[i]->trait_method->ce = NULL;
     820           0 :                                         zend_accel_store(ce->trait_aliases[i]->trait_method,
     821             :                                                 sizeof(zend_trait_method_reference));
     822             :                                 }
     823             : 
     824           0 :                                 if (ce->trait_aliases[i]->alias) {
     825           0 :                                         zend_accel_store_interned_string(ce->trait_aliases[i]->alias);
     826             :                                 }
     827             : 
     828           0 :                                 zend_accel_store(ce->trait_aliases[i], sizeof(zend_trait_alias));
     829           0 :                                 i++;
     830             :                         }
     831             : 
     832           0 :                         zend_accel_store(ce->trait_aliases, sizeof(zend_trait_alias*) * (i + 1));
     833             :                 }
     834             : 
     835           7 :                 if (ce->trait_precedences) {
     836           0 :                         int i = 0;
     837             : 
     838           0 :                         while (ce->trait_precedences[i]) {
     839           0 :                                 zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method->method_name);
     840           0 :                                 zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method->class_name);
     841           0 :                                 ce->trait_precedences[i]->trait_method->ce = NULL;
     842           0 :                                 zend_accel_store(ce->trait_precedences[i]->trait_method,
     843             :                                         sizeof(zend_trait_method_reference));
     844             : 
     845           0 :                                 if (ce->trait_precedences[i]->exclude_from_classes) {
     846           0 :                                         int j = 0;
     847             : 
     848           0 :                                         while (ce->trait_precedences[i]->exclude_from_classes[j].class_name) {
     849           0 :                                                 zend_accel_store_interned_string(ce->trait_precedences[i]->exclude_from_classes[j].class_name);
     850           0 :                                                 j++;
     851             :                                         }
     852           0 :                                         zend_accel_store(ce->trait_precedences[i]->exclude_from_classes,
     853             :                                                 sizeof(zend_class_entry*) * (j + 1));
     854             :                                 }
     855             : 
     856           0 :                                 zend_accel_store(ce->trait_precedences[i], sizeof(zend_trait_precedence));
     857           0 :                                 i++;
     858             :                         }
     859           0 :                         zend_accel_store(
     860             :                                 ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
     861             :                 }
     862             :         }
     863           7 : }
     864             : 
     865             : //static int zend_update_property_info_ce(zval *zv)
     866             : //{
     867             : //      zend_property_info *prop = Z_PTR_P(zv);
     868             : //
     869             : //      prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce);
     870             : //      return 0;
     871             : //}
     872             : 
     873           7 : static int zend_update_parent_ce(zval *zv)
     874             : {
     875           7 :         zend_class_entry *ce = Z_PTR_P(zv);
     876             : 
     877           7 :         if (ce->parent) {
     878           3 :                 ce->parent = zend_shared_alloc_get_xlat_entry(ce->parent);
     879             :         }
     880             : 
     881             :         /* update methods */
     882           7 :         if (ce->constructor) {
     883           0 :                 ce->constructor = zend_shared_alloc_get_xlat_entry(ce->constructor);
     884             :         }
     885           7 :         if (ce->destructor) {
     886           0 :                 ce->destructor = zend_shared_alloc_get_xlat_entry(ce->destructor);
     887             :         }
     888           7 :         if (ce->clone) {
     889           0 :                 ce->clone = zend_shared_alloc_get_xlat_entry(ce->clone);
     890             :         }
     891           7 :         if (ce->__get) {
     892           0 :                 ce->__get = zend_shared_alloc_get_xlat_entry(ce->__get);
     893             :         }
     894           7 :         if (ce->__set) {
     895           0 :                 ce->__set = zend_shared_alloc_get_xlat_entry(ce->__set);
     896             :         }
     897           7 :         if (ce->__call) {
     898           0 :                 ce->__call = zend_shared_alloc_get_xlat_entry(ce->__call);
     899             :         }
     900           7 :         if (ce->serialize_func) {
     901           0 :                 ce->serialize_func = zend_shared_alloc_get_xlat_entry(ce->serialize_func);
     902             :         }
     903           7 :         if (ce->unserialize_func) {
     904           0 :                 ce->unserialize_func = zend_shared_alloc_get_xlat_entry(ce->unserialize_func);
     905             :         }
     906           7 :         if (ce->__isset) {
     907           0 :                 ce->__isset = zend_shared_alloc_get_xlat_entry(ce->__isset);
     908             :         }
     909           7 :         if (ce->__unset) {
     910           0 :                 ce->__unset = zend_shared_alloc_get_xlat_entry(ce->__unset);
     911             :         }
     912           7 :         if (ce->__tostring) {
     913           0 :                 ce->__tostring = zend_shared_alloc_get_xlat_entry(ce->__tostring);
     914             :         }
     915           7 :         if (ce->__callstatic) {
     916           0 :                 ce->__callstatic = zend_shared_alloc_get_xlat_entry(ce->__callstatic);
     917             :         }
     918           7 :         if (ce->__debugInfo) {
     919           0 :                 ce->__debugInfo = zend_shared_alloc_get_xlat_entry(ce->__debugInfo);
     920             :         }
     921             : //      zend_hash_apply(&ce->properties_info, (apply_func_t) zend_update_property_info_ce);
     922           7 :         return 0;
     923             : }
     924             : 
     925         430 : static void zend_accel_persist_class_table(HashTable *class_table)
     926             : {
     927         430 :     zend_hash_persist(class_table, zend_persist_class_entry);
     928         430 :         zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce);
     929         430 : }
     930             : 
     931         430 : zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length)
     932             : {
     933         430 :         script->mem = ZCG(mem);
     934             : 
     935             :         ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     936         430 :         zend_shared_alloc_clear_xlat_table();
     937             : 
     938         430 :         zend_accel_store(script, sizeof(zend_persistent_script));
     939         430 :         if (key && *key) {
     940         430 :                 *key = zend_accel_memdup(*key, key_length + 1);
     941             :         }
     942        1290 :         zend_accel_store_string(script->script.filename);
     943             : 
     944             : #ifdef __SSE2__
     945             :         /* Align to 64-byte boundary */
     946         430 :         ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 63L) & ~63L);
     947             : #else
     948             :         ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
     949             : #endif
     950             : 
     951         430 :         script->arena_mem = ZCG(arena_mem) = ZCG(mem);
     952         430 :         ZCG(mem) = (void*)((char*)ZCG(mem) + script->arena_size);
     953             : 
     954         430 :         zend_accel_persist_class_table(&script->script.class_table);
     955         430 :         zend_hash_persist(&script->script.function_table, zend_persist_op_array);
     956         430 :         zend_persist_op_array_ex(&script->script.main_op_array, script);
     957             : 
     958         430 :         return script;
     959             : }
     960             : 
     961         430 : int zend_accel_script_persistable(zend_persistent_script *script)
     962             : {
     963         430 :         return 1;
     964             : }

Generated by: LCOV version 1.10

Generated at Fri, 01 Jul 2016 16:15:13 +0000 (6 hours ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.