1 /*
2 +----------------------------------------------------------------------+
3 | Zend OPcache |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 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 | https://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@php.net> |
16 | Zeev Suraski <zeev@php.net> |
17 | Stanislav Malyshev <stas@zend.com> |
18 | Dmitry Stogov <dmitry@php.net> |
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 #include "zend_attributes.h"
29
30 #define ADD_DUP_SIZE(m,s) ZCG(current_persistent_script)->size += zend_shared_memdup_size((void*)m, s)
31 #define ADD_SIZE(m) ZCG(current_persistent_script)->size += ZEND_ALIGNED_SIZE(m)
32
33 # define ADD_STRING(str) ADD_DUP_SIZE((str), _ZSTR_STRUCT_SIZE(ZSTR_LEN(str)))
34
35 # define ADD_INTERNED_STRING(str) do { \
36 if (ZCG(current_persistent_script)->corrupted) { \
37 ADD_STRING(str); \
38 } else if (!IS_ACCEL_INTERNED(str)) { \
39 zend_string *tmp = accel_new_interned_string(str); \
40 if (tmp != (str)) { \
41 (str) = tmp; \
42 } else { \
43 ADD_STRING(str); \
44 } \
45 } \
46 } while (0)
47
48 static void zend_persist_zval_calc(zval *z);
49 static void zend_persist_op_array_calc(zval *zv);
50
zend_hash_persist_calc(HashTable * ht)51 static void zend_hash_persist_calc(HashTable *ht)
52 {
53 if ((HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) || ht->nNumUsed == 0) {
54 return;
55 }
56
57 if (!(HT_FLAGS(ht) & HASH_FLAG_PACKED) && ht->nNumUsed > HT_MIN_SIZE && ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 4) {
58 /* compact table */
59 uint32_t hash_size;
60
61 hash_size = (uint32_t)(-(int32_t)ht->nTableMask);
62 while (hash_size >> 2 > ht->nNumUsed) {
63 hash_size >>= 1;
64 }
65 ADD_SIZE(hash_size * sizeof(uint32_t) + ht->nNumUsed * sizeof(Bucket));
66 } else {
67 ADD_SIZE(HT_USED_SIZE(ht));
68 }
69 }
70
zend_persist_ast_calc(zend_ast * ast)71 static void zend_persist_ast_calc(zend_ast *ast)
72 {
73 uint32_t i;
74
75 if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
76 ADD_SIZE(sizeof(zend_ast_zval));
77 zend_persist_zval_calc(&((zend_ast_zval*)(ast))->val);
78 } else if (zend_ast_is_list(ast)) {
79 zend_ast_list *list = zend_ast_get_list(ast);
80 ADD_SIZE(sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
81 for (i = 0; i < list->children; i++) {
82 if (list->child[i]) {
83 zend_persist_ast_calc(list->child[i]);
84 }
85 }
86 } else {
87 uint32_t children = zend_ast_get_num_children(ast);
88 ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
89 for (i = 0; i < children; i++) {
90 if (ast->child[i]) {
91 zend_persist_ast_calc(ast->child[i]);
92 }
93 }
94 }
95 }
96
zend_persist_zval_calc(zval * z)97 static void zend_persist_zval_calc(zval *z)
98 {
99 uint32_t size;
100
101 switch (Z_TYPE_P(z)) {
102 case IS_STRING:
103 ADD_INTERNED_STRING(Z_STR_P(z));
104 if (ZSTR_IS_INTERNED(Z_STR_P(z))) {
105 Z_TYPE_FLAGS_P(z) = 0;
106 }
107 break;
108 case IS_ARRAY:
109 if (!ZCG(current_persistent_script)->corrupted
110 && zend_accel_in_shm(Z_ARR_P(z))) {
111 return;
112 }
113 size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array));
114 if (size) {
115 Bucket *p;
116
117 ADD_SIZE(size);
118 zend_hash_persist_calc(Z_ARRVAL_P(z));
119 ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(z), p) {
120 if (p->key) {
121 ADD_INTERNED_STRING(p->key);
122 }
123 zend_persist_zval_calc(&p->val);
124 } ZEND_HASH_FOREACH_END();
125 }
126 break;
127 case IS_CONSTANT_AST:
128 if (ZCG(current_persistent_script)->corrupted
129 || !zend_accel_in_shm(Z_AST_P(z))) {
130 size = zend_shared_memdup_size(Z_AST_P(z), sizeof(zend_ast_ref));
131 if (size) {
132 ADD_SIZE(size);
133 zend_persist_ast_calc(Z_ASTVAL_P(z));
134 }
135 }
136 break;
137 default:
138 ZEND_ASSERT(Z_TYPE_P(z) < IS_STRING);
139 break;
140 }
141 }
142
zend_persist_attributes_calc(HashTable * attributes)143 static void zend_persist_attributes_calc(HashTable *attributes)
144 {
145 if (!zend_shared_alloc_get_xlat_entry(attributes)
146 && (ZCG(current_persistent_script)->corrupted
147 || !zend_accel_in_shm(attributes))) {
148 zend_attribute *attr;
149 uint32_t i;
150
151 zend_shared_alloc_register_xlat_entry(attributes, attributes);
152 ADD_SIZE(sizeof(HashTable));
153 zend_hash_persist_calc(attributes);
154
155 ZEND_HASH_FOREACH_PTR(attributes, attr) {
156 ADD_SIZE(ZEND_ATTRIBUTE_SIZE(attr->argc));
157 ADD_INTERNED_STRING(attr->name);
158 ADD_INTERNED_STRING(attr->lcname);
159
160 for (i = 0; i < attr->argc; i++) {
161 if (attr->args[i].name) {
162 ADD_INTERNED_STRING(attr->args[i].name);
163 }
164 zend_persist_zval_calc(&attr->args[i].value);
165 }
166 } ZEND_HASH_FOREACH_END();
167 }
168 }
169
zend_persist_type_calc(zend_type * type)170 static void zend_persist_type_calc(zend_type *type)
171 {
172 if (ZEND_TYPE_HAS_LIST(*type)) {
173 ADD_SIZE(ZEND_TYPE_LIST_SIZE(ZEND_TYPE_LIST(*type)->num_types));
174 }
175
176 zend_type *single_type;
177 ZEND_TYPE_FOREACH(*type, single_type) {
178 if (ZEND_TYPE_HAS_NAME(*single_type)) {
179 zend_string *type_name = ZEND_TYPE_NAME(*single_type);
180 ADD_INTERNED_STRING(type_name);
181 ZEND_TYPE_SET_PTR(*single_type, type_name);
182 }
183 } ZEND_TYPE_FOREACH_END();
184 }
185
zend_persist_op_array_calc_ex(zend_op_array * op_array)186 static void zend_persist_op_array_calc_ex(zend_op_array *op_array)
187 {
188 if (op_array->function_name) {
189 zend_string *old_name = op_array->function_name;
190 ADD_INTERNED_STRING(op_array->function_name);
191 /* Remember old function name, so it can be released multiple times if shared. */
192 if (op_array->function_name != old_name
193 && !zend_shared_alloc_get_xlat_entry(&op_array->function_name)) {
194 zend_shared_alloc_register_xlat_entry(&op_array->function_name, old_name);
195 }
196 }
197
198 if (op_array->scope) {
199 if (zend_shared_alloc_get_xlat_entry(op_array->opcodes)) {
200 /* already stored */
201 ADD_SIZE(ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist_calc(op_array)));
202 return;
203 }
204 }
205
206 if (op_array->scope
207 && !(op_array->fn_flags & ZEND_ACC_CLOSURE)
208 && (op_array->scope->ce_flags & ZEND_ACC_CACHED)) {
209 return;
210 }
211
212 if (op_array->static_variables && !zend_accel_in_shm(op_array->static_variables)) {
213 if (!zend_shared_alloc_get_xlat_entry(op_array->static_variables)) {
214 Bucket *p;
215
216 zend_shared_alloc_register_xlat_entry(op_array->static_variables, op_array->static_variables);
217 ADD_SIZE(sizeof(HashTable));
218 zend_hash_persist_calc(op_array->static_variables);
219 ZEND_HASH_FOREACH_BUCKET(op_array->static_variables, p) {
220 ZEND_ASSERT(p->key != NULL);
221 ADD_INTERNED_STRING(p->key);
222 zend_persist_zval_calc(&p->val);
223 } ZEND_HASH_FOREACH_END();
224 }
225 }
226
227 if (op_array->literals) {
228 zval *p = op_array->literals;
229 zval *end = p + op_array->last_literal;
230 ADD_SIZE(sizeof(zval) * op_array->last_literal);
231 while (p < end) {
232 zend_persist_zval_calc(p);
233 p++;
234 }
235 }
236
237 zend_shared_alloc_register_xlat_entry(op_array->opcodes, op_array->opcodes);
238 ADD_SIZE(sizeof(zend_op) * op_array->last);
239
240 if (op_array->filename) {
241 ADD_STRING(op_array->filename);
242 }
243
244 if (op_array->arg_info) {
245 zend_arg_info *arg_info = op_array->arg_info;
246 uint32_t num_args = op_array->num_args;
247 uint32_t i;
248
249 if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
250 num_args++;
251 }
252 if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
253 arg_info--;
254 num_args++;
255 }
256 ADD_SIZE(sizeof(zend_arg_info) * num_args);
257 for (i = 0; i < num_args; i++) {
258 if (arg_info[i].name) {
259 ADD_INTERNED_STRING(arg_info[i].name);
260 }
261 zend_persist_type_calc(&arg_info[i].type);
262 }
263 }
264
265 if (op_array->live_range) {
266 ADD_SIZE(sizeof(zend_live_range) * op_array->last_live_range);
267 }
268
269 if (ZCG(accel_directives).save_comments && op_array->doc_comment) {
270 ADD_STRING(op_array->doc_comment);
271 }
272
273 if (op_array->attributes) {
274 zend_persist_attributes_calc(op_array->attributes);
275 }
276
277 if (op_array->try_catch_array) {
278 ADD_SIZE(sizeof(zend_try_catch_element) * op_array->last_try_catch);
279 }
280
281 if (op_array->vars) {
282 int i;
283
284 ADD_SIZE(sizeof(zend_string*) * op_array->last_var);
285 for (i = 0; i < op_array->last_var; i++) {
286 ADD_INTERNED_STRING(op_array->vars[i]);
287 }
288 }
289
290 if (op_array->num_dynamic_func_defs) {
291 ADD_SIZE(sizeof(void *) * op_array->num_dynamic_func_defs);
292 for (uint32_t i = 0; i < op_array->num_dynamic_func_defs; i++) {
293 zval tmp;
294 ZVAL_PTR(&tmp, op_array->dynamic_func_defs[i]);
295 zend_persist_op_array_calc(&tmp);
296 }
297 }
298
299 ADD_SIZE(ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist_calc(op_array)));
300 }
301
zend_persist_op_array_calc(zval * zv)302 static void zend_persist_op_array_calc(zval *zv)
303 {
304 zend_op_array *op_array = Z_PTR_P(zv);
305 ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
306 if (!zend_shared_alloc_get_xlat_entry(op_array)) {
307 zend_shared_alloc_register_xlat_entry(op_array, op_array);
308 ADD_SIZE(sizeof(zend_op_array));
309 zend_persist_op_array_calc_ex(op_array);
310 } else {
311 /* This can happen during preloading, if a dynamic function definition is declared. */
312 }
313 }
314
zend_persist_class_method_calc(zval * zv)315 static void zend_persist_class_method_calc(zval *zv)
316 {
317 zend_op_array *op_array = Z_PTR_P(zv);
318 zend_op_array *old_op_array;
319
320 if (op_array->type != ZEND_USER_FUNCTION) {
321 ZEND_ASSERT(op_array->type == ZEND_INTERNAL_FUNCTION);
322 if (op_array->fn_flags & ZEND_ACC_ARENA_ALLOCATED) {
323 old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
324 if (!old_op_array) {
325 ADD_SIZE(sizeof(zend_internal_function));
326 zend_shared_alloc_register_xlat_entry(op_array, Z_PTR_P(zv));
327 }
328 }
329 return;
330 }
331
332 if ((op_array->fn_flags & ZEND_ACC_IMMUTABLE)
333 && !ZCG(current_persistent_script)->corrupted
334 && zend_accel_in_shm(op_array)) {
335 zend_shared_alloc_register_xlat_entry(op_array, op_array);
336 return;
337 }
338
339 old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
340 if (!old_op_array) {
341 ADD_SIZE(sizeof(zend_op_array));
342 zend_persist_op_array_calc_ex(Z_PTR_P(zv));
343 zend_shared_alloc_register_xlat_entry(op_array, Z_PTR_P(zv));
344 } else {
345 /* If op_array is shared, the function name refcount is still incremented for each use,
346 * so we need to release it here. We remembered the original function name in xlat. */
347 zend_string *old_function_name =
348 zend_shared_alloc_get_xlat_entry(&old_op_array->function_name);
349 if (old_function_name) {
350 zend_string_release_ex(old_function_name, 0);
351 }
352 }
353 }
354
zend_persist_property_info_calc(zend_property_info * prop)355 static void zend_persist_property_info_calc(zend_property_info *prop)
356 {
357 ADD_SIZE(sizeof(zend_property_info));
358 ADD_INTERNED_STRING(prop->name);
359 zend_persist_type_calc(&prop->type);
360 if (ZCG(accel_directives).save_comments && prop->doc_comment) {
361 ADD_STRING(prop->doc_comment);
362 }
363 if (prop->attributes) {
364 zend_persist_attributes_calc(prop->attributes);
365 }
366 }
367
zend_persist_class_constant_calc(zval * zv)368 static void zend_persist_class_constant_calc(zval *zv)
369 {
370 zend_class_constant *c = Z_PTR_P(zv);
371
372 if (!zend_shared_alloc_get_xlat_entry(c)) {
373 if (!ZCG(current_persistent_script)->corrupted
374 && zend_accel_in_shm(Z_PTR_P(zv))) {
375 return;
376 }
377 zend_shared_alloc_register_xlat_entry(c, c);
378 ADD_SIZE(sizeof(zend_class_constant));
379 zend_persist_zval_calc(&c->value);
380 if (ZCG(accel_directives).save_comments && c->doc_comment) {
381 ADD_STRING(c->doc_comment);
382 }
383 if (c->attributes) {
384 zend_persist_attributes_calc(c->attributes);
385 }
386 }
387 }
388
zend_persist_class_entry_calc(zend_class_entry * ce)389 void zend_persist_class_entry_calc(zend_class_entry *ce)
390 {
391 Bucket *p;
392
393 if (ce->type == ZEND_USER_CLASS) {
394 /* The same zend_class_entry may be reused by class_alias */
395 if (zend_shared_alloc_get_xlat_entry(ce)) {
396 return;
397 }
398 zend_shared_alloc_register_xlat_entry(ce, ce);
399
400 ADD_SIZE(sizeof(zend_class_entry));
401
402 if (!(ce->ce_flags & ZEND_ACC_CACHED)) {
403 ADD_INTERNED_STRING(ce->name);
404 if (ce->parent_name && !(ce->ce_flags & ZEND_ACC_LINKED)) {
405 ADD_INTERNED_STRING(ce->parent_name);
406 }
407 }
408
409 zend_hash_persist_calc(&ce->function_table);
410 ZEND_HASH_FOREACH_BUCKET(&ce->function_table, p) {
411 ZEND_ASSERT(p->key != NULL);
412 ADD_INTERNED_STRING(p->key);
413 zend_persist_class_method_calc(&p->val);
414 } ZEND_HASH_FOREACH_END();
415 if (ce->default_properties_table) {
416 int i;
417
418 ADD_SIZE(sizeof(zval) * ce->default_properties_count);
419 for (i = 0; i < ce->default_properties_count; i++) {
420 zend_persist_zval_calc(&ce->default_properties_table[i]);
421 }
422 }
423 if (ce->default_static_members_table) {
424 int i;
425
426 ADD_SIZE(sizeof(zval) * ce->default_static_members_count);
427 for (i = 0; i < ce->default_static_members_count; i++) {
428 if (Z_TYPE(ce->default_static_members_table[i]) != IS_INDIRECT) {
429 zend_persist_zval_calc(&ce->default_static_members_table[i]);
430 }
431 }
432 }
433 zend_hash_persist_calc(&ce->constants_table);
434 ZEND_HASH_FOREACH_BUCKET(&ce->constants_table, p) {
435 ZEND_ASSERT(p->key != NULL);
436 ADD_INTERNED_STRING(p->key);
437 zend_persist_class_constant_calc(&p->val);
438 } ZEND_HASH_FOREACH_END();
439
440 zend_hash_persist_calc(&ce->properties_info);
441 ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, p) {
442 zend_property_info *prop = Z_PTR(p->val);
443 ZEND_ASSERT(p->key != NULL);
444 ADD_INTERNED_STRING(p->key);
445 if (prop->ce == ce) {
446 zend_persist_property_info_calc(prop);
447 }
448 } ZEND_HASH_FOREACH_END();
449
450 if (ce->properties_info_table) {
451 ADD_SIZE(sizeof(zend_property_info *) * ce->default_properties_count);
452 }
453
454 if (ce->num_interfaces && (ce->ce_flags & ZEND_ACC_LINKED)) {
455 ADD_SIZE(sizeof(zend_class_entry*) * ce->num_interfaces);
456 }
457
458 if (ce->iterator_funcs_ptr) {
459 ADD_SIZE(sizeof(zend_class_iterator_funcs));
460 }
461
462 if (ce->ce_flags & ZEND_ACC_CACHED) {
463 return;
464 }
465
466 if (ce->info.user.filename) {
467 ADD_STRING(ce->info.user.filename);
468 }
469
470 if (ZCG(accel_directives).save_comments && ce->info.user.doc_comment) {
471 ADD_STRING(ce->info.user.doc_comment);
472 }
473
474 if (ce->attributes) {
475 zend_persist_attributes_calc(ce->attributes);
476 }
477
478 if (ce->num_interfaces) {
479 uint32_t i;
480
481 if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
482 for (i = 0; i < ce->num_interfaces; i++) {
483 ADD_INTERNED_STRING(ce->interface_names[i].name);
484 ADD_INTERNED_STRING(ce->interface_names[i].lc_name);
485 }
486 ADD_SIZE(sizeof(zend_class_name) * ce->num_interfaces);
487 }
488 }
489
490 if (ce->num_traits) {
491 uint32_t i;
492
493 for (i = 0; i < ce->num_traits; i++) {
494 ADD_INTERNED_STRING(ce->trait_names[i].name);
495 ADD_INTERNED_STRING(ce->trait_names[i].lc_name);
496 }
497 ADD_SIZE(sizeof(zend_class_name) * ce->num_traits);
498
499 if (ce->trait_aliases) {
500 i = 0;
501 while (ce->trait_aliases[i]) {
502 if (ce->trait_aliases[i]->trait_method.method_name) {
503 ADD_INTERNED_STRING(ce->trait_aliases[i]->trait_method.method_name);
504 }
505 if (ce->trait_aliases[i]->trait_method.class_name) {
506 ADD_INTERNED_STRING(ce->trait_aliases[i]->trait_method.class_name);
507 }
508
509 if (ce->trait_aliases[i]->alias) {
510 ADD_INTERNED_STRING(ce->trait_aliases[i]->alias);
511 }
512 ADD_SIZE(sizeof(zend_trait_alias));
513 i++;
514 }
515 ADD_SIZE(sizeof(zend_trait_alias*) * (i + 1));
516 }
517
518 if (ce->trait_precedences) {
519 int j;
520
521 i = 0;
522 while (ce->trait_precedences[i]) {
523 ADD_INTERNED_STRING(ce->trait_precedences[i]->trait_method.method_name);
524 ADD_INTERNED_STRING(ce->trait_precedences[i]->trait_method.class_name);
525
526 for (j = 0; j < ce->trait_precedences[i]->num_excludes; j++) {
527 ADD_INTERNED_STRING(ce->trait_precedences[i]->exclude_class_names[j]);
528 }
529 ADD_SIZE(sizeof(zend_trait_precedence) + (ce->trait_precedences[i]->num_excludes - 1) * sizeof(zend_string*));
530 i++;
531 }
532 ADD_SIZE(sizeof(zend_trait_precedence*) * (i + 1));
533 }
534 }
535
536 if (ce->backed_enum_table) {
537 Bucket *p;
538 ADD_SIZE(sizeof(HashTable));
539 zend_hash_persist_calc(ce->backed_enum_table);
540 ZEND_HASH_FOREACH_BUCKET(ce->backed_enum_table, p) {
541 if (p->key != NULL) {
542 ADD_INTERNED_STRING(p->key);
543 }
544 zend_persist_zval_calc(&p->val);
545 } ZEND_HASH_FOREACH_END();
546 }
547 }
548 }
549
zend_accel_persist_class_table_calc(HashTable * class_table)550 static void zend_accel_persist_class_table_calc(HashTable *class_table)
551 {
552 Bucket *p;
553
554 zend_hash_persist_calc(class_table);
555 ZEND_HASH_FOREACH_BUCKET(class_table, p) {
556 ZEND_ASSERT(p->key != NULL);
557 ADD_INTERNED_STRING(p->key);
558 zend_persist_class_entry_calc(Z_CE(p->val));
559 } ZEND_HASH_FOREACH_END();
560 }
561
zend_persist_warnings_calc(uint32_t num_warnings,zend_error_info ** warnings)562 void zend_persist_warnings_calc(uint32_t num_warnings, zend_error_info **warnings) {
563 ADD_SIZE(num_warnings * sizeof(zend_error_info *));
564 for (uint32_t i = 0; i < num_warnings; i++) {
565 ADD_SIZE(sizeof(zend_error_info));
566 ADD_STRING(warnings[i]->filename);
567 ADD_STRING(warnings[i]->message);
568 }
569 }
570
zend_accel_script_persist_calc(zend_persistent_script * new_persistent_script,int for_shm)571 uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, int for_shm)
572 {
573 Bucket *p;
574
575 new_persistent_script->mem = NULL;
576 new_persistent_script->size = 0;
577 new_persistent_script->corrupted = 0;
578 ZCG(current_persistent_script) = new_persistent_script;
579
580 if (!for_shm) {
581 /* script is not going to be saved in SHM */
582 new_persistent_script->corrupted = 1;
583 }
584
585 ADD_SIZE(sizeof(zend_persistent_script));
586 ADD_INTERNED_STRING(new_persistent_script->script.filename);
587
588 #if defined(__AVX__) || defined(__SSE2__)
589 /* Align size to 64-byte boundary */
590 new_persistent_script->size = (new_persistent_script->size + 63) & ~63;
591 #endif
592
593 if (new_persistent_script->script.class_table.nNumUsed != new_persistent_script->script.class_table.nNumOfElements) {
594 zend_hash_rehash(&new_persistent_script->script.class_table);
595 }
596 zend_accel_persist_class_table_calc(&new_persistent_script->script.class_table);
597 if (new_persistent_script->script.function_table.nNumUsed != new_persistent_script->script.function_table.nNumOfElements) {
598 zend_hash_rehash(&new_persistent_script->script.function_table);
599 }
600 zend_hash_persist_calc(&new_persistent_script->script.function_table);
601 ZEND_HASH_FOREACH_BUCKET(&new_persistent_script->script.function_table, p) {
602 ZEND_ASSERT(p->key != NULL);
603 ADD_INTERNED_STRING(p->key);
604 zend_persist_op_array_calc(&p->val);
605 } ZEND_HASH_FOREACH_END();
606 zend_persist_op_array_calc_ex(&new_persistent_script->script.main_op_array);
607 zend_persist_warnings_calc(
608 new_persistent_script->num_warnings, new_persistent_script->warnings);
609
610 new_persistent_script->corrupted = 0;
611
612 ZCG(current_persistent_script) = NULL;
613
614 return new_persistent_script->size;
615 }
616