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_calc.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 0 154 0.0 %
Date: 2014-04-06 Functions: 0 9 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_operators.h"
      28             : 
      29             : #define START_SIZE()       uint memory_used = 0
      30             : #define ADD_DUP_SIZE(m,s)  memory_used += zend_shared_memdup_size((void*)m, s)
      31             : #define ADD_SIZE(m)        memory_used += ZEND_ALIGNED_SIZE(m)
      32             : #define RETURN_SIZE()      return memory_used
      33             : 
      34             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      35             : # define ADD_INTERNED_STRING(str, len) do { \
      36             :                 if (!IS_INTERNED(str)) { \
      37             :                         const char *tmp = accel_new_interned_string((str), (len), 1 TSRMLS_CC); \
      38             :                         if (tmp != (str)) { \
      39             :                                 (str) = (char*)tmp; \
      40             :                         } else { \
      41             :                                 ADD_DUP_SIZE((str), (len)); \
      42             :                         } \
      43             :                 } \
      44             :         } while (0)
      45             : #else
      46             : # define ADD_INTERNED_STRING(str, len) ADD_DUP_SIZE((str), (len))
      47             : #endif
      48             : 
      49             : static uint zend_persist_zval_ptr_calc(zval **zp TSRMLS_DC);
      50             : static uint zend_persist_zval_calc(zval *z TSRMLS_DC);
      51             : 
      52           0 : static uint zend_hash_persist_calc(HashTable *ht, int (*pPersistElement)(void *pElement TSRMLS_DC), size_t el_size TSRMLS_DC)
      53             : {
      54           0 :         Bucket *p = ht->pListHead;
      55           0 :         START_SIZE();
      56             : 
      57           0 :         while (p) {
      58             :                 /* persist bucket and key */
      59             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      60           0 :                 ADD_DUP_SIZE(p, sizeof(Bucket));
      61           0 :                 if (p->nKeyLength) {
      62           0 :                         const char *tmp = accel_new_interned_string(p->arKey, p->nKeyLength, 0 TSRMLS_CC);
      63           0 :                         if (tmp != p->arKey) {
      64           0 :                                 p->arKey = tmp;
      65             :                         } else {
      66           0 :                                 ADD_DUP_SIZE(p->arKey, p->nKeyLength);
      67             :                         }
      68             :                 }
      69             : #else
      70             :                 ADD_DUP_SIZE(p, sizeof(Bucket) - 1 + p->nKeyLength);
      71             : #endif
      72             : 
      73             :                 /* persist data pointer in bucket */
      74           0 :                 if (!p->pDataPtr) {
      75           0 :                         ADD_DUP_SIZE(p->pData, el_size);
      76             :                 }
      77             : 
      78             :                 /* persist the data itself */
      79           0 :                 if (pPersistElement) {
      80           0 :                         ADD_SIZE(pPersistElement(p->pData TSRMLS_CC));
      81             :                 }
      82             : 
      83           0 :                 p = p->pListNext;
      84             :         }
      85             : 
      86             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
      87           0 :         if (ht->nTableMask) {
      88           0 :                 ADD_DUP_SIZE(ht->arBuckets, sizeof(Bucket*) * ht->nTableSize);
      89             :         }
      90             : #else
      91             :         ADD_DUP_SIZE(ht->arBuckets, sizeof(Bucket*) * ht->nTableSize);
      92             : #endif
      93             : 
      94           0 :         RETURN_SIZE();
      95             : }
      96             : 
      97             : #if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
      98           0 : static uint zend_persist_ast_calc(zend_ast *ast TSRMLS_DC)
      99             : {
     100             :         int i;
     101           0 :         START_SIZE();
     102             : 
     103           0 :         if (ast->kind == ZEND_CONST) {
     104           0 :                 ADD_SIZE(sizeof(zend_ast) + sizeof(zval));
     105           0 :                 ADD_SIZE(zend_persist_zval_calc(ast->u.val TSRMLS_CC));
     106             :         } else {
     107           0 :                 ADD_SIZE(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
     108           0 :                 for (i = 0; i < ast->children; i++) {
     109           0 :                         if ((&ast->u.child)[i]) {
     110           0 :                                 ADD_SIZE(zend_persist_ast_calc((&ast->u.child)[i] TSRMLS_CC));
     111             :                         }
     112             :                 }
     113             :         }
     114           0 :         RETURN_SIZE();
     115             : }
     116             : #endif
     117             : 
     118           0 : static uint zend_persist_zval_calc(zval *z TSRMLS_DC)
     119             : {
     120           0 :         START_SIZE();
     121             : 
     122             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     123           0 :         switch (z->type & IS_CONSTANT_TYPE_MASK) {
     124             : #else
     125             :         switch (z->type & ~IS_CONSTANT_INDEX) {
     126             : #endif
     127             :                 case IS_STRING:
     128             :                 case IS_CONSTANT:
     129           0 :                         ADD_INTERNED_STRING(Z_STRVAL_P(z), Z_STRLEN_P(z) + 1);
     130           0 :                         break;
     131             :                 case IS_ARRAY:
     132             :                 case IS_CONSTANT_ARRAY:
     133           0 :                         ADD_DUP_SIZE(z->value.ht, sizeof(HashTable));
     134           0 :                         ADD_SIZE(zend_hash_persist_calc(z->value.ht, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
     135           0 :                         break;
     136             : #if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
     137             :                 case IS_CONSTANT_AST:
     138           0 :                         ADD_SIZE(zend_persist_ast_calc(Z_AST_P(z) TSRMLS_CC));
     139             :                         break;
     140             : #endif
     141             :         }
     142           0 :         RETURN_SIZE();
     143             : }
     144             : 
     145           0 : static uint zend_persist_zval_ptr_calc(zval **zp TSRMLS_DC)
     146             : {
     147           0 :         START_SIZE();
     148           0 :         zval *new_ptr = zend_shared_alloc_get_xlat_entry(*zp);
     149             : 
     150           0 :         if (!new_ptr) {
     151           0 :                 ADD_DUP_SIZE(*zp, sizeof(zval));
     152           0 :                 ADD_SIZE(zend_persist_zval_calc(*zp TSRMLS_CC));
     153             :         }
     154           0 :         RETURN_SIZE();
     155             : }
     156             : 
     157           0 : static uint zend_persist_op_array_calc(zend_op_array *op_array TSRMLS_DC)
     158             : {
     159           0 :         START_SIZE();
     160             : 
     161           0 :         if (op_array->type != ZEND_USER_FUNCTION) {
     162           0 :                 return 0;
     163             :         }
     164             : 
     165           0 :         if (op_array->filename) {
     166           0 :                 ADD_DUP_SIZE(op_array->filename, strlen(op_array->filename) + 1);
     167             :         }
     168             : 
     169             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     170           0 :         if (op_array->literals && !zend_shared_alloc_get_xlat_entry(op_array->literals)) {
     171           0 :                 zend_literal *p = op_array->literals;
     172           0 :                 zend_literal *end = p + op_array->last_literal;
     173           0 :                 ADD_DUP_SIZE(op_array->literals, sizeof(zend_literal) * op_array->last_literal);
     174           0 :                 while (p < end) {
     175           0 :                         ADD_SIZE(zend_persist_zval_calc(&p->constant TSRMLS_CC));
     176           0 :                         p++;
     177             :                 }
     178             :         }
     179             : #endif
     180             : 
     181           0 :         if (!zend_shared_alloc_get_xlat_entry(op_array->opcodes)) {
     182             : #if ZEND_EXTENSION_API_NO <= PHP_5_3_X_API_NO
     183             :                 zend_op *opline = op_array->opcodes;
     184             :                 zend_op *end = op_array->opcodes + op_array->last;
     185             : 
     186             :                 ADD_DUP_SIZE(op_array->opcodes, sizeof(zend_op) * op_array->last);
     187             :                 while (opline<end) {
     188             :                         if (opline->op1.op_type == IS_CONST) {
     189             :                                 ADD_SIZE(zend_persist_zval_calc(&opline->op1.u.constant TSRMLS_CC));
     190             :                         }
     191             :                         if (opline->op2.op_type == IS_CONST) {
     192             :                                 ADD_SIZE(zend_persist_zval_calc(&opline->op2.u.constant TSRMLS_CC));
     193             :                         }
     194             :                         opline++;
     195             :                 }
     196             : #else
     197           0 :                 ADD_DUP_SIZE(op_array->opcodes, sizeof(zend_op) * op_array->last);
     198             : #endif
     199             :         }
     200             : 
     201           0 :         if (op_array->function_name) {
     202           0 :                 ADD_DUP_SIZE(op_array->function_name, strlen(op_array->function_name) + 1);
     203             :     }
     204             : 
     205           0 :         if (op_array->arg_info &&
     206           0 :                 !zend_shared_alloc_get_xlat_entry(op_array->arg_info)) {
     207             :                 zend_uint i;
     208             : 
     209           0 :                 ADD_DUP_SIZE(op_array->arg_info, sizeof(zend_arg_info) * op_array->num_args);
     210           0 :                 for (i = 0; i < op_array->num_args; i++) {
     211           0 :                         if (op_array->arg_info[i].name) {
     212           0 :                                 ADD_INTERNED_STRING(op_array->arg_info[i].name, op_array->arg_info[i].name_len + 1);
     213             :                         }
     214           0 :                         if (op_array->arg_info[i].class_name) {
     215           0 :                                 ADD_INTERNED_STRING(op_array->arg_info[i].class_name, op_array->arg_info[i].class_name_len + 1);
     216             :                         }
     217             : 
     218             :                 }
     219             :         }
     220             : 
     221           0 :         if (op_array->brk_cont_array) {
     222           0 :                 ADD_DUP_SIZE(op_array->brk_cont_array, sizeof(zend_brk_cont_element) * op_array->last_brk_cont);
     223             :         }
     224             : 
     225           0 :         if (op_array->static_variables) {
     226           0 :                 ADD_DUP_SIZE(op_array->static_variables, sizeof(HashTable));
     227           0 :                 ADD_SIZE(zend_hash_persist_calc(op_array->static_variables, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
     228             :         }
     229             : 
     230           0 :         if (ZCG(accel_directives).save_comments && op_array->doc_comment) {
     231           0 :                 ADD_DUP_SIZE(op_array->doc_comment, op_array->doc_comment_len + 1);
     232             :         }
     233             : 
     234           0 :         if (op_array->try_catch_array) {
     235           0 :                 ADD_DUP_SIZE(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
     236             :         }
     237             : 
     238           0 :         if (op_array->vars && !zend_shared_alloc_get_xlat_entry(op_array->vars)) {
     239             :                 int i;
     240             : 
     241           0 :                 ADD_DUP_SIZE(op_array->vars, sizeof(zend_compiled_variable) * op_array->last_var);
     242           0 :                 for (i = 0; i < op_array->last_var; i++) {
     243           0 :                         ADD_INTERNED_STRING(op_array->vars[i].name, op_array->vars[i].name_len + 1);
     244             :                 }
     245             :         }
     246             : 
     247           0 :         RETURN_SIZE();
     248             : }
     249             : 
     250           0 : static uint zend_persist_property_info_calc(zend_property_info *prop TSRMLS_DC)
     251             : {
     252           0 :         START_SIZE();
     253           0 :         ADD_INTERNED_STRING(prop->name, prop->name_length + 1);
     254           0 :         if (ZCG(accel_directives).save_comments && prop->doc_comment) {
     255           0 :                 ADD_DUP_SIZE(prop->doc_comment, prop->doc_comment_len + 1);
     256             :         }
     257           0 :         RETURN_SIZE();
     258             : }
     259             : 
     260           0 : static uint zend_persist_class_entry_calc(zend_class_entry **pce TSRMLS_DC)
     261             : {
     262           0 :         zend_class_entry *ce = *pce;
     263           0 :         START_SIZE();
     264             : 
     265           0 :         if (ce->type == ZEND_USER_CLASS) {
     266           0 :                 ADD_DUP_SIZE(ce, sizeof(zend_class_entry));
     267           0 :                 ADD_INTERNED_STRING(ce->name, ce->name_length + 1);
     268           0 :                 ADD_SIZE(zend_hash_persist_calc(&ce->function_table, (int (*)(void* TSRMLS_DC)) zend_persist_op_array_calc, sizeof(zend_op_array) TSRMLS_CC));
     269             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     270           0 :                 if (ce->default_properties_table) {
     271             :                     int i;
     272             : 
     273           0 :                         ADD_SIZE(sizeof(zval*) * ce->default_properties_count);
     274           0 :                         for (i = 0; i < ce->default_properties_count; i++) {
     275           0 :                                 if (ce->default_properties_table[i]) {
     276           0 :                                         ADD_SIZE(zend_persist_zval_ptr_calc(&ce->default_properties_table[i] TSRMLS_CC));
     277             :                                 }
     278             :                         }
     279             :                 }
     280           0 :                 if (ce->default_static_members_table) {
     281             :                     int i;
     282             : 
     283           0 :                         ADD_SIZE(sizeof(zval*) * ce->default_static_members_count);
     284           0 :                         for (i = 0; i < ce->default_static_members_count; i++) {
     285           0 :                                 if (ce->default_static_members_table[i]) {
     286           0 :                                         ADD_SIZE(zend_persist_zval_ptr_calc(&ce->default_static_members_table[i] TSRMLS_CC));
     287             :                                 }
     288             :                         }
     289             :                 }
     290             : #else
     291             :                 ADD_SIZE(zend_hash_persist_calc(&ce->default_properties, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
     292             :                 ADD_SIZE(zend_hash_persist_calc(&ce->default_static_members, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
     293             : #endif
     294           0 :                 ADD_SIZE(zend_hash_persist_calc(&ce->constants_table, (int (*)(void* TSRMLS_DC)) zend_persist_zval_ptr_calc, sizeof(zval**) TSRMLS_CC));
     295             : 
     296           0 :                 if (ZEND_CE_FILENAME(ce)) {
     297           0 :                         ADD_DUP_SIZE(ZEND_CE_FILENAME(ce), strlen(ZEND_CE_FILENAME(ce)) + 1);
     298             :                 }
     299           0 :                 if (ZCG(accel_directives).save_comments && ZEND_CE_DOC_COMMENT(ce)) {
     300           0 :                         ADD_DUP_SIZE(ZEND_CE_DOC_COMMENT(ce), ZEND_CE_DOC_COMMENT_LEN(ce) + 1);
     301             :                 }
     302             : 
     303           0 :                 ADD_SIZE(zend_hash_persist_calc(&ce->properties_info, (int (*)(void* TSRMLS_DC)) zend_persist_property_info_calc, sizeof(zend_property_info) TSRMLS_CC));
     304             : 
     305             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     306           0 :                 if (ce->trait_aliases) {
     307           0 :                         int i = 0;
     308           0 :                         while (ce->trait_aliases[i]) {
     309           0 :                                 if (ce->trait_aliases[i]->trait_method) {
     310           0 :                                         if (ce->trait_aliases[i]->trait_method->method_name) {
     311           0 :                                                 ADD_SIZE(ce->trait_aliases[i]->trait_method->mname_len + 1);
     312             :                                         }
     313           0 :                                         if (ce->trait_aliases[i]->trait_method->class_name) {
     314           0 :                                                 ADD_SIZE(ce->trait_aliases[i]->trait_method->cname_len + 1);
     315             :                                         }
     316           0 :                                         ADD_SIZE(sizeof(zend_trait_method_reference));
     317             :                                 }
     318             : 
     319           0 :                                 if (ce->trait_aliases[i]->alias) {
     320           0 :                                         ADD_SIZE(ce->trait_aliases[i]->alias_len + 1);
     321             :                                 }
     322           0 :                                 ADD_SIZE(sizeof(zend_trait_alias));
     323           0 :                                 i++;
     324             :                         }
     325           0 :                         ADD_SIZE(sizeof(zend_trait_alias*) * (i + 1));
     326             :                 }
     327             : 
     328           0 :                 if (ce->trait_precedences) {
     329           0 :                         int i = 0;
     330             : 
     331           0 :                         while (ce->trait_precedences[i]) {
     332           0 :                                 ADD_SIZE(ce->trait_precedences[i]->trait_method->mname_len + 1);
     333           0 :                                 ADD_SIZE(ce->trait_precedences[i]->trait_method->cname_len + 1);
     334           0 :                                 ADD_SIZE(sizeof(zend_trait_method_reference));
     335             : 
     336           0 :                                 if (ce->trait_precedences[i]->exclude_from_classes) {
     337           0 :                                         int j = 0;
     338             : 
     339           0 :                                         while (ce->trait_precedences[i]->exclude_from_classes[j]) {
     340           0 :                                                 ADD_SIZE(strlen((char*)ce->trait_precedences[i]->exclude_from_classes[j]) + 1);
     341           0 :                                                 j++;
     342             :                                         }
     343           0 :                                         ADD_SIZE(sizeof(zend_class_entry*) * (j + 1));
     344             :                                 }
     345           0 :                                 ADD_SIZE(sizeof(zend_trait_precedence));
     346           0 :                                 i++;
     347             :                         }
     348           0 :                         ADD_SIZE(sizeof(zend_trait_precedence*) * (i + 1));
     349             :                 }
     350             : #endif
     351             :         }
     352           0 :         RETURN_SIZE();
     353             : }
     354             : 
     355           0 : static uint zend_accel_persist_class_table_calc(HashTable *class_table TSRMLS_DC)
     356             : {
     357           0 :         return zend_hash_persist_calc(class_table, (int (*)(void* TSRMLS_DC)) zend_persist_class_entry_calc, sizeof(zend_class_entry*) TSRMLS_CC);
     358             : }
     359             : 
     360           0 : uint zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length TSRMLS_DC)
     361             : {
     362           0 :         START_SIZE();
     363             : 
     364           0 :         ADD_SIZE(zend_hash_persist_calc(&new_persistent_script->function_table, (int (*)(void* TSRMLS_DC)) zend_persist_op_array_calc, sizeof(zend_op_array) TSRMLS_CC));
     365           0 :         ADD_SIZE(zend_accel_persist_class_table_calc(&new_persistent_script->class_table TSRMLS_CC));
     366           0 :         ADD_SIZE(zend_persist_op_array_calc(&new_persistent_script->main_op_array TSRMLS_CC));
     367           0 :         ADD_DUP_SIZE(key, key_length + 1);
     368           0 :         ADD_DUP_SIZE(new_persistent_script->full_path, new_persistent_script->full_path_len + 1);
     369           0 :         ADD_DUP_SIZE(new_persistent_script, sizeof(zend_persistent_script));
     370             : 
     371           0 :         RETURN_SIZE();
     372             : }

Generated by: LCOV version 1.10

Generated at Sun, 06 Apr 2014 17:31:05 +0000 (9 days ago)

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