Changeset 328
- Timestamp:
- 08/20/07 13:33:54 (9 months ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/cache.c (modified) (1 diff)
- eaccelerator/trunk/ea_store.c (modified) (10 diffs)
- eaccelerator/trunk/ea_store.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r327 r328 1 2007-08-20 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 * Rewrite the calc_* values so it no longer uses the EAG(mem) global. 3 1 4 2007-08-19 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 5 * Fix an E_NOTICE error in the control panel eaccelerator/trunk/cache.c
r296 r328 219 219 zend_hash_init(&EAG(strings), 0, NULL, NULL, 0); 220 220 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); 223 223 zend_hash_destroy(&EAG(strings)); 224 225 size = (long) EAG(mem);226 224 227 225 EAG(mem) = NULL; eaccelerator/trunk/ea_store.c
r291 r328 36 36 /* Functions to calculate the size of different structure that a compiled php */ 37 37 /* script contains. */ 38 /* Each function needs to return a size that is aligned to the machine word */ 39 /* size. */ 38 40 /******************************************************************************/ 39 41 … … 41 43 inline 42 44 #endif 43 static voidcalc_string(char *str, int len TSRMLS_DC)45 static size_t calc_string(char *str, int len TSRMLS_DC) 44 46 { 45 47 if (len > MAX_DUP_STR_LEN || 46 48 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 55 typedef size_t (*calc_bucket_t) (void * TSRMLS_DC); 53 56 54 57 #define calc_hash_ex(from, start, calc_bucket) \ … … 64 67 calc_hash_ex(from, start, (calc_bucket_t)calc_zval_ptr) 65 68 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); 69 static 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 81 static 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); 80 89 #ifdef INCLUDE_DOC_COMMENTS 81 90 #ifdef ZEND_ENGINE_2_1 82 91 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); 84 93 } 85 94 #endif 86 95 #endif 96 return size; 87 97 } 88 98 #endif 89 99 90 100 /* Calculate the size of an HashTable */ 91 static voidcalc_hash_int(HashTable * source, Bucket * start,101 static size_t calc_hash_int(HashTable * source, Bucket * start, 92 102 calc_bucket_t calc_bucket TSRMLS_DC) 93 103 { 94 104 Bucket *p; 105 size_t size = 0; 95 106 96 107 if (source->nNumOfElements > 0) { 97 108 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); 100 111 } 101 112 p = start; 102 113 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); 106 117 p = p->pListNext; 107 118 } 108 119 } 109 } 110 111 void calc_zval(zval * zv TSRMLS_DC) 112 { 120 return size; 121 } 122 123 size_t calc_zval(zval *zv TSRMLS_DC) 124 { 125 size_t size = 0; 126 113 127 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; 133 151 } 134 152 135 153 /* Calculate the size of an op_array */ 136 static voidcalc_op_array(zend_op_array * from TSRMLS_DC)154 static size_t calc_op_array(zend_op_array * from TSRMLS_DC) 137 155 { 138 156 zend_op *opline; 139 157 zend_op *end; 158 size_t size = 0; 140 159 141 160 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); 144 163 } 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); 147 166 } else { 148 167 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache function \"%s\"\n", getpid(), from->function_name)); … … 152 171 if (from->num_args > 0) { 153 172 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); 156 175 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 } 161 182 } 162 183 } 163 184 #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 } 169 192 #ifdef ZEND_ENGINE_2 170 193 if (from->scope != NULL) { … … 173 196 while (q != NULL) { 174 197 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); 176 199 break; 177 200 } … … 180 203 } 181 204 #endif 182 if (from->type == ZEND_INTERNAL_FUNCTION) 205 if (from->type == ZEND_INTERNAL_FUNCTION) { 183 206 return; 207 } 184 208 185 209 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); 188 212 189 213 opline = from->opcodes; … … 191 215 EAG(compress) = 0; 192 216 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 } 197 223 } 198 224 EAG(compress) = 1; 199 225 } 200 226 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); 203 229 } 204 230 #ifdef ZEND_ENGINE_2 205 231 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); 208 234 } 209 235 #endif 210 236 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); 214 240 } 215 241 #ifdef ZEND_ENGINE_2_1 216 242 if (from->vars != NULL) { 217 243 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); 220 246 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 } 227 254 #ifdef INCLUDE_DOC_COMMENTS 228 255 #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; 233 263 } 234 264 235 265 /* Calculate the size of a class entry */ 236 static void calc_class_entry(zend_class_entry * from TSRMLS_DC) 237 { 266 static size_t calc_class_entry(zend_class_entry * from TSRMLS_DC) 267 { 268 size_t size = 0; 238 269 if (from->type != ZEND_USER_CLASS) { 239 270 DBG(ea_debug_error, ("[%d] EACCELERATOR can't cache internal class \"%s\"\n", getpid(), from->name)); 240 271 zend_bailout(); 241 272 } 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 } 252 286 #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 } 255 290 #endif 256 291 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); 260 295 261 296 # ifdef ZEND_ENGINE_2_1 262 calc_zval_hash(&from->default_static_members);297 size += calc_zval_hash(&from->default_static_members); 263 298 if ((from->static_members != NULL) && (from->static_members != &from->default_static_members)) { 264 299 # else 265 300 if (from->static_members != NULL) { 266 301 # 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); 270 305 } 271 306 #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; 275 312 } 276 313 277 314 /* Calculate the size of a cache entry with its given op_array and function and 278 315 class bucket */ 279 int calc_size(char *key, zend_op_array * op_array, Bucket * f, Bucket * c TSRMLS_DC)316 size_t calc_size(char *key, zend_op_array * op_array, Bucket * f, Bucket * c TSRMLS_DC) 280 317 { 281 318 Bucket *b; … … 283 320 int len = strlen(key); 284 321 EAG(compress) = 1; 285 EAG(mem) = NULL;322 size_t size = 0; 286 323 287 324 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); 289 327 zend_hash_add(&EAG(strings), key, len + 1, &key, sizeof(char *), NULL); 290 328 b = c; 291 329 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 294 333 x = b->arKey; 295 334 zend_hash_add(&EAG(strings), b->arKey, b->nKeyLength, &x, sizeof(char *), NULL); … … 298 337 b = f; 299 338 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 302 342 x = b->arKey; 303 343 zend_hash_add(&EAG(strings), b->arKey, b->nKeyLength, &x, sizeof(char *), NULL); … … 306 346 while (c != NULL) { 307 347 #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); 309 349 #else 310 calc_class_entry((zend_class_entry *) c->pData TSRMLS_CC);350 size += calc_class_entry((zend_class_entry *) c->pData TSRMLS_CC); 311 351 #endif 312 352 c = c->pListNext; 313 353 } 314 354 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); 316 356 f = f->pListNext; 317 357 } 318 calc_op_array(op_array TSRMLS_CC); 319 EACCELERATOR_ALIGN(EAG(mem)); 358 size += calc_op_array(op_array TSRMLS_CC); 320 359 zend_hash_destroy(&EAG(strings)); 321 return (size_t) EAG(mem); 360 361 return size; 322 362 } 323 363 eaccelerator/trunk/ea_store.h
r286 r328 29 29 #define EA_STORE_H 30 30 31 voidcalc_zval(zval *z TSRMLS_DC);32 int calc_size(char *key, zend_op_array *op_array, Bucket *f, Bucket *c TSRMLS_DC);31 size_t calc_zval(zval *z TSRMLS_DC); 32 size_t calc_size(char *key, zend_op_array *op_array, Bucket *f, Bucket *c TSRMLS_DC); 33 33 34 34 void store_zval(zval *z TSRMLS_DC);