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 && !(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED)) { in gc_scan_black()
380 zend_object *obj = (zend_object*)ref; in gc_scan_black()
399 ref = Z_COUNTED_P(zv); in gc_scan_black()
400 GC_REFCOUNT(ref)++; in gc_scan_black()
401 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
402 gc_scan_black(ref); in gc_scan_black()
408 ref = Z_COUNTED_P(zv); in gc_scan_black()
409 GC_REFCOUNT(ref)++; in gc_scan_black()
410 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
418 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan_black()
419 if ((zend_array*)ref != &EG(symbol_table)) { in gc_scan_black()
420 ht = (zend_array*)ref; in gc_scan_black()
424 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan_black()
425 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan_black()
426 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan_black()
427 GC_REFCOUNT(ref)++; in gc_scan_black()
428 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
457 ref = Z_COUNTED_P(zv); in gc_scan_black()
458 GC_REFCOUNT(ref)++; in gc_scan_black()
459 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
460 gc_scan_black(ref); in gc_scan_black()
469 ref = Z_COUNTED_P(zv); in gc_scan_black()
470 GC_REFCOUNT(ref)++; in gc_scan_black()
471 if (GC_REF_GET_COLOR(ref) != GC_BLACK) { in gc_scan_black()
476 static void gc_mark_grey(zend_refcounted *ref) in gc_mark_grey() argument
483 if (GC_REF_GET_COLOR(ref) != GC_GREY) { in gc_mark_grey()
486 GC_REF_SET_COLOR(ref, GC_GREY); in gc_mark_grey()
488 if (GC_TYPE(ref) == IS_OBJECT && !(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED)) { in gc_mark_grey()
490 zend_object *obj = (zend_object*)ref; in gc_mark_grey()
509 ref = Z_COUNTED_P(zv); in gc_mark_grey()
510 GC_REFCOUNT(ref)--; in gc_mark_grey()
511 gc_mark_grey(ref); in gc_mark_grey()
516 ref = Z_COUNTED_P(zv); in gc_mark_grey()
517 GC_REFCOUNT(ref)--; in gc_mark_grey()
523 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_mark_grey()
524 if (((zend_array*)ref) == &EG(symbol_table)) { in gc_mark_grey()
525 GC_REF_SET_BLACK(ref); in gc_mark_grey()
528 ht = (zend_array*)ref; in gc_mark_grey()
530 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_mark_grey()
531 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_mark_grey()
533 Z_TYPE(((zend_reference*)ref)->val) == IS_OBJECT) { in gc_mark_grey()
534 Z_TYPE_INFO(((zend_reference*)ref)->val) = IS_NULL; in gc_mark_grey()
537 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_mark_grey()
538 GC_REFCOUNT(ref)--; in gc_mark_grey()
570 ref = Z_COUNTED_P(zv); in gc_mark_grey()
571 GC_REFCOUNT(ref)--; in gc_mark_grey()
572 gc_mark_grey(ref); in gc_mark_grey()
585 ref = Z_COUNTED_P(zv); in gc_mark_grey()
586 GC_REFCOUNT(ref)--; in gc_mark_grey()
597 if (GC_REF_GET_COLOR(current->ref) == GC_PURPLE) { in gc_mark_roots()
598 gc_mark_grey(current->ref); in gc_mark_roots()
604 static void gc_scan(zend_refcounted *ref) in gc_scan() argument
611 if (GC_REF_GET_COLOR(ref) == GC_GREY) { in gc_scan()
612 if (GC_REFCOUNT(ref) > 0) { in gc_scan()
613 gc_scan_black(ref); in gc_scan()
615 GC_REF_SET_COLOR(ref, GC_WHITE); in gc_scan()
616 if (GC_TYPE(ref) == IS_OBJECT && !(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED)) { in gc_scan()
618 zend_object *obj = (zend_object*)ref; in gc_scan()
637 ref = Z_COUNTED_P(zv); in gc_scan()
638 gc_scan(ref); in gc_scan()
643 ref = Z_COUNTED_P(zv); in gc_scan()
649 } else if (GC_TYPE(ref) == IS_ARRAY) { in gc_scan()
650 if ((zend_array*)ref == &EG(symbol_table)) { in gc_scan()
651 GC_REF_SET_BLACK(ref); in gc_scan()
654 ht = (zend_array*)ref; in gc_scan()
656 } else if (GC_TYPE(ref) == IS_REFERENCE) { in gc_scan()
657 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) { in gc_scan()
658 ref = Z_COUNTED(((zend_reference*)ref)->val); in gc_scan()
686 ref = Z_COUNTED_P(zv); in gc_scan()
687 gc_scan(ref); in gc_scan()
695 ref = Z_COUNTED_P(zv); in gc_scan()
706 gc_scan(current->ref); in gc_scan_roots()
711 static void gc_add_garbage(zend_refcounted *ref) in gc_add_garbage() argument
719 GC_INFO(ref) = buf - GC_G(buf); in gc_add_garbage()
721 GC_REF_SET_ADDRESS(ref, buf - GC_G(buf)); in gc_add_garbage()
728 GC_INFO(ref) = buf - GC_G(buf); in gc_add_garbage()
730 GC_REF_SET_ADDRESS(ref, buf - GC_G(buf)); in gc_add_garbage()
746 GC_INFO(ref) = GC_ROOT_BUFFER_MAX_ENTRIES + GC_G(additional_buffer)->used; in gc_add_garbage()
748 GC_REF_SET_ADDRESS(ref, GC_ROOT_BUFFER_MAX_ENTRIES) + GC_G(additional_buffer)->used; in gc_add_garbage()
753 buf->ref = ref; in gc_add_garbage()
761 static int gc_collect_white(zend_refcounted *ref, uint32_t *flags) argument
769 if (GC_REF_GET_COLOR(ref) == GC_WHITE) {
771 GC_REF_SET_BLACK(ref);
774 if (GC_TYPE(ref) != IS_REFERENCE) {
778 if (GC_TYPE(ref) == IS_OBJECT && !(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED)) {
780 zend_object *obj = (zend_object*)ref;
790 if (!GC_INFO(ref)) {
792 if (!GC_ADDRESS(GC_INFO(ref))) {
794 gc_add_garbage(ref);
816 ref = Z_COUNTED_P(zv);
817 GC_REFCOUNT(ref)++;
818 count += gc_collect_white(ref, flags);
826 ref = Z_COUNTED_P(zv);
827 GC_REFCOUNT(ref)++;
833 } else if (GC_TYPE(ref) == IS_ARRAY) {
836 if (!GC_INFO(ref)) {
838 if (!GC_ADDRESS(GC_INFO(ref))) {
840 gc_add_garbage(ref);
842 ht = (zend_array*)ref;
843 } else if (GC_TYPE(ref) == IS_REFERENCE) {
844 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
845 ref = Z_COUNTED(((zend_reference*)ref)->val);
846 GC_REFCOUNT(ref)++;
878 ref = Z_COUNTED_P(zv);
879 GC_REFCOUNT(ref)++;
880 count += gc_collect_white(ref, flags);
891 ref = Z_COUNTED_P(zv);
892 GC_REFCOUNT(ref)++;
906 if (GC_REF_GET_COLOR(current->ref) == GC_BLACK) {
907 if (EXPECTED(GC_ADDRESS(GC_INFO(current->ref)) < GC_ROOT_BUFFER_MAX_ENTRIES)) {
912 GC_INFO(current->ref) = 0; /* reset GC_ADDRESS() and keep GC_BLACK */
919 if (GC_REF_GET_COLOR(current->ref) == GC_WHITE) {
920 count += gc_collect_white(current->ref, flags);
947 static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root) argument
955 (GC_ADDRESS(GC_INFO(ref)) != 0 &&
956 GC_REF_GET_COLOR(ref) == GC_BLACK)) {
957 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;
967 GC_REMOVE_FROM_BUFFER(ref);
970 if (GC_TYPE(ref) == IS_OBJECT && !(GC_FLAGS(ref) & IS_OBJ_FREE_CALLED)) {
972 zend_object *obj = (zend_object*)ref;
991 ref = Z_COUNTED_P(zv);
992 gc_remove_nested_data_from_buffer(ref, NULL);
997 ref = Z_COUNTED_P(zv);
1003 } else if (GC_TYPE(ref) == IS_ARRAY) {
1004 ht = (zend_array*)ref;
1005 } else if (GC_TYPE(ref) == IS_REFERENCE) {
1006 if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
1007 ref = Z_COUNTED(((zend_reference*)ref)->val);
1035 ref = Z_COUNTED_P(zv);
1036 gc_remove_nested_data_from_buffer(ref, NULL);
1044 ref = Z_COUNTED_P(zv);
1118 current->refcount = GC_REFCOUNT(current->ref);
1125 p = current->ref;
1148 if (GC_REFCOUNT(current->ref) > current->refcount) {
1149 gc_remove_nested_data_from_buffer(current->ref, current);
1161 p = current->ref;
1181 p = current->ref = (zend_refcounted*)(((char*)obj) - obj->handlers->offset);
1196 p = current->ref;