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: 0 301 0.0 %
Date: 2014-04-16 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend OPcache                                                         |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 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 TSRMLS_CC))
      33             : #define zend_accel_memdup(p, size) \
      34             :             _zend_shared_memdup((void*)p, size, 0 TSRMLS_CC)
      35             : 
      36             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      37             : # define zend_accel_memdup_interned_string(str, len) \
      38             :         IS_INTERNED(str) ? str : zend_accel_memdup(str, len)
      39             : 
      40             : # define zend_accel_store_interned_string(str, len) do { \
      41             :                 if (!IS_INTERNED(str)) { zend_accel_store(str, len); } \
      42             :         } while (0)
      43             : #else
      44             : # define zend_accel_memdup_interned_string(str, len) \
      45             :         zend_accel_memdup(str, len)
      46             : 
      47             : # define zend_accel_store_interned_string(str, len) \
      48             :         zend_accel_store(str, len)
      49             : #endif
      50             : 
      51             : typedef void (*zend_persist_func_t)(void * TSRMLS_DC);
      52             : 
      53             : static void zend_persist_zval_ptr(zval **zp TSRMLS_DC);
      54             : static void zend_persist_zval(zval *z TSRMLS_DC);
      55             : 
      56             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      57             : static const Bucket *uninitialized_bucket = NULL;
      58             : #endif
      59             : 
      60           0 : static void zend_hash_persist(HashTable *ht, void (*pPersistElement)(void *pElement TSRMLS_DC), size_t el_size TSRMLS_DC)
      61             : {
      62           0 :         Bucket *p = ht->pListHead;
      63             :         uint i;
      64             : 
      65           0 :         while (p) {
      66           0 :                 Bucket *q = p;
      67             : 
      68             :                 /* persist bucket and key */
      69             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      70           0 :                 p = zend_accel_memdup(p, sizeof(Bucket));
      71           0 :                 if (p->nKeyLength) {
      72           0 :                         p->arKey = zend_accel_memdup_interned_string(p->arKey, p->nKeyLength);
      73             :                 }
      74             : #else
      75             :                 p = zend_accel_memdup(p, sizeof(Bucket) - 1 + p->nKeyLength);
      76             : #endif
      77             : 
      78             :                 /* persist data pointer in bucket */
      79           0 :                 if (!p->pDataPtr) {
      80           0 :                         zend_accel_store(p->pData, el_size);
      81             :                 } else {
      82             :                         /* Update p->pData to point to the new p->pDataPtr address, after the bucket relocation */
      83           0 :                         p->pData = &p->pDataPtr;
      84             :                 }
      85             : 
      86             :                 /* persist the data itself */
      87           0 :                 if (pPersistElement) {
      88           0 :                         pPersistElement(p->pData TSRMLS_CC);
      89             :                 }
      90             : 
      91             :                 /* update linked lists */
      92           0 :                 if (p->pLast) {
      93           0 :                         p->pLast->pNext = p;
      94             :                 }
      95           0 :                 if (p->pNext) {
      96           0 :                         p->pNext->pLast = p;
      97             :                 }
      98           0 :                 if (p->pListLast) {
      99           0 :                         p->pListLast->pListNext = p;
     100             :                 }
     101           0 :                 if (p->pListNext) {
     102           0 :                         p->pListNext->pListLast = p;
     103             :                 }
     104             : 
     105           0 :                 p = p->pListNext;
     106             : 
     107             :                 /* delete the old non-persistent bucket */
     108           0 :                 efree(q);
     109             :         }
     110             : 
     111             :         /* update linked lists */
     112           0 :         if (ht->pListHead) {
     113           0 :                 ht->pListHead = zend_shared_alloc_get_xlat_entry(ht->pListHead);
     114             :         }
     115           0 :         if (ht->pListTail) {
     116           0 :                 ht->pListTail = zend_shared_alloc_get_xlat_entry(ht->pListTail);
     117             :         }
     118           0 :         if (ht->pInternalPointer) {
     119           0 :                 ht->pInternalPointer = zend_shared_alloc_get_xlat_entry(ht->pInternalPointer);
     120             :         }
     121             : 
     122             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     123             :         /* Check if HastTable is initialized */
     124           0 :         if (ht->nTableMask) {
     125             : #endif
     126           0 :                 if (ht->nNumOfElements) {
     127             :                         /* update hash table */
     128           0 :                         for (i = 0; i < ht->nTableSize; i++) {
     129           0 :                                 if (ht->arBuckets[i]) {
     130           0 :                                         ht->arBuckets[i] = zend_shared_alloc_get_xlat_entry(ht->arBuckets[i]);
     131             :                                 }
     132             :                         }
     133             :                 }
     134           0 :                 zend_accel_store(ht->arBuckets, sizeof(Bucket*) * ht->nTableSize);
     135             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     136             :         } else {
     137           0 :                 ht->arBuckets = (Bucket**)&uninitialized_bucket;
     138             :         }
     139             : #endif
     140           0 : }
     141             : 
     142             : #if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
     143           0 : static zend_ast *zend_persist_ast(zend_ast *ast TSRMLS_DC)
     144             : {
     145             :         int i;
     146             :         zend_ast *node;
     147             : 
     148           0 :         if (ast->kind == ZEND_CONST) {
     149           0 :                 node = zend_accel_memdup(ast, sizeof(zend_ast) + sizeof(zval));
     150           0 :                 node->u.val = (zval*)(node + 1);
     151           0 :                 zend_persist_zval(node->u.val TSRMLS_CC);
     152             :         } else {
     153           0 :                 node = zend_accel_memdup(ast, sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
     154           0 :                 for (i = 0; i < ast->children; i++) {
     155           0 :                         if ((&node->u.child)[i]) {
     156           0 :                                 (&node->u.child)[i] = zend_persist_ast((&node->u.child)[i] TSRMLS_CC);
     157             :                         }
     158             :                 }
     159             :         }
     160           0 :         efree(ast);
     161           0 :         return node;
     162             : }
     163             : #endif
     164             : 
     165           0 : static void zend_persist_zval(zval *z TSRMLS_DC)
     166             : {
     167             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     168           0 :         switch (z->type & IS_CONSTANT_TYPE_MASK) {
     169             : #else
     170             :         switch (z->type & ~IS_CONSTANT_INDEX) {
     171             : #endif
     172             :                 case IS_STRING:
     173             :                 case IS_CONSTANT:
     174           0 :                         zend_accel_store_interned_string(z->value.str.val, z->value.str.len + 1);
     175           0 :                         break;
     176             :                 case IS_ARRAY:
     177             : #if ZEND_EXTENSION_API_NO <= PHP_5_5_API_NO
     178             :                 case IS_CONSTANT_ARRAY:
     179             : #endif
     180           0 :                         zend_accel_store(z->value.ht, sizeof(HashTable));
     181           0 :                         zend_hash_persist(z->value.ht, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
     182           0 :                         break;
     183             : #if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
     184             :                 case IS_CONSTANT_AST:
     185           0 :                         Z_AST_P(z) = zend_persist_ast(Z_AST_P(z) TSRMLS_CC);
     186             :                         break;
     187             : #endif
     188             :         }
     189           0 : }
     190             : 
     191           0 : static void zend_persist_zval_ptr(zval **zp TSRMLS_DC)
     192             : {
     193           0 :         zval *new_ptr = zend_shared_alloc_get_xlat_entry(*zp);
     194             : 
     195           0 :         if (new_ptr) {
     196           0 :                 *zp = new_ptr;
     197             :         } else {
     198             :                 /* Attempt to store only if we didn't store this zval_ptr yet */
     199           0 :                 zend_accel_store(*zp, sizeof(zval));
     200           0 :                 zend_persist_zval(*zp TSRMLS_CC);
     201             :         }
     202           0 : }
     203             : 
     204           0 : static void zend_protect_zval(zval *z TSRMLS_DC)
     205             : {
     206             :         PZ_SET_ISREF_P(z);
     207           0 :         PZ_SET_REFCOUNT_P(z, 2);
     208           0 : }
     209             : 
     210           0 : static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_script* main_persistent_script TSRMLS_DC)
     211             : {
     212             :         zend_op *persist_ptr;
     213             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     214             :         int has_jmp = 0;
     215             : #endif
     216             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     217           0 :         zend_literal *orig_literals = NULL;
     218             : #endif
     219             : 
     220           0 :         if (op_array->type != ZEND_USER_FUNCTION) {
     221           0 :                 return;
     222             :         }
     223             : 
     224             : #if ZEND_EXTENSION_API_NO <= PHP_5_3_X_API_NO
     225             :         op_array->size = op_array->last;
     226             : #endif
     227             : 
     228           0 :         if (--(*op_array->refcount) == 0) {
     229           0 :                 efree(op_array->refcount);
     230             :         }
     231           0 :         op_array->refcount = NULL;
     232             : 
     233           0 :         if (op_array->filename) {
     234             :                 /* do not free! PHP has centralized filename storage, compiler will free it */
     235           0 :                 op_array->filename = zend_accel_memdup(op_array->filename, strlen(op_array->filename) + 1);
     236             :         }
     237             : 
     238           0 :         if (main_persistent_script) {
     239           0 :                 zend_bool orig_in_execution = EG(in_execution);
     240           0 :                 zend_op_array *orig_op_array = EG(active_op_array);
     241             :                 zval offset;
     242             : 
     243             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     244             :                 main_persistent_script->early_binding = -1;
     245             : #endif
     246           0 :                 EG(in_execution) = 1;
     247           0 :                 EG(active_op_array) = op_array;
     248           0 :                 if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &offset TSRMLS_CC)) {
     249           0 :                         main_persistent_script->compiler_halt_offset = Z_LVAL(offset);
     250             :                 }
     251           0 :                 EG(active_op_array) = orig_op_array;
     252           0 :                 EG(in_execution) = orig_in_execution;
     253             :         }
     254             : 
     255             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     256           0 :         if (op_array->literals) {
     257           0 :                 orig_literals = zend_shared_alloc_get_xlat_entry(op_array->literals);
     258           0 :                 if (orig_literals) {
     259           0 :                         op_array->literals = orig_literals;
     260             :                 } else {
     261           0 :                         zend_literal *p = zend_accel_memdup(op_array->literals, sizeof(zend_literal) * op_array->last_literal);
     262           0 :                         zend_literal *end = p + op_array->last_literal;
     263           0 :                         orig_literals = op_array->literals;
     264           0 :                         op_array->literals = p;
     265           0 :                         while (p < end) {
     266           0 :                                 zend_persist_zval(&p->constant TSRMLS_CC);
     267           0 :                                 zend_protect_zval(&p->constant TSRMLS_CC);
     268           0 :                                 p++;
     269             :                         }
     270           0 :                         efree(orig_literals);
     271             :                 }
     272             :         }
     273             : #endif
     274             : 
     275           0 :         if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->opcodes))) {
     276           0 :                 op_array->opcodes = persist_ptr;
     277             :         } else {
     278           0 :                 zend_op *new_opcodes = zend_accel_memdup(op_array->opcodes, sizeof(zend_op) * op_array->last);
     279           0 :                 zend_op *opline = new_opcodes;
     280           0 :                 zend_op *end = new_opcodes + op_array->last;
     281           0 :                 int offset = 0;
     282             : 
     283           0 :                 for (; opline < end ; opline++, offset++) {
     284           0 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST) {
     285             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     286           0 :                                 opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
     287             : #else
     288             :                                 zend_persist_zval(&opline->op1.u.constant TSRMLS_CC);
     289             :                                 zend_protect_zval(&opline->op1.u.constant TSRMLS_CC);
     290             : #endif
     291             :                         }
     292           0 :                         if (ZEND_OP2_TYPE(opline) == IS_CONST) {
     293             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     294           0 :                                 opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
     295             : #else
     296             :                                 zend_persist_zval(&opline->op2.u.constant TSRMLS_CC);
     297             :                                 zend_protect_zval(&opline->op2.u.constant TSRMLS_CC);
     298             : #endif
     299             :                         }
     300             : 
     301             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     302             :                         switch (opline->opcode) {
     303             :                                 case ZEND_JMP:
     304             :                                         has_jmp = 1;
     305             :                                         if (ZEND_DONE_PASS_TWO(op_array)) {
     306             :                                                 ZEND_OP1(opline).jmp_addr = &new_opcodes[ZEND_OP1(opline).jmp_addr - op_array->opcodes];
     307             :                                         }
     308             :                                         break;
     309             :                                 case ZEND_JMPZ:
     310             :                                 case ZEND_JMPNZ:
     311             :                                 case ZEND_JMPZ_EX:
     312             :                                 case ZEND_JMPNZ_EX:
     313             :                                         has_jmp = 1;
     314             :                                         if (ZEND_DONE_PASS_TWO(op_array)) {
     315             :                                                 ZEND_OP2(opline).jmp_addr = &new_opcodes[ZEND_OP2(opline).jmp_addr - op_array->opcodes];
     316             :                                         }
     317             :                                         break;
     318             :                                 case ZEND_JMPZNZ:
     319             :                                 case ZEND_BRK:
     320             :                                 case ZEND_CONT:
     321             :                                         has_jmp = 1;
     322             :                                         break;
     323             :                                 case ZEND_DECLARE_INHERITED_CLASS:
     324             :                                         if (main_persistent_script && ZCG(accel_directives).inherited_hack) {
     325             :                                         if (!has_jmp &&
     326             :                                            ((opline + 2) >= end ||
     327             :                                             (opline + 1)->opcode != ZEND_FETCH_CLASS ||
     328             :                                             (opline + 2)->opcode != ZEND_ADD_INTERFACE)) {
     329             : 
     330             :                                                 zend_uint *opline_num = &main_persistent_script->early_binding;
     331             : 
     332             :                                                 while ((int)*opline_num != -1) {
     333             :                                                         opline_num = &new_opcodes[*opline_num].result.u.opline_num;
     334             :                                                 }
     335             :                                                 *opline_num = opline - new_opcodes;
     336             :                                                 opline->result.op_type = IS_UNUSED;
     337             :                                                 opline->result.u.opline_num = -1;
     338             :                                                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS_DELAYED;
     339             :                                                 ZEND_VM_SET_OPCODE_HANDLER(opline);
     340             :                                         }
     341             :                                         break;
     342             :                                 }
     343             :                         }
     344             : 
     345             : #else /* if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO */
     346             : 
     347           0 :                         if (ZEND_DONE_PASS_TWO(op_array)) {
     348             :                                 /* fix jumps to point to new array */
     349           0 :                                 switch (opline->opcode) {
     350             :                                         case ZEND_JMP:
     351             :                                         case ZEND_GOTO:
     352             : #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
     353             :                                         case ZEND_FAST_CALL:
     354             : #endif
     355           0 :                                                 ZEND_OP1(opline).jmp_addr = &new_opcodes[ZEND_OP1(opline).jmp_addr - op_array->opcodes];
     356           0 :                                                 break;
     357             :                                         case ZEND_JMPZ:
     358             :                                         case ZEND_JMPNZ:
     359             :                                         case ZEND_JMPZ_EX:
     360             :                                         case ZEND_JMPNZ_EX:
     361             :                                         case ZEND_JMP_SET:
     362             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     363             :                                         case ZEND_JMP_SET_VAR:
     364             : #endif
     365           0 :                                                 ZEND_OP2(opline).jmp_addr = &new_opcodes[ZEND_OP2(opline).jmp_addr - op_array->opcodes];
     366             :                                                 break;
     367             :                                 }
     368             :                         }
     369             : #endif /* if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO */
     370             :                 }
     371             : 
     372           0 :                 efree(op_array->opcodes);
     373           0 :                 op_array->opcodes = new_opcodes;
     374             : 
     375             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     376           0 :                 if (op_array->run_time_cache) {
     377           0 :                         efree(op_array->run_time_cache);
     378           0 :                         op_array->run_time_cache = NULL;
     379             :                 }
     380             : #endif
     381             :         }
     382             : 
     383           0 :         if (op_array->function_name) {
     384             :                 char *new_name;
     385           0 :                 if ((new_name = zend_shared_alloc_get_xlat_entry(op_array->function_name))) {
     386           0 :                         op_array->function_name = new_name;
     387             :                 } else {
     388           0 :                         zend_accel_store(op_array->function_name, strlen(op_array->function_name) + 1);
     389             :                 }
     390             :         }
     391             : 
     392           0 :         if (op_array->arg_info) {
     393             :                 zend_arg_info *new_ptr;
     394           0 :                 if ((new_ptr = zend_shared_alloc_get_xlat_entry(op_array->arg_info))) {
     395           0 :                         op_array->arg_info = new_ptr;
     396             :                 } else {
     397             :                         zend_uint i;
     398             : 
     399           0 :                         zend_accel_store(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
     400           0 :                         for (i = 0; i < op_array->num_args; i++) {
     401           0 :                                 if (op_array->arg_info[i].name) {
     402           0 :                                         zend_accel_store_interned_string(op_array->arg_info[i].name, op_array->arg_info[i].name_len + 1);
     403             :                                 }
     404           0 :                                 if (op_array->arg_info[i].class_name) {
     405           0 :                                         zend_accel_store_interned_string(op_array->arg_info[i].class_name, op_array->arg_info[i].class_name_len + 1);
     406             :                                 }
     407             :                         }
     408             :                 }
     409             :         }
     410             : 
     411           0 :         if (op_array->brk_cont_array) {
     412           0 :                 zend_accel_store(op_array->brk_cont_array, sizeof(zend_brk_cont_element) * op_array->last_brk_cont);
     413             :         }
     414             : 
     415           0 :         if (op_array->static_variables) {
     416           0 :                 zend_hash_persist(op_array->static_variables, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
     417           0 :                 zend_accel_store(op_array->static_variables, sizeof(HashTable));
     418             :         }
     419             : 
     420           0 :         if (op_array->scope) {
     421           0 :                 op_array->scope = zend_shared_alloc_get_xlat_entry(op_array->scope);
     422             :         }
     423             : 
     424           0 :         if (op_array->doc_comment) {
     425           0 :                 if (ZCG(accel_directives).save_comments) {
     426           0 :                         zend_accel_store(op_array->doc_comment, op_array->doc_comment_len + 1);
     427             :                 } else {
     428           0 :                         if (!zend_shared_alloc_get_xlat_entry(op_array->doc_comment)) {
     429           0 :                                 zend_shared_alloc_register_xlat_entry(op_array->doc_comment, op_array->doc_comment);
     430           0 :                                 efree((char*)op_array->doc_comment);
     431             :                         }
     432           0 :                         op_array->doc_comment = NULL;
     433           0 :                         op_array->doc_comment_len = 0;
     434             :                 }
     435             :         }
     436             : 
     437           0 :         if (op_array->try_catch_array) {
     438           0 :                 zend_accel_store(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
     439             :         }
     440             : 
     441           0 :         if (op_array->vars) {
     442           0 :                 if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->vars))) {
     443           0 :                         op_array->vars = (zend_compiled_variable*)persist_ptr;
     444             :                 } else {
     445             :                         int i;
     446           0 :                         zend_accel_store(op_array->vars, sizeof(zend_compiled_variable) * op_array->last_var);
     447           0 :                         for (i = 0; i < op_array->last_var; i++) {
     448           0 :                                 zend_accel_store_interned_string(op_array->vars[i].name, op_array->vars[i].name_len + 1);
     449             :                         }
     450             :                 }
     451             :         }
     452             : 
     453             :         /* "prototype" may be undefined if "scope" isn't set */
     454           0 :         if (op_array->scope && op_array->prototype) {
     455           0 :                 if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) {
     456           0 :                         op_array->prototype = (union _zend_function*)persist_ptr;
     457             :                         /* we use refcount to show that op_array is referenced from several places */
     458           0 :                         op_array->prototype->op_array.refcount++;
     459             :                 }
     460             :         } else {
     461           0 :                 op_array->prototype = NULL;
     462             :         }
     463             : }
     464             : 
     465           0 : static void zend_persist_op_array(zend_op_array *op_array TSRMLS_DC)
     466             : {
     467           0 :         zend_persist_op_array_ex(op_array, NULL TSRMLS_CC);
     468           0 : }
     469             : 
     470           0 : static void zend_persist_property_info(zend_property_info *prop TSRMLS_DC)
     471             : {
     472           0 :         zend_accel_store_interned_string(prop->name, prop->name_length + 1);
     473           0 :         if (prop->doc_comment) {
     474           0 :                 if (ZCG(accel_directives).save_comments) {
     475           0 :                         zend_accel_store(prop->doc_comment, prop->doc_comment_len + 1);
     476             :                 } else {
     477           0 :                         if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
     478           0 :                                 zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
     479           0 :                                 efree((char*)prop->doc_comment);
     480             :                         }
     481           0 :                         prop->doc_comment = NULL;
     482           0 :                         prop->doc_comment_len = 0;
     483             :                 }
     484             :         }
     485           0 : }
     486             : 
     487           0 : static void zend_persist_class_entry(zend_class_entry **pce TSRMLS_DC)
     488             : {
     489           0 :         zend_class_entry *ce = *pce;
     490             : 
     491           0 :         if (ce->type == ZEND_USER_CLASS) {
     492           0 :                 *pce = zend_accel_store(ce, sizeof(zend_class_entry));
     493           0 :                 zend_accel_store_interned_string(ce->name, ce->name_length + 1);
     494           0 :                 zend_hash_persist(&ce->function_table, (zend_persist_func_t) zend_persist_op_array, sizeof(zend_op_array) TSRMLS_CC);
     495             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     496           0 :                 if (ce->default_properties_table) {
     497             :                     int i;
     498             : 
     499           0 :                         zend_accel_store(ce->default_properties_table, sizeof(zval*) * ce->default_properties_count);
     500           0 :                         for (i = 0; i < ce->default_properties_count; i++) {
     501           0 :                                 if (ce->default_properties_table[i]) {
     502           0 :                                         zend_persist_zval_ptr(&ce->default_properties_table[i] TSRMLS_CC);
     503             :                                 }
     504             :                         }
     505             :                 }
     506           0 :                 if (ce->default_static_members_table) {
     507             :                     int i;
     508             : 
     509           0 :                         zend_accel_store(ce->default_static_members_table, sizeof(zval*) * ce->default_static_members_count);
     510           0 :                         for (i = 0; i < ce->default_static_members_count; i++) {
     511           0 :                                 if (ce->default_static_members_table[i]) {
     512           0 :                                         zend_persist_zval_ptr(&ce->default_static_members_table[i] TSRMLS_CC);
     513             :                                 }
     514             :                         }
     515             :                 }
     516           0 :                 ce->static_members_table = NULL;
     517             : #else
     518             :                 zend_hash_persist(&ce->default_properties, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
     519             :                 zend_hash_persist(&ce->default_static_members, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
     520             :                 ce->static_members = NULL;
     521             : #endif
     522           0 :                 zend_hash_persist(&ce->constants_table, (zend_persist_func_t) zend_persist_zval_ptr, sizeof(zval**) TSRMLS_CC);
     523             : 
     524           0 :                 if (ZEND_CE_FILENAME(ce)) {
     525             :                         /* do not free! PHP has centralized filename storage, compiler will free it */
     526           0 :                         ZEND_CE_FILENAME(ce) = zend_accel_memdup(ZEND_CE_FILENAME(ce), strlen(ZEND_CE_FILENAME(ce)) + 1);
     527             :                 }
     528           0 :                 if (ZEND_CE_DOC_COMMENT(ce)) {
     529           0 :                         if (ZCG(accel_directives).save_comments) {
     530           0 :                                 zend_accel_store(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT_LEN(ce) + 1);
     531             :                         } else {
     532           0 :                                 if (!zend_shared_alloc_get_xlat_entry(ZEND_CE_DOC_COMMENT(ce))) {
     533           0 :                                         zend_shared_alloc_register_xlat_entry(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT(ce));
     534           0 :                                         efree((char*)ZEND_CE_DOC_COMMENT(ce));
     535             :                                 }
     536           0 :                                 ZEND_CE_DOC_COMMENT(ce) = NULL;
     537           0 :                                 ZEND_CE_DOC_COMMENT_LEN(ce) = 0;
     538             :                         }
     539             :                 }
     540           0 :                 zend_hash_persist(&ce->properties_info, (zend_persist_func_t) zend_persist_property_info, sizeof(zend_property_info) TSRMLS_CC);
     541           0 :                 if (ce->num_interfaces && ce->interfaces) {
     542           0 :                         efree(ce->interfaces);
     543             :                 }
     544           0 :                 ce->interfaces = NULL; /* will be filled in on fetch */
     545             : 
     546             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     547           0 :                 if (ce->num_traits && ce->traits) {
     548           0 :                         efree(ce->traits);
     549             :                 }
     550           0 :                 ce->traits = NULL;
     551             : 
     552           0 :                 if (ce->trait_aliases) {
     553           0 :                         int i = 0;
     554           0 :                         while (ce->trait_aliases[i]) {
     555           0 :                                 if (ce->trait_aliases[i]->trait_method) {
     556           0 :                                         if (ce->trait_aliases[i]->trait_method->method_name) {
     557           0 :                                                 zend_accel_store(ce->trait_aliases[i]->trait_method->method_name,
     558             :                                                         ce->trait_aliases[i]->trait_method->mname_len + 1);
     559             :                                         }
     560           0 :                                         if (ce->trait_aliases[i]->trait_method->class_name) {
     561           0 :                                                 zend_accel_store(ce->trait_aliases[i]->trait_method->class_name,
     562             :                                                         ce->trait_aliases[i]->trait_method->cname_len + 1);
     563             :                                         }
     564           0 :                                         ce->trait_aliases[i]->trait_method->ce = NULL;
     565           0 :                                         zend_accel_store(ce->trait_aliases[i]->trait_method,
     566             :                                                 sizeof(zend_trait_method_reference));
     567             :                                 }
     568             : 
     569           0 :                                 if (ce->trait_aliases[i]->alias) {
     570           0 :                                         zend_accel_store(ce->trait_aliases[i]->alias,
     571             :                                                 ce->trait_aliases[i]->alias_len + 1);
     572             :                                 }
     573             : 
     574             : #if ZEND_EXTENSION_API_NO <= PHP_5_4_X_API_NO
     575             :                 ce->trait_aliases[i]->function = NULL;
     576             : #endif
     577           0 :                                 zend_accel_store(ce->trait_aliases[i], sizeof(zend_trait_alias));
     578           0 :                                 i++;
     579             :                         }
     580             : 
     581           0 :                         zend_accel_store(ce->trait_aliases, sizeof(zend_trait_alias*) * (i + 1));
     582             :                 }
     583             : 
     584           0 :                 if (ce->trait_precedences) {
     585           0 :                         int i = 0;
     586             : 
     587           0 :                         while (ce->trait_precedences[i]) {
     588           0 :                                 zend_accel_store(ce->trait_precedences[i]->trait_method->method_name,
     589             :                                         ce->trait_precedences[i]->trait_method->mname_len + 1);
     590           0 :                                 zend_accel_store(ce->trait_precedences[i]->trait_method->class_name,
     591             :                                         ce->trait_precedences[i]->trait_method->cname_len + 1);
     592           0 :                                 ce->trait_precedences[i]->trait_method->ce = NULL;
     593           0 :                                 zend_accel_store(ce->trait_precedences[i]->trait_method,
     594             :                                         sizeof(zend_trait_method_reference));
     595             : 
     596           0 :                                 if (ce->trait_precedences[i]->exclude_from_classes) {
     597           0 :                                         int j = 0;
     598             : 
     599           0 :                                         while (ce->trait_precedences[i]->exclude_from_classes[j]) {
     600           0 :                                                 zend_accel_store(ce->trait_precedences[i]->exclude_from_classes[j],
     601             :                                                         strlen((char*)ce->trait_precedences[i]->exclude_from_classes[j]) + 1);
     602           0 :                                                 j++;
     603             :                                         }
     604           0 :                                         zend_accel_store(ce->trait_precedences[i]->exclude_from_classes,
     605             :                                                 sizeof(zend_class_entry*) * (j + 1));
     606             :                                 }
     607             : 
     608             : #if ZEND_EXTENSION_API_NO <= PHP_5_4_X_API_NO
     609             :                 ce->trait_precedences[i]->function = NULL;
     610             : #endif
     611           0 :                                 zend_accel_store(ce->trait_precedences[i], sizeof(zend_trait_precedence));
     612           0 :                                 i++;
     613             :                         }
     614           0 :                         zend_accel_store(
     615             :                                 ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
     616             :                 }
     617             : #endif
     618             :         }
     619           0 : }
     620             : 
     621           0 : static int zend_update_property_info_ce(zend_property_info *prop TSRMLS_DC)
     622             : {
     623           0 :         prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce);
     624           0 :         return 0;
     625             : }
     626             : 
     627           0 : static int zend_update_parent_ce(zend_class_entry **pce TSRMLS_DC)
     628             : {
     629           0 :         zend_class_entry *ce = *pce;
     630             : 
     631           0 :         if (ce->parent) {
     632           0 :                 ce->parent = zend_shared_alloc_get_xlat_entry(ce->parent);
     633             :                 /* We use refcount to show if the class is used as a parent */
     634           0 :                 ce->parent->refcount++;
     635             :         }
     636             : 
     637             :         /* update methods */
     638           0 :         if (ce->constructor) {
     639           0 :                 ce->constructor = zend_shared_alloc_get_xlat_entry(ce->constructor);
     640             :                 /* we use refcount to show that op_array is referenced from several places */
     641           0 :                 ce->constructor->op_array.refcount++;
     642             :         }
     643           0 :         if (ce->destructor) {
     644           0 :                 ce->destructor = zend_shared_alloc_get_xlat_entry(ce->destructor);
     645           0 :                 ce->destructor->op_array.refcount++;
     646             :         }
     647           0 :         if (ce->clone) {
     648           0 :                 ce->clone = zend_shared_alloc_get_xlat_entry(ce->clone);
     649           0 :                 ce->clone->op_array.refcount++;
     650             :         }
     651           0 :         if (ce->__get) {
     652           0 :                 ce->__get = zend_shared_alloc_get_xlat_entry(ce->__get);
     653           0 :                 ce->__get->op_array.refcount++;
     654             :         }
     655           0 :         if (ce->__set) {
     656           0 :                 ce->__set = zend_shared_alloc_get_xlat_entry(ce->__set);
     657           0 :                 ce->__set->op_array.refcount++;
     658             :         }
     659           0 :         if (ce->__call) {
     660           0 :                 ce->__call = zend_shared_alloc_get_xlat_entry(ce->__call);
     661           0 :                 ce->__call->op_array.refcount++;
     662             :         }
     663           0 :         if (ce->serialize_func) {
     664           0 :                 ce->serialize_func = zend_shared_alloc_get_xlat_entry(ce->serialize_func);
     665           0 :                 ce->serialize_func->op_array.refcount++;
     666             :         }
     667           0 :         if (ce->unserialize_func) {
     668           0 :                 ce->unserialize_func = zend_shared_alloc_get_xlat_entry(ce->unserialize_func);
     669           0 :                 ce->unserialize_func->op_array.refcount++;
     670             :         }
     671           0 :         if (ce->__isset) {
     672           0 :                 ce->__isset = zend_shared_alloc_get_xlat_entry(ce->__isset);
     673           0 :                 ce->__isset->op_array.refcount++;
     674             :         }
     675           0 :         if (ce->__unset) {
     676           0 :                 ce->__unset = zend_shared_alloc_get_xlat_entry(ce->__unset);
     677           0 :                 ce->__unset->op_array.refcount++;
     678             :         }
     679           0 :         if (ce->__tostring) {
     680           0 :                 ce->__tostring = zend_shared_alloc_get_xlat_entry(ce->__tostring);
     681           0 :                 ce->__tostring->op_array.refcount++;
     682             :         }
     683             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     684           0 :         if (ce->__callstatic) {
     685           0 :                 ce->__callstatic = zend_shared_alloc_get_xlat_entry(ce->__callstatic);
     686           0 :                 ce->__callstatic->op_array.refcount++;
     687             :         }
     688             : #endif
     689           0 :         zend_hash_apply(&ce->properties_info, (apply_func_t) zend_update_property_info_ce TSRMLS_CC);
     690           0 :         return 0;
     691             : }
     692             : 
     693           0 : static void zend_accel_persist_class_table(HashTable *class_table TSRMLS_DC)
     694             : {
     695           0 :     zend_hash_persist(class_table, (zend_persist_func_t) zend_persist_class_entry, sizeof(zend_class_entry*) TSRMLS_CC);
     696           0 :         zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce TSRMLS_CC);
     697           0 : }
     698             : 
     699           0 : zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length TSRMLS_DC)
     700             : {
     701           0 :         zend_shared_alloc_clear_xlat_table();
     702           0 :         zend_hash_persist(&script->function_table, (zend_persist_func_t) zend_persist_op_array, sizeof(zend_op_array) TSRMLS_CC);
     703           0 :         zend_accel_persist_class_table(&script->class_table TSRMLS_CC);
     704           0 :         zend_persist_op_array_ex(&script->main_op_array, script TSRMLS_CC);
     705           0 :         *key = zend_accel_memdup(*key, key_length + 1);
     706           0 :         zend_accel_store(script->full_path, script->full_path_len + 1);
     707           0 :         zend_accel_store(script, sizeof(zend_persistent_script));
     708             : 
     709           0 :         return script;
     710             : }
     711             : 
     712           0 : int zend_accel_script_persistable(zend_persistent_script *script)
     713             : {
     714           0 :         return 1;
     715             : }

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:52 +0000 (4 days ago)

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