Lines Matching refs:ref

94 # define GC_TRACE_REF(ref, format, ...) \  argument
96 gc_trace_ref((zend_refcounted *) ref); \
99 # define GC_TRACE_SET_COLOR(ref, color) \ argument
100 GC_TRACE_REF(ref, "->%s", gc_color_name(color))
102 # define GC_TRACE_REF(ref, format, ...) argument
103 # define GC_TRACE_SET_COLOR(ref, new_color) argument
107 #define GC_REF_SET_ADDRESS(ref, a) \ argument
108 GC_INFO_SET_ADDRESS(GC_INFO(ref), a)
109 #define GC_REF_GET_COLOR(ref) \ argument
110 GC_INFO_GET_COLOR(GC_INFO(ref))
111 #define GC_REF_SET_COLOR(ref, c) \ argument
112 do { GC_TRACE_SET_COLOR(ref, c); GC_INFO_SET_COLOR(GC_INFO(ref), c); } while (0)
113 #define GC_REF_SET_BLACK(ref) \ argument
114 do { GC_TRACE_SET_COLOR(ref, GC_BLACK); GC_INFO_SET_BLACK(GC_INFO(ref)); } while (0)
115 #define GC_REF_SET_PURPLE(ref) \ argument
116 do { GC_TRACE_SET_COLOR(ref, GC_PURPLE); GC_INFO_SET_PURPLE(GC_INFO(ref)); } while (0)
128 static void gc_trace_ref(zend_refcounted *ref) { in gc_trace_ref() argument
129 if (GC_TYPE(ref) == IS_OBJECT) { in gc_trace_ref()
130 zend_object *obj = (zend_object *) ref; in gc_trace_ref()
132 ref, GC_REFCOUNT(ref), GC_ADDRESS(GC_INFO(ref)), in gc_trace_ref()
133 gc_color_name(GC_REF_GET_COLOR(ref)), in gc_trace_ref()
135 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_trace_ref()
136 zend_array *arr = (zend_array *) ref; in gc_trace_ref()
138 ref, GC_REFCOUNT(ref), GC_ADDRESS(GC_INFO(ref)), in gc_trace_ref()
139 gc_color_name(GC_REF_GET_COLOR(ref)), in gc_trace_ref()
143 ref, GC_REFCOUNT(ref), GC_ADDRESS(GC_INFO(ref)), in gc_trace_ref()
144 gc_color_name(GC_REF_GET_COLOR(ref)), in gc_trace_ref()
145 zend_get_type_by_const(GC_TYPE(ref))); in gc_trace_ref()
261 ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref) in gc_possible_root() argument
269 ZEND_ASSERT(GC_TYPE(ref) == IS_ARRAY || GC_TYPE(ref) == IS_OBJECT); in gc_possible_root()
270 ZEND_ASSERT(EXPECTED(GC_REF_GET_COLOR(ref) == GC_BLACK)); in gc_possible_root()
271 ZEND_ASSERT(!GC_ADDRESS(GC_INFO(ref))); in gc_possible_root()
285 GC_REFCOUNT(ref)++; in gc_possible_root()
287 GC_REFCOUNT(ref)--; in gc_possible_root()
288 if (UNEXPECTED(GC_REFCOUNT(ref)) == 0) { in gc_possible_root()
289 zval_dtor_func(ref); in gc_possible_root()
292 if (UNEXPECTED(GC_INFO(ref))) { in gc_possible_root()
308 GC_TRACE_SET_COLOR(ref, GC_PURPLE); in gc_possible_root()
309 GC_INFO(ref) = (newRoot - GC_G(buf)) | GC_PURPLE; in gc_possible_root()
310 newRoot->ref = ref; in gc_possible_root()
322 static zend_always_inline gc_root_buffer* gc_find_additional_buffer(zend_refcounted *ref) in gc_find_additional_buffer() argument
328 uint32_t idx = GC_ADDRESS(GC_INFO(ref)) - GC_ROOT_BUFFER_MAX_ENTRIES; in gc_find_additional_buffer()
331 if (root->ref == ref) { in gc_find_additional_buffer()
342 ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref) in gc_remove_from_buffer() argument
346 ZEND_ASSERT(GC_ADDRESS(GC_INFO(ref))); in gc_remove_from_buffer()
350 if (EXPECTED(GC_ADDRESS(GC_INFO(ref)) < GC_ROOT_BUFFER_MAX_ENTRIES)) { in gc_remove_from_buffer()
351 root = GC_G(buf) + GC_ADDRESS(GC_INFO(ref)); in gc_remove_from_buffer()
354 root = gc_find_additional_buffer(ref); in gc_remove_from_buffer()
357 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_remove_from_buffer()
358 GC_TRACE_SET_COLOR(ref, GC_PURPLE); in gc_remove_from_buffer()
360 GC_INFO(ref) = 0; in gc_remove_from_buffer()
368 static void gc_scan_black(zend_refcounted *ref) in gc_scan_black() argument
376 GC_REF_SET_BLACK(ref); in gc_scan_black()
378 if (GC_TYPE(ref) == IS_OBJECT) { in gc_scan_black()
380 zend_object *obj = (zend_object*)ref; in gc_scan_black()
382 if (EXPECTED(!(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_scan_black()
402 ref = Z_COUNTED_P(zv); in gc_scan_black()
403 GC_REFCOUNT(ref)++; in gc_scan_black()
404 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
405 gc_scan_black(ref); in gc_scan_black()
411 ref = Z_COUNTED_P(zv); in gc_scan_black()
412 GC_REFCOUNT(ref)++; in gc_scan_black()
413 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
421 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan_black()
422 if ((zend_array*)ref != &EG(symbol_table)) { in gc_scan_black()
423 ht = (zend_array*)ref; in gc_scan_black()
427 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan_black()
428 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan_black()
429 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan_black()
430 GC_REFCOUNT(ref)++; in gc_scan_black()
431 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
460 ref = Z_COUNTED_P(zv); in gc_scan_black()
461 GC_REFCOUNT(ref)++; in gc_scan_black()
462 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
463 gc_scan_black(ref); in gc_scan_black()
472 ref = Z_COUNTED_P(zv); in gc_scan_black()
473 GC_REFCOUNT(ref)++; in gc_scan_black()
474 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
479 static void gc_mark_grey(zend_refcounted *ref) in gc_mark_grey() argument
486 if (GC_REF_GET_COLOR(ref) != GC_GREY) { in gc_mark_grey()
489 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
491 if (GC_TYPE(ref) == IS_OBJECT) { in gc_mark_grey()
493 zend_object *obj = (zend_object*)ref; in gc_mark_grey()
495 if (EXPECTED(!(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_mark_grey()
515 ref = Z_COUNTED_P(zv); in gc_mark_grey()
516 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
517 GC_REFCOUNT(ref)--; in gc_mark_grey()
518 gc_mark_grey(ref); in gc_mark_grey()
523 ref = Z_COUNTED_P(zv); in gc_mark_grey()
524 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
525 GC_REFCOUNT(ref)--; in gc_mark_grey()
531 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_mark_grey()
532 if (((zend_array*)ref) == &EG(symbol_table)) { in gc_mark_grey()
533 GC_REF_SET_BLACK(ref); in gc_mark_grey()
536 ht = (zend_array*)ref; in gc_mark_grey()
538 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_mark_grey()
539 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_mark_grey()
540 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_mark_grey()
541 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
542 GC_REFCOUNT(ref)--; in gc_mark_grey()
570 ref = Z_COUNTED_P(zv); in gc_mark_grey()
571 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
572 GC_REFCOUNT(ref)--; in gc_mark_grey()
573 gc_mark_grey(ref); in gc_mark_grey()
581 ref = Z_COUNTED_P(zv); in gc_mark_grey()
582 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
583 GC_REFCOUNT(ref)--; in gc_mark_grey()
593 if (GC_REF_GET_COLOR(current->ref) == GC_PURPLE) { in gc_mark_roots()
594 gc_mark_grey(current->ref); in gc_mark_roots()
600 static void gc_scan(zend_refcounted *ref) in gc_scan() argument
607 if (GC_REF_GET_COLOR(ref) == GC_GREY) { in gc_scan()
608 if (GC_REFCOUNT(ref) > 0) { in gc_scan()
609 gc_scan_black(ref); in gc_scan()
611 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
612 if (GC_TYPE(ref) == IS_OBJECT) { in gc_scan()
614 zend_object *obj = (zend_object*)ref; in gc_scan()
616 if (EXPECTED(!(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_scan()
636 ref = Z_COUNTED_P(zv); in gc_scan()
637 gc_scan(ref); in gc_scan()
642 ref = Z_COUNTED_P(zv); in gc_scan()
648 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan()
649 if ((zend_array*)ref == &EG(symbol_table)) { in gc_scan()
650 GC_REF_SET_BLACK(ref); in gc_scan()
653 ht = (zend_array*)ref; in gc_scan()
655 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan()
656 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan()
657 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan()
685 ref = Z_COUNTED_P(zv); in gc_scan()
686 gc_scan(ref); in gc_scan()
694 ref = Z_COUNTED_P(zv); in gc_scan()
705 gc_scan(current->ref); in gc_scan_roots()
710 static void gc_add_garbage(zend_refcounted *ref) in gc_add_garbage() argument
718 GC_INFO(ref) = buf - GC_G(buf); in gc_add_garbage()
720 GC_REF_SET_ADDRESS(ref, buf - GC_G(buf)); in gc_add_garbage()
727 GC_INFO(ref) = buf - GC_G(buf); in gc_add_garbage()
729 GC_REF_SET_ADDRESS(ref, buf - GC_G(buf)); in gc_add_garbage()
745 GC_INFO(ref) = GC_ROOT_BUFFER_MAX_ENTRIES + GC_G(additional_buffer)->used; in gc_add_garbage()
747 GC_REF_SET_ADDRESS(ref, GC_ROOT_BUFFER_MAX_ENTRIES) + GC_G(additional_buffer)->used; in gc_add_garbage()
752 buf->ref = ref; in gc_add_garbage()
760 static int gc_collect_white(zend_refcounted *ref, uint32_t *flags) argument
768 if (GC_REF_GET_COLOR(ref) == GC_WHITE) {
770 GC_REF_SET_BLACK(ref);
773 if (GC_TYPE(ref) != IS_REFERENCE) {
777 if (GC_TYPE(ref) == IS_OBJECT) {
779 zend_object *obj = (zend_object*)ref;
781 if (EXPECTED(!(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED) &&
789 if (!GC_INFO(ref)) {
791 if (!GC_ADDRESS(GC_INFO(ref))) {
793 gc_add_garbage(ref);
818 ref = Z_COUNTED_P(zv);
819 GC_REFCOUNT(ref)++;
820 count += gc_collect_white(ref, flags);
828 ref = Z_COUNTED_P(zv);
829 GC_REFCOUNT(ref)++;
835 } else if (GC_TYPE(ref) == IS_ARRAY) {
838 if (!GC_INFO(ref)) {
840 if (!GC_ADDRESS(GC_INFO(ref))) {
842 gc_add_garbage(ref);
844 ht = (zend_array*)ref;
845 } else if (GC_TYPE(ref) == IS_REFERENCE) {
846 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
847 ref = Z_COUNTED(((zend_reference*)ref)->val);
848 GC_REFCOUNT(ref)++;
880 ref = Z_COUNTED_P(zv);
881 GC_REFCOUNT(ref)++;
882 count += gc_collect_white(ref, flags);
893 ref = Z_COUNTED_P(zv);
894 GC_REFCOUNT(ref)++;
908 if (GC_REF_GET_COLOR(current->ref) == GC_BLACK) {
909 if (EXPECTED(GC_ADDRESS(GC_INFO(current->ref)) < GC_ROOT_BUFFER_MAX_ENTRIES)) {
914 GC_INFO(current->ref) = 0; /* reset GC_ADDRESS() and keep GC_BLACK */
921 if (GC_REF_GET_COLOR(current->ref) == GC_WHITE) {
922 count += gc_collect_white(current->ref, flags);
949 static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root) argument
958 GC_TRACE_REF(ref, "removing from buffer");
959 if (EXPECTED(GC_ADDRESS(GC_INFO(root->ref)) < GC_ROOT_BUFFER_MAX_ENTRIES)) {
964 GC_INFO(ref) = 0;
966 } else if (GC_ADDRESS(GC_INFO(ref)) != 0
967 && GC_REF_GET_COLOR(ref) == GC_BLACK) {
968 GC_TRACE_REF(ref, "removing from buffer");
969 GC_REMOVE_FROM_BUFFER(ref);
970 } else if (GC_TYPE(ref) == IS_REFERENCE) {
971 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
972 ref = Z_COUNTED(((zend_reference*)ref)->val);
980 if (GC_TYPE(ref) == IS_OBJECT) {
982 zend_object *obj = (zend_object*)ref;
984 if (EXPECTED(!(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED) &&
1001 ref = Z_COUNTED_P(zv);
1002 gc_remove_nested_data_from_buffer(ref, NULL);
1007 ref = Z_COUNTED_P(zv);
1017 } else if (GC_TYPE(ref) == IS_ARRAY) {
1018 ht = (zend_array*)ref;
1043 ref = Z_COUNTED_P(zv);
1044 gc_remove_nested_data_from_buffer(ref, NULL);
1052 ref = Z_COUNTED_P(zv);
1126 current->refcount = GC_REFCOUNT(current->ref);
1133 p = current->ref;
1157 if (GC_REFCOUNT(current->ref) > current->refcount) {
1158 gc_remove_nested_data_from_buffer(current->ref, current);
1169 p = current->ref;
1187 p = current->ref = (zend_refcounted*)(((char*)obj) - obj->handlers->offset);
1205 p = current->ref;