Lines Matching refs:ref

92 # define GC_TRACE_REF(ref, format, ...) \  argument
94 gc_trace_ref((zend_refcounted *) ref); \
97 # define GC_TRACE_SET_COLOR(ref, color) \ argument
98 GC_TRACE_REF(ref, "->%s", gc_color_name(color))
100 # define GC_TRACE_REF(ref, format, ...) argument
101 # define GC_TRACE_SET_COLOR(ref, new_color) argument
106 #define GC_REF_ADDRESS(ref) \ argument
107 (((GC_TYPE_INFO(ref)) & (GC_ADDRESS << GC_INFO_SHIFT)) >> GC_INFO_SHIFT)
109 #define GC_REF_COLOR(ref) \ argument
110 (((GC_TYPE_INFO(ref)) & (GC_COLOR << GC_INFO_SHIFT)) >> GC_INFO_SHIFT)
112 #define GC_REF_CHECK_COLOR(ref, color) \ argument
113 ((GC_TYPE_INFO(ref) & (GC_COLOR << GC_INFO_SHIFT)) == ((color) << GC_INFO_SHIFT))
115 #define GC_REF_SET_INFO(ref, info) do { \ argument
116 GC_TYPE_INFO(ref) = \
117 (GC_TYPE_INFO(ref) & (GC_TYPE_MASK | GC_FLAGS_MASK)) | \
121 #define GC_REF_SET_COLOR(ref, c) do { \ argument
122 GC_TRACE_SET_COLOR(ref, c); \
123 GC_TYPE_INFO(ref) = \
124 (GC_TYPE_INFO(ref) & ~(GC_COLOR << GC_INFO_SHIFT)) | \
128 #define GC_REF_SET_BLACK(ref) do { \ argument
129 GC_TRACE_SET_COLOR(ref, GC_BLACK); \
130 GC_TYPE_INFO(ref) &= ~(GC_COLOR << GC_INFO_SHIFT); \
133 #define GC_REF_SET_PURPLE(ref) do { \ argument
134 GC_TRACE_SET_COLOR(ref, GC_PURPLE); \
135 GC_TYPE_INFO(ref) |= (GC_COLOR << GC_INFO_SHIFT); \
201 zend_refcounted *ref; member
267 #define GC_STACK_PUSH(ref) \ argument
268 gc_stack_push(&_stack, &_top, ref);
284 static zend_always_inline void gc_stack_push(gc_stack **stack, size_t *top, zend_refcounted *ref) in gc_stack_push() argument
290 (*stack)->data[(*top)++] = ref; in gc_stack_push()
327 static zend_always_inline gc_root_buffer* gc_decompress(zend_refcounted *ref, uint32_t idx) in gc_decompress() argument
331 if (EXPECTED(GC_GET_PTR(root->ref) == ref)) { in gc_decompress()
339 if (GC_GET_PTR(root->ref) == ref) { in gc_decompress()
353 ZEND_ASSERT(GC_IS_UNUSED(root->ref)); in gc_fetch_unused()
354 GC_G(unused) = GC_LIST2IDX(root->ref); in gc_fetch_unused()
360 root->ref = GC_IDX2LIST(GC_G(unused)); in gc_link_unused()
384 static void gc_trace_ref(zend_refcounted *ref) { in gc_trace_ref() argument
385 if (GC_TYPE(ref) == IS_OBJECT) { in gc_trace_ref()
386 zend_object *obj = (zend_object *) ref; in gc_trace_ref()
388 ref, GC_REFCOUNT(ref), GC_REF_ADDRESS(ref), in gc_trace_ref()
389 gc_color_name(GC_REF_COLOR(ref)), in gc_trace_ref()
391 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_trace_ref()
392 zend_array *arr = (zend_array *) ref; in gc_trace_ref()
394 ref, GC_REFCOUNT(ref), GC_REF_ADDRESS(ref), in gc_trace_ref()
395 gc_color_name(GC_REF_COLOR(ref)), in gc_trace_ref()
399 ref, GC_REFCOUNT(ref), GC_REF_ADDRESS(ref), in gc_trace_ref()
400 gc_color_name(GC_REF_COLOR(ref)), in gc_trace_ref()
401 zend_get_type_by_const(GC_TYPE(ref))); in gc_trace_ref()
494 GC_G(buf)[0].ref = NULL; in gc_enable()
574 static zend_never_inline void ZEND_FASTCALL gc_possible_root_when_full(zend_refcounted *ref) in gc_possible_root_when_full() argument
579 ZEND_ASSERT(GC_TYPE(ref) == IS_ARRAY || GC_TYPE(ref) == IS_OBJECT); in gc_possible_root_when_full()
580 ZEND_ASSERT(GC_INFO(ref) == 0); in gc_possible_root_when_full()
583 GC_ADDREF(ref); in gc_possible_root_when_full()
585 if (UNEXPECTED(GC_DELREF(ref)) == 0) { in gc_possible_root_when_full()
586 rc_dtor_func(ref); in gc_possible_root_when_full()
588 } else if (UNEXPECTED(GC_INFO(ref))) { in gc_possible_root_when_full()
606 newRoot->ref = ref; /* GC_ROOT tag is 0 */ in gc_possible_root_when_full()
607 GC_TRACE_SET_COLOR(ref, GC_PURPLE); in gc_possible_root_when_full()
610 GC_REF_SET_INFO(ref, idx | GC_PURPLE); in gc_possible_root_when_full()
618 ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref) in gc_possible_root() argument
634 gc_possible_root_when_full(ref); in gc_possible_root()
638 ZEND_ASSERT(GC_TYPE(ref) == IS_ARRAY || GC_TYPE(ref) == IS_OBJECT); in gc_possible_root()
639 ZEND_ASSERT(GC_INFO(ref) == 0); in gc_possible_root()
642 newRoot->ref = ref; /* GC_ROOT tag is 0 */ in gc_possible_root()
643 GC_TRACE_SET_COLOR(ref, GC_PURPLE); in gc_possible_root()
646 GC_REF_SET_INFO(ref, idx | GC_PURPLE); in gc_possible_root()
654 static zend_never_inline void ZEND_FASTCALL gc_remove_compressed(zend_refcounted *ref, uint32_t idx) in gc_remove_compressed() argument
656 gc_root_buffer *root = gc_decompress(ref, idx); in gc_remove_compressed()
660 ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref) in gc_remove_from_buffer() argument
663 uint32_t idx = GC_REF_ADDRESS(ref); in gc_remove_from_buffer()
667 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_remove_from_buffer()
668 GC_TRACE_SET_COLOR(ref, GC_BLACK); in gc_remove_from_buffer()
670 GC_REF_SET_INFO(ref, 0); in gc_remove_from_buffer()
674 gc_remove_compressed(ref, idx); in gc_remove_from_buffer()
683 static void gc_scan_black(zend_refcounted *ref, gc_stack *stack) in gc_scan_black() argument
691 if (GC_TYPE(ref) == IS_OBJECT) { in gc_scan_black()
693 zend_object *obj = (zend_object*)ref; in gc_scan_black()
695 if (EXPECTED(!(OBJ_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_scan_black()
715 ref = Z_COUNTED_P(zv); in gc_scan_black()
716 GC_ADDREF(ref); in gc_scan_black()
717 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan_black()
718 GC_REF_SET_BLACK(ref); in gc_scan_black()
719 GC_STACK_PUSH(ref); in gc_scan_black()
725 ref = Z_COUNTED_P(zv); in gc_scan_black()
726 GC_ADDREF(ref); in gc_scan_black()
727 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan_black()
728 GC_REF_SET_BLACK(ref); in gc_scan_black()
736 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan_black()
737 if ((zend_array*)ref != &EG(symbol_table)) { in gc_scan_black()
738 ht = (zend_array*)ref; in gc_scan_black()
742 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan_black()
743 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan_black()
744 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan_black()
745 GC_ADDREF(ref); in gc_scan_black()
746 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan_black()
747 GC_REF_SET_BLACK(ref); in gc_scan_black()
776 ref = Z_COUNTED_P(zv); in gc_scan_black()
777 GC_ADDREF(ref); in gc_scan_black()
778 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan_black()
779 GC_REF_SET_BLACK(ref); in gc_scan_black()
780 GC_STACK_PUSH(ref); in gc_scan_black()
789 ref = Z_COUNTED_P(zv); in gc_scan_black()
790 GC_ADDREF(ref); in gc_scan_black()
791 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan_black()
792 GC_REF_SET_BLACK(ref); in gc_scan_black()
797 ref = GC_STACK_POP(); in gc_scan_black()
798 if (ref) { in gc_scan_black()
803 static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack) in gc_mark_grey() argument
813 if (GC_TYPE(ref) == IS_OBJECT) { in gc_mark_grey()
815 zend_object *obj = (zend_object*)ref; in gc_mark_grey()
817 if (EXPECTED(!(OBJ_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_mark_grey()
837 ref = Z_COUNTED_P(zv); in gc_mark_grey()
838 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
839 GC_DELREF(ref); in gc_mark_grey()
840 if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_mark_grey()
841 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
842 GC_STACK_PUSH(ref); in gc_mark_grey()
848 ref = Z_COUNTED_P(zv); in gc_mark_grey()
849 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
850 GC_DELREF(ref); in gc_mark_grey()
851 if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_mark_grey()
852 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
860 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_mark_grey()
861 if (((zend_array*)ref) == &EG(symbol_table)) { in gc_mark_grey()
862 GC_REF_SET_BLACK(ref); in gc_mark_grey()
865 ht = (zend_array*)ref; in gc_mark_grey()
867 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_mark_grey()
868 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_mark_grey()
869 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_mark_grey()
870 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
871 GC_DELREF(ref); in gc_mark_grey()
872 if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_mark_grey()
873 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
902 ref = Z_COUNTED_P(zv); in gc_mark_grey()
903 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
904 GC_DELREF(ref); in gc_mark_grey()
905 if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_mark_grey()
906 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
907 GC_STACK_PUSH(ref); in gc_mark_grey()
916 ref = Z_COUNTED_P(zv); in gc_mark_grey()
917 ZEND_ASSERT(GC_REFCOUNT(ref) > 0); in gc_mark_grey()
918 GC_DELREF(ref); in gc_mark_grey()
919 if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_mark_grey()
920 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
925 ref = GC_STACK_POP(); in gc_mark_grey()
926 } while (ref); in gc_mark_grey()
941 while (!GC_IS_UNUSED(free->ref)) { in gc_compact()
944 while (GC_IS_UNUSED(scan->ref)) { in gc_compact()
948 p = scan->ref; in gc_compact()
949 free->ref = p; in gc_compact()
975 if (GC_IS_ROOT(current->ref)) { in gc_mark_roots()
976 if (GC_REF_CHECK_COLOR(current->ref, GC_PURPLE)) { in gc_mark_roots()
977 GC_REF_SET_COLOR(current->ref, GC_GREY); in gc_mark_roots()
978 gc_mark_grey(current->ref, stack); in gc_mark_roots()
985 static void gc_scan(zend_refcounted *ref, gc_stack *stack) in gc_scan() argument
993 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_scan()
994 if (GC_REFCOUNT(ref) > 0) { in gc_scan()
995 if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_scan()
996 GC_REF_SET_BLACK(ref); in gc_scan()
1002 gc_scan_black(ref, _stack->next); in gc_scan()
1006 if (GC_TYPE(ref) == IS_OBJECT) { in gc_scan()
1008 zend_object *obj = (zend_object*)ref; in gc_scan()
1010 if (EXPECTED(!(OBJ_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_scan()
1030 ref = Z_COUNTED_P(zv); in gc_scan()
1031 if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_scan()
1032 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
1033 GC_STACK_PUSH(ref); in gc_scan()
1039 ref = Z_COUNTED_P(zv); in gc_scan()
1040 if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_scan()
1041 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
1049 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan()
1050 if ((zend_array*)ref == &EG(symbol_table)) { in gc_scan()
1051 GC_REF_SET_BLACK(ref); in gc_scan()
1054 ht = (zend_array*)ref; in gc_scan()
1056 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan()
1057 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan()
1058 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan()
1059 if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_scan()
1060 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
1089 ref = Z_COUNTED_P(zv); in gc_scan()
1090 if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_scan()
1091 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
1092 GC_STACK_PUSH(ref); in gc_scan()
1101 ref = Z_COUNTED_P(zv); in gc_scan()
1102 if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { in gc_scan()
1103 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
1110 ref = GC_STACK_POP(); in gc_scan()
1111 if (ref) { in gc_scan()
1122 if (GC_IS_ROOT(current->ref)) { in gc_scan_roots()
1123 if (GC_REF_CHECK_COLOR(current->ref, GC_GREY)) { in gc_scan_roots()
1124 GC_REF_SET_COLOR(current->ref, GC_WHITE); in gc_scan_roots()
1125 gc_scan(current->ref, stack); in gc_scan_roots()
1132 static void gc_add_garbage(zend_refcounted *ref) in gc_add_garbage() argument
1150 buf->ref = GC_MAKE_GARBAGE(ref); in gc_add_garbage()
1153 GC_REF_SET_INFO(ref, idx | GC_BLACK); in gc_add_garbage()
1157 static int gc_collect_white(zend_refcounted *ref, uint32_t *flags, gc_stack *stack) in gc_collect_white() argument
1167 if (GC_TYPE(ref) != IS_REFERENCE) { in gc_collect_white()
1171 if (GC_TYPE(ref) == IS_OBJECT) { in gc_collect_white()
1173 zend_object *obj = (zend_object*)ref; in gc_collect_white()
1175 if (EXPECTED(!(OBJ_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_collect_white()
1182 if (!GC_INFO(ref)) { in gc_collect_white()
1183 gc_add_garbage(ref); in gc_collect_white()
1208 ref = Z_COUNTED_P(zv); in gc_collect_white()
1209 GC_ADDREF(ref); in gc_collect_white()
1210 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_white()
1211 GC_REF_SET_BLACK(ref); in gc_collect_white()
1212 GC_STACK_PUSH(ref); in gc_collect_white()
1221 ref = Z_COUNTED_P(zv); in gc_collect_white()
1222 GC_ADDREF(ref); in gc_collect_white()
1223 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_white()
1224 GC_REF_SET_BLACK(ref); in gc_collect_white()
1232 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_collect_white()
1234 if (!GC_INFO(ref)) { in gc_collect_white()
1235 gc_add_garbage(ref); in gc_collect_white()
1237 ht = (zend_array*)ref; in gc_collect_white()
1238 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_collect_white()
1239 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_collect_white()
1240 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_collect_white()
1241 GC_ADDREF(ref); in gc_collect_white()
1242 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_white()
1243 GC_REF_SET_BLACK(ref); in gc_collect_white()
1276 ref = Z_COUNTED_P(zv); in gc_collect_white()
1277 GC_ADDREF(ref); in gc_collect_white()
1278 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_white()
1279 GC_REF_SET_BLACK(ref); in gc_collect_white()
1280 GC_STACK_PUSH(ref); in gc_collect_white()
1292 ref = Z_COUNTED_P(zv); in gc_collect_white()
1293 GC_ADDREF(ref); in gc_collect_white()
1294 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_white()
1295 GC_REF_SET_BLACK(ref); in gc_collect_white()
1300 ref = GC_STACK_POP(); in gc_collect_white()
1301 } while (ref); in gc_collect_white()
1309 zend_refcounted *ref; in gc_collect_roots() local
1316 if (GC_IS_ROOT(current->ref)) { in gc_collect_roots()
1317 if (GC_REF_CHECK_COLOR(current->ref, GC_BLACK)) { in gc_collect_roots()
1318 GC_REF_SET_INFO(current->ref, 0); /* reset GC_ADDRESS() and keep GC_BLACK */ in gc_collect_roots()
1333 ref = current->ref; in gc_collect_roots()
1334 ZEND_ASSERT(GC_IS_ROOT(ref)); in gc_collect_roots()
1335 current->ref = GC_MAKE_GARBAGE(ref); in gc_collect_roots()
1336 if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { in gc_collect_roots()
1337 GC_REF_SET_BLACK(ref); in gc_collect_roots()
1338 count += gc_collect_white(ref, flags, stack); in gc_collect_roots()
1346 static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root) in gc_remove_nested_data_from_buffer() argument
1355 GC_TRACE_REF(ref, "removing from buffer"); in gc_remove_nested_data_from_buffer()
1357 GC_REF_SET_INFO(ref, 0); in gc_remove_nested_data_from_buffer()
1359 } else if (GC_REF_ADDRESS(ref) != 0 in gc_remove_nested_data_from_buffer()
1360 && GC_REF_CHECK_COLOR(ref, GC_BLACK)) { in gc_remove_nested_data_from_buffer()
1361 GC_TRACE_REF(ref, "removing from buffer"); in gc_remove_nested_data_from_buffer()
1362 GC_REMOVE_FROM_BUFFER(ref); in gc_remove_nested_data_from_buffer()
1363 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_remove_nested_data_from_buffer()
1364 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_remove_nested_data_from_buffer()
1365 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_remove_nested_data_from_buffer()
1373 if (GC_TYPE(ref) == IS_OBJECT) { in gc_remove_nested_data_from_buffer()
1375 zend_object *obj = (zend_object*)ref; in gc_remove_nested_data_from_buffer()
1377 if (EXPECTED(!(OBJ_FLAGS(ref) & IS_OBJ_FREE_CALLED) && in gc_remove_nested_data_from_buffer()
1394 ref = Z_COUNTED_P(zv); in gc_remove_nested_data_from_buffer()
1395 gc_remove_nested_data_from_buffer(ref, NULL); in gc_remove_nested_data_from_buffer()
1400 ref = Z_COUNTED_P(zv); in gc_remove_nested_data_from_buffer()
1410 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_remove_nested_data_from_buffer()
1411 ht = (zend_array*)ref; in gc_remove_nested_data_from_buffer()
1436 ref = Z_COUNTED_P(zv); in gc_remove_nested_data_from_buffer()
1437 gc_remove_nested_data_from_buffer(ref, NULL); in gc_remove_nested_data_from_buffer()
1445 ref = Z_COUNTED_P(zv); in gc_remove_nested_data_from_buffer()
1503 if (GC_IS_GARBAGE(current->ref)) { in zend_gc_collect_cycles()
1504 p = GC_GET_PTR(current->ref); in zend_gc_collect_cycles()
1518 if (GC_IS_GARBAGE(current->ref)) { in zend_gc_collect_cycles()
1519 p = GC_GET_PTR(current->ref); in zend_gc_collect_cycles()
1542 if (GC_IS_GARBAGE(current->ref)) { in zend_gc_collect_cycles()
1543 p = GC_GET_PTR(current->ref); in zend_gc_collect_cycles()
1566 if (GC_IS_GARBAGE(current->ref)) { in zend_gc_collect_cycles()
1567 p = GC_GET_PTR(current->ref); in zend_gc_collect_cycles()
1585 current->ref = GC_MAKE_GARBAGE(((char*)obj) - obj->handlers->offset); in zend_gc_collect_cycles()
1604 if (GC_IS_GARBAGE(current->ref)) { in zend_gc_collect_cycles()
1605 p = GC_GET_PTR(current->ref); in zend_gc_collect_cycles()