Changeset 328

Show
Ignore:
Timestamp:
08/20/07 13:33:54 (9 months ago)
Author:
bart
Message:

Rewrite the calc_* values so it no longer uses the EAG(mem) global.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r327 r328  
     12007-08-20  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
     2        * Rewrite the calc_* values so it no longer uses the EAG(mem) global. 
     3 
    142007-08-19  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
    25        * Fix an E_NOTICE error in the control panel 
  • eaccelerator/trunk/cache.c

    r296 r328  
    219219    zend_hash_init(&EAG(strings), 0, NULL, NULL, 0); 
    220220    EACCELERATOR_ALIGN(EAG(mem)); 
    221     EAG(mem) += offsetof(ea_user_cache_entry, key) + xlen + 1; 
    222     calc_zval(val TSRMLS_CC); 
     221    size = offsetof(ea_user_cache_entry, key) + xlen + 1; 
     222    size += calc_zval(val TSRMLS_CC); 
    223223    zend_hash_destroy(&EAG(strings)); 
    224  
    225     size = (long) EAG(mem); 
    226224 
    227225    EAG(mem) = NULL; 
  • eaccelerator/trunk/ea_store.c

    r291 r328  
    3636/* Functions to calculate the size of different structure that a compiled php */ 
    3737/* script contains.                                                           */ 
     38/* Each function needs to return a size that is aligned to the machine word   */ 
     39/* size.                                                                      */ 
    3840/******************************************************************************/ 
    3941 
     
    4143inline 
    4244#endif 
    43 static void calc_string(char *str, int len TSRMLS_DC) 
     45static size_t calc_string(char *str, int len TSRMLS_DC) 
    4446{ 
    4547        if (len > MAX_DUP_STR_LEN ||  
    4648            zend_hash_add(&EAG(strings), str, len, &str, sizeof(char *), NULL) == SUCCESS) { 
    47                 EACCELERATOR_ALIGN(EAG(mem)); 
    48                 EAG(mem) += len; 
    49         } 
    50 
    51  
    52 typedef void (*calc_bucket_t) (void *TSRMLS_DC); 
     49        EA_SIZE_ALIGN(len); 
     50        return len; 
     51        } 
     52    return 0; 
     53
     54 
     55typedef size_t (*calc_bucket_t) (void * TSRMLS_DC); 
    5356 
    5457#define calc_hash_ex(from, start, calc_bucket) \ 
     
    6467  calc_hash_ex(from, start, (calc_bucket_t)calc_zval_ptr) 
    6568 
    66  
    67 static void calc_zval_ptr(zval ** from TSRMLS_DC) 
    68 
    69         EACCELERATOR_ALIGN(EAG(mem)); 
    70         EAG(mem) += sizeof(zval); 
    71         calc_zval(*from TSRMLS_CC); 
    72 
    73  
    74 #ifdef ZEND_ENGINE_2 
    75 static void calc_property_info(zend_property_info * from TSRMLS_DC) 
    76 
    77         EACCELERATOR_ALIGN(EAG(mem)); 
    78         EAG(mem) += sizeof(zend_property_info); 
    79         calc_string(from->name, from->name_length + 1 TSRMLS_CC); 
     69static size_t calc_zval_ptr(zval ** from TSRMLS_DC) 
     70
     71    size_t size = 0; 
     72 
     73        size += sizeof(zval); 
     74    EA_SIZE_ALIGN(size); 
     75        size += calc_zval(*from TSRMLS_CC); 
     76 
     77    return size; 
     78
     79 
     80#ifdef ZEND_ENGINE_2 
     81static size_t calc_property_info(zend_property_info * from TSRMLS_DC) 
     82
     83    size_t size = 0; 
     84 
     85        size += sizeof(zend_property_info); 
     86    EA_SIZE_ALIGN(size); 
     87 
     88        size += calc_string(from->name, from->name_length + 1 TSRMLS_CC); 
    8089#ifdef INCLUDE_DOC_COMMENTS 
    8190#ifdef ZEND_ENGINE_2_1 
    8291     if (from->doc_comment != NULL) { 
    83         calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     92        size += calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
    8493     } 
    8594#endif 
    8695#endif 
     96     return size; 
    8797} 
    8898#endif 
    8999 
    90100/* Calculate the size of an HashTable */ 
    91 static void calc_hash_int(HashTable * source, Bucket * start, 
     101static size_t calc_hash_int(HashTable * source, Bucket * start, 
    92102                                                  calc_bucket_t calc_bucket TSRMLS_DC) 
    93103{ 
    94104        Bucket *p; 
     105    size_t size = 0; 
    95106 
    96107        if (source->nNumOfElements > 0) { 
    97108                if (!EAG(compress)) { 
    98                         EACCELERATOR_ALIGN(EAG(mem)); 
    99                        EAG(mem) += source->nTableSize * sizeof(Bucket *); 
     109                        size += source->nTableSize * sizeof(Bucket *); 
     110            EA_SIZE_ALIGN(size); 
    100111                } 
    101112                p = start; 
    102113                while (p) { 
    103                         EACCELERATOR_ALIGN(EAG(mem))
    104                        EAG(mem) += offsetof(Bucket, arKey) + p->nKeyLength
    105                         calc_bucket(p->pData TSRMLS_CC); 
     114                        size += offsetof(Bucket, arKey) + p->nKeyLength
     115            EA_SIZE_ALIGN(size)
     116                        size += calc_bucket(p->pData TSRMLS_CC); 
    106117                        p = p->pListNext; 
    107118                } 
    108119        } 
    109 
    110  
    111 void calc_zval(zval * zv TSRMLS_DC) 
    112 
     120    return size; 
     121
     122 
     123size_t calc_zval(zval *zv TSRMLS_DC) 
     124
     125    size_t size = 0; 
     126 
    113127        switch (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX) { 
    114         case IS_CONSTANT: 
    115     case IS_OBJECT: /* object should have been serialized before storing them */ 
    116         case IS_STRING: 
    117                 calc_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 
    118                 break; 
    119         case IS_ARRAY: 
    120         case IS_CONSTANT_ARRAY: 
    121                 if (Z_ARRVAL_P(zv) != NULL && Z_ARRVAL_P(zv) != &EG(symbol_table)) { 
    122                         EACCELERATOR_ALIGN(EAG(mem)); 
    123                         EAG(mem) += sizeof(HashTable); 
    124                         calc_zval_hash(Z_ARRVAL_P(zv)); 
    125                 } 
    126                 break; 
    127         case IS_RESOURCE: 
    128                 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache resources\n", getpid())); 
    129                 zend_bailout(); 
    130         default: 
    131                 break; 
    132         } 
     128        case IS_CONSTANT: 
     129        case IS_OBJECT: /* object should have been serialized before storing them */ 
     130        case IS_STRING: 
     131                size += calc_string(Z_STRVAL_P(zv), Z_STRLEN_P(zv) + 1 TSRMLS_CC); 
     132                break; 
     133 
     134        case IS_ARRAY: 
     135        case IS_CONSTANT_ARRAY: 
     136                if (Z_ARRVAL_P(zv) != NULL && Z_ARRVAL_P(zv) != &EG(symbol_table)) { 
     137                        size += sizeof(HashTable); 
     138                EA_SIZE_ALIGN(size); 
     139                        size += calc_zval_hash(Z_ARRVAL_P(zv)); 
     140                } 
     141                break; 
     142 
     143        case IS_RESOURCE: 
     144                DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache resources\n", getpid())); 
     145                zend_bailout(); 
     146            break; 
     147        default: 
     148                break; 
     149        } 
     150    return size; 
    133151} 
    134152 
    135153/* Calculate the size of an op_array */ 
    136 static void calc_op_array(zend_op_array * from TSRMLS_DC) 
     154static size_t calc_op_array(zend_op_array * from TSRMLS_DC) 
    137155{ 
    138156        zend_op *opline; 
    139157        zend_op *end; 
     158    size_t size = 0; 
    140159 
    141160        if (from->type == ZEND_INTERNAL_FUNCTION) { 
    142                 EACCELERATOR_ALIGN(EAG(mem)); 
    143                EAG(mem) += sizeof(zend_internal_function); 
     161                size += sizeof(zend_internal_function); 
     162        EA_SIZE_ALIGN(size); 
    144163        } else if (from->type == ZEND_USER_FUNCTION) { 
    145                 EACCELERATOR_ALIGN(EAG(mem)); 
    146                EAG(mem) += sizeof(ea_op_array); 
     164                size += sizeof(ea_op_array); 
     165        EA_SIZE_ALIGN(size); 
    147166        } else { 
    148167                DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache function \"%s\"\n", getpid(), from->function_name)); 
     
    152171        if (from->num_args > 0) { 
    153172                zend_uint i; 
    154                 EACCELERATOR_ALIGN(EAG(mem)); 
    155                EAG(mem) += from->num_args * sizeof(zend_arg_info); 
     173                size += from->num_args * sizeof(zend_arg_info); 
     174        EA_SIZE_ALIGN(size); 
    156175                for (i = 0; i < from->num_args; i++) { 
    157                         if (from->arg_info[i].name) 
    158                                 calc_string(from->arg_info[i].name, from->arg_info[i].name_len + 1 TSRMLS_CC); 
    159                         if (from->arg_info[i].class_name) 
    160                                 calc_string(from->arg_info[i].class_name, from->arg_info[i].class_name_len + 1 TSRMLS_CC); 
     176                        if (from->arg_info[i].name) { 
     177                                size += calc_string(from->arg_info[i].name, from->arg_info[i].name_len + 1 TSRMLS_CC); 
     178            } 
     179                        if (from->arg_info[i].class_name) { 
     180                                size += calc_string(from->arg_info[i].class_name, from->arg_info[i].class_name_len + 1 TSRMLS_CC); 
     181            } 
    161182                } 
    162183        } 
    163184#else 
    164         if (from->arg_types != NULL) 
    165                 calc_string((char *) from->arg_types, (from->arg_types[0] + 1) * sizeof(zend_uchar) TSRMLS_CC); 
    166 #endif 
    167         if (from->function_name != NULL) 
    168                 calc_string(from->function_name, strlen(from->function_name) + 1 TSRMLS_CC); 
     185        if (from->arg_types != NULL) { 
     186            size += calc_string((char *) from->arg_types, (from->arg_types[0] + 1) * sizeof(zend_uchar) TSRMLS_CC); 
     187    } 
     188#endif 
     189        if (from->function_name != NULL) { 
     190                size += calc_string(from->function_name, strlen(from->function_name) + 1 TSRMLS_CC); 
     191    } 
    169192#ifdef ZEND_ENGINE_2 
    170193        if (from->scope != NULL) { 
     
    173196                while (q != NULL) { 
    174197                        if (*(zend_class_entry **) q->pData == from->scope) { 
    175                                 calc_string(q->arKey, q->nKeyLength TSRMLS_CC); 
     198                                size += calc_string(q->arKey, q->nKeyLength TSRMLS_CC); 
    176199                                break; 
    177200                        } 
     
    180203        } 
    181204#endif 
    182         if (from->type == ZEND_INTERNAL_FUNCTION) 
     205        if (from->type == ZEND_INTERNAL_FUNCTION) { 
    183206                return; 
     207    } 
    184208 
    185209        if (from->opcodes != NULL) { 
    186                EACCELERATOR_ALIGN(EAG(mem)); 
    187                EAG(mem) += from->last * sizeof(zend_op); 
     210        size += from->last * sizeof(zend_op); 
     211        EA_SIZE_ALIGN(size); 
    188212 
    189213                opline = from->opcodes; 
     
    191215                EAG(compress) = 0; 
    192216                for (; opline < end; opline++) { 
    193                         if (opline->op1.op_type == IS_CONST) 
    194                                 calc_zval(&opline->op1.u.constant TSRMLS_CC); 
    195                         if (opline->op2.op_type == IS_CONST) 
    196                                 calc_zval(&opline->op2.u.constant TSRMLS_CC); 
     217                        if (opline->op1.op_type == IS_CONST) { 
     218                                size += calc_zval(&opline->op1.u.constant TSRMLS_CC); 
     219            } 
     220                        if (opline->op2.op_type == IS_CONST) { 
     221                                size += calc_zval(&opline->op2.u.constant TSRMLS_CC); 
     222            } 
    197223                } 
    198224                EAG(compress) = 1; 
    199225        } 
    200226        if (from->brk_cont_array != NULL) { 
    201                 EACCELERATOR_ALIGN(EAG(mem))
    202                EAG(mem) += sizeof(zend_brk_cont_element) * from->last_brk_cont
     227                size += sizeof(zend_brk_cont_element) * from->last_brk_cont
     228        EA_SIZE_ALIGN(size)
    203229        } 
    204230#ifdef ZEND_ENGINE_2 
    205231        if (from->try_catch_array != NULL) { 
    206                 EACCELERATOR_ALIGN(EAG(mem))
    207                EAG(mem) += sizeof(zend_try_catch_element) * from->last_try_catch
     232                size += sizeof(zend_try_catch_element) * from->last_try_catch
     233        EA_SIZE_ALIGN(size)
    208234        } 
    209235#endif 
    210236        if (from->static_variables != NULL) { 
    211                 EACCELERATOR_ALIGN(EAG(mem)); 
    212                EAG(mem) += sizeof(HashTable); 
    213                 calc_zval_hash(from->static_variables); 
     237                size += sizeof(HashTable); 
     238        EA_SIZE_ALIGN(size); 
     239                size += calc_zval_hash(from->static_variables); 
    214240        } 
    215241#ifdef ZEND_ENGINE_2_1 
    216242        if (from->vars != NULL) { 
    217243                int i; 
    218                 EACCELERATOR_ALIGN(EAG(mem))
    219                EAG(mem) += sizeof(zend_compiled_variable) * from->last_var
     244                size += sizeof(zend_compiled_variable) * from->last_var
     245        EA_SIZE_ALIGN(size)
    220246                for (i = 0; i < from->last_var; i ++) { 
    221                         calc_string(from->vars[i].name, from->vars[i].name_len+1 TSRMLS_CC); 
    222                 } 
    223         } 
    224 #endif 
    225         if (from->filename != NULL) 
    226                 calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     247                        size += calc_string(from->vars[i].name, from->vars[i].name_len+1 TSRMLS_CC); 
     248                } 
     249        } 
     250#endif 
     251        if (from->filename != NULL) { 
     252                size += calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     253    } 
    227254#ifdef INCLUDE_DOC_COMMENTS 
    228255#ifdef ZEND_ENGINE_2 
    229     if (from->doc_comment != NULL) 
    230         calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
    231 #endif 
    232 #endif 
     256    if (from->doc_comment != NULL) { 
     257        size += calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     258    } 
     259#endif 
     260#endif 
     261 
     262    return size; 
    233263} 
    234264 
    235265/* Calculate the size of a class entry */ 
    236 static void calc_class_entry(zend_class_entry * from TSRMLS_DC) 
    237 
     266static size_t calc_class_entry(zend_class_entry * from TSRMLS_DC) 
     267
     268    size_t size = 0; 
    238269        if (from->type != ZEND_USER_CLASS) { 
    239270                DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache internal class \"%s\"\n", getpid(), from->name)); 
    240271                zend_bailout(); 
    241272        } 
    242         EACCELERATOR_ALIGN(EAG(mem)); 
    243         EAG(mem) += sizeof(ea_class_entry); 
    244  
    245         if (from->name != NULL) 
    246                 calc_string(from->name, from->name_length + 1 TSRMLS_CC); 
    247         if (from->parent != NULL && from->parent->name) 
    248                 calc_string(from->parent->name, from->parent->name_length + 1 TSRMLS_CC); 
    249 #ifdef ZEND_ENGINE_2 
    250         if (from->filename != NULL) 
    251                 calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     273        size += sizeof(ea_class_entry); 
     274    EA_SIZE_ALIGN(size); 
     275 
     276        if (from->name != NULL) { 
     277                size += calc_string(from->name, from->name_length + 1 TSRMLS_CC); 
     278    } 
     279        if (from->parent != NULL && from->parent->name) { 
     280                size += calc_string(from->parent->name, from->parent->name_length + 1 TSRMLS_CC); 
     281    } 
     282#ifdef ZEND_ENGINE_2 
     283        if (from->filename != NULL) { 
     284                size += calc_string(from->filename, strlen(from->filename) + 1 TSRMLS_CC); 
     285    } 
    252286#ifdef INCLUDE_DOC_COMMENTS 
    253      if (from->doc_comment != NULL)  
    254         calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     287     if (from->doc_comment != NULL) { 
     288        size += calc_string(from->doc_comment, from->doc_comment_len + 1 TSRMLS_CC); 
     289     } 
    255290#endif 
    256291         
    257     calc_zval_hash(&from->constants_table); 
    258         calc_zval_hash(&from->default_properties); 
    259         calc_hash(&from->properties_info, (calc_bucket_t) calc_property_info); 
     292    size += calc_zval_hash(&from->constants_table); 
     293        size += calc_zval_hash(&from->default_properties); 
     294        size += calc_hash(&from->properties_info, (calc_bucket_t) calc_property_info); 
    260295 
    261296#  ifdef ZEND_ENGINE_2_1 
    262         calc_zval_hash(&from->default_static_members); 
     297        size += calc_zval_hash(&from->default_static_members); 
    263298        if ((from->static_members != NULL) && (from->static_members != &from->default_static_members)) { 
    264299#  else 
    265300        if (from->static_members != NULL) { 
    266301#  endif 
    267                 EACCELERATOR_ALIGN(EAG(mem)); 
    268                EAG(mem) += sizeof(HashTable); 
    269                 calc_zval_hash(from->static_members); 
     302                size += sizeof(HashTable); 
     303        EA_SIZE_ALIGN(size); 
     304                size += calc_zval_hash(from->static_members); 
    270305        } 
    271306#else 
    272         calc_zval_hash(&from->default_properties); 
    273 #endif 
    274         calc_hash(&from->function_table, (calc_bucket_t) calc_op_array); 
     307        size += calc_zval_hash(&from->default_properties); 
     308#endif 
     309        size += calc_hash(&from->function_table, (calc_bucket_t) calc_op_array); 
     310 
     311    return size; 
    275312} 
    276313 
    277314/* Calculate the size of a cache entry with its given op_array and function and 
    278315   class bucket */ 
    279 int calc_size(char *key, zend_op_array * op_array, Bucket * f, Bucket * c TSRMLS_DC) 
     316size_t calc_size(char *key, zend_op_array * op_array, Bucket * f, Bucket * c TSRMLS_DC) 
    280317{ 
    281318        Bucket *b; 
     
    283320        int len = strlen(key); 
    284321        EAG(compress) = 1; 
    285        EAG(mem) = NULL
     322    size_t size = 0
    286323 
    287324        zend_hash_init(&EAG(strings), 0, NULL, NULL, 0); 
    288         EAG(mem) += offsetof(ea_cache_entry, realfilename) + len + 1; 
     325        size += offsetof(ea_cache_entry, realfilename) + len + 1; 
     326    EA_SIZE_ALIGN(size); 
    289327        zend_hash_add(&EAG(strings), key, len + 1, &key, sizeof(char *), NULL); 
    290328        b = c; 
    291329        while (b != NULL) { 
    292                 EACCELERATOR_ALIGN(EAG(mem)); 
    293                 EAG(mem) += offsetof(ea_fc_entry, htabkey) + b->nKeyLength; 
     330                size += offsetof(ea_fc_entry, htabkey) + b->nKeyLength; 
     331        EA_SIZE_ALIGN(size); 
     332 
    294333                x = b->arKey; 
    295334                zend_hash_add(&EAG(strings), b->arKey, b->nKeyLength, &x, sizeof(char *), NULL); 
     
    298337        b = f; 
    299338        while (b != NULL) { 
    300                 EACCELERATOR_ALIGN(EAG(mem)); 
    301                 EAG(mem) += offsetof(ea_fc_entry, htabkey) + b->nKeyLength; 
     339                size += offsetof(ea_fc_entry, htabkey) + b->nKeyLength; 
     340        EA_SIZE_ALIGN(size); 
     341     
    302342                x = b->arKey; 
    303343                zend_hash_add(&EAG(strings), b->arKey, b->nKeyLength, &x, sizeof(char *), NULL); 
     
    306346        while (c != NULL) { 
    307347#ifdef ZEND_ENGINE_2 
    308                 calc_class_entry(*(zend_class_entry **) c->pData TSRMLS_CC); 
     348                size += calc_class_entry(*(zend_class_entry **) c->pData TSRMLS_CC); 
    309349#else 
    310                 calc_class_entry((zend_class_entry *) c->pData TSRMLS_CC); 
     350                size += calc_class_entry((zend_class_entry *) c->pData TSRMLS_CC); 
    311351#endif 
    312352                c = c->pListNext; 
    313353        } 
    314354        while (f != NULL) { 
    315                 calc_op_array((zend_op_array *) f->pData TSRMLS_CC); 
     355                size += calc_op_array((zend_op_array *) f->pData TSRMLS_CC); 
    316356                f = f->pListNext; 
    317357        } 
    318         calc_op_array(op_array TSRMLS_CC); 
    319         EACCELERATOR_ALIGN(EAG(mem)); 
     358        size += calc_op_array(op_array TSRMLS_CC); 
    320359        zend_hash_destroy(&EAG(strings)); 
    321         return (size_t) EAG(mem); 
     360 
     361        return size; 
    322362} 
    323363 
  • eaccelerator/trunk/ea_store.h

    r286 r328  
    2929#define EA_STORE_H 
    3030 
    31 void calc_zval(zval *z TSRMLS_DC); 
    32 int calc_size(char *key, zend_op_array *op_array, Bucket *f, Bucket *c TSRMLS_DC); 
     31size_t calc_zval(zval *z TSRMLS_DC); 
     32size_t calc_size(char *key, zend_op_array *op_array, Bucket *f, Bucket *c TSRMLS_DC); 
    3333 
    3434void store_zval(zval *z TSRMLS_DC);