Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

gc.h
Go to the documentation of this file.
1
2 #ifndef RUBY_GC_H
3 #define RUBY_GC_H 1
4
5 #if defined(__x86_64__) && !defined(_ILP32) && defined(__GNUC__)
6 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("movq\t%%rsp, %0" : "=r" (*(p)))
7 #elif defined(__i386) && defined(__GNUC__)
8 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("movl\t%%esp, %0" : "=r" (*(p)))
9 #elif defined(__powerpc64__) && defined(__GNUC__)
10 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mr\t%0, %%r1" : "=r" (*(p)))
11 #else
12 NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p));
13 #define SET_MACHINE_STACK_END(p) rb_gc_set_stack_end(p)
14 #define USE_CONSERVATIVE_STACK_END
15 #endif
16
17 /* for GC debug */
18
19 #ifndef RUBY_MARK_FREE_DEBUG
20 #define RUBY_MARK_FREE_DEBUG 0
21 #endif
22
23 #if RUBY_MARK_FREE_DEBUG
24 extern int ruby_gc_debug_indent;
25
26 static inline void
27 rb_gc_debug_indent(void)
28 {
29 printf("%*s", ruby_gc_debug_indent, "");
30 }
31
32 static inline void
33 rb_gc_debug_body(const char *mode, const char *msg, int st, void *ptr)
34 {
35 if (st == 0) {
36 ruby_gc_debug_indent--;
37 }
38 rb_gc_debug_indent();
39 printf("%s: %s %s (%p)\n", mode, st ? "->" : "<-", msg, ptr);
40
41 if (st) {
42 ruby_gc_debug_indent++;
43 }
44
45 fflush(stdout);
46 }
47
48 #define RUBY_MARK_ENTER(msg) rb_gc_debug_body("mark", (msg), 1, ptr)
49 #define RUBY_MARK_LEAVE(msg) rb_gc_debug_body("mark", (msg), 0, ptr)
50 #define RUBY_FREE_ENTER(msg) rb_gc_debug_body("free", (msg), 1, ptr)
51 #define RUBY_FREE_LEAVE(msg) rb_gc_debug_body("free", (msg), 0, ptr)
52 #define RUBY_GC_INFO rb_gc_debug_indent(); printf
53
54 #else
55 #define RUBY_MARK_ENTER(msg)
56 #define RUBY_MARK_LEAVE(msg)
57 #define RUBY_FREE_ENTER(msg)
58 #define RUBY_FREE_LEAVE(msg)
59 #define RUBY_GC_INFO if(0)printf
60 #endif
61
62 #define RUBY_MARK_NO_PIN_UNLESS_NULL(ptr) do { \
63 VALUE markobj = (ptr); \
64 if (RTEST(markobj)) {rb_gc_mark_movable(markobj);} \
65 } while (0)
66 #define RUBY_MARK_UNLESS_NULL(ptr) do { \
67 VALUE markobj = (ptr); \
68 if (RTEST(markobj)) {rb_gc_mark(markobj);} \
69 } while (0)
70 #define RUBY_FREE_UNLESS_NULL(ptr) if(ptr){ruby_xfree(ptr);(ptr)=NULL;}
71
72 #if STACK_GROW_DIRECTION > 0
73 # define STACK_UPPER(x, a, b) (a)
74 #elif STACK_GROW_DIRECTION < 0
75 # define STACK_UPPER(x, a, b) (b)
76 #else
77 RUBY_EXTERN int ruby_stack_grow_direction;
78 int ruby_get_stack_grow_direction(volatile VALUE *addr);
79 # define stack_growup_p(x) ( \
80 (ruby_stack_grow_direction ? \
81 ruby_stack_grow_direction : \
82 ruby_get_stack_grow_direction(x)) > 0)
83 # define STACK_UPPER(x, a, b) (stack_growup_p(x) ? (a) : (b))
84 #endif
85
86 /*
87 STACK_GROW_DIR_DETECTION is used with STACK_DIR_UPPER.
88
89 On most normal systems, stacks grow from high address to lower address. In
90 this case, STACK_DIR_UPPER(a, b) will return (b), but on exotic systems where
91 the stack grows UP (from low address to high address), it will return (a).
92 */
93
94 #if STACK_GROW_DIRECTION
95 #define STACK_GROW_DIR_DETECTION
96 #define STACK_DIR_UPPER(a,b) STACK_UPPER(0, (a), (b))
97 #else
98 #define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection
99 #define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, (a), (b))
100 #endif
101 #define IS_STACK_DIR_UPPER() STACK_DIR_UPPER(1,0)
102
103 const char *rb_obj_info(VALUE obj);
104 const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj);
105
106 VALUE rb_gc_disable_no_rest(void);
107
108 struct rb_thread_struct;
109
110 RUBY_SYMBOL_EXPORT_BEGIN
111
112 /* exports for objspace module */
113 size_t rb_objspace_data_type_memsize(VALUE obj);
114 void rb_objspace_reachable_objects_from(VALUE obj, void (func)(VALUE, void *), void *data);
115 void rb_objspace_reachable_objects_from_root(void (func)(const char *category, VALUE, void *), void *data);
116 int rb_objspace_markable_object_p(VALUE obj);
117 int rb_objspace_internal_object_p(VALUE obj);
118 int rb_objspace_marked_object_p(VALUE obj);
119 int rb_objspace_garbage_object_p(VALUE obj);
120
121 void rb_objspace_each_objects(
122 int (*callback)(void *start, void *end, size_t stride, void *data),
123 void *data);
124
125 void rb_objspace_each_objects_without_setup(
126 int (*callback)(void *, void *, size_t, void *),
127 void *data);
128
129 RUBY_SYMBOL_EXPORT_END
130
131 #endif /* RUBY_GC_H */
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_gc_set_stack_end
void rb_gc_set_stack_end(VALUE **stack_end_p)
Definition: thread.c:4306
rb_thread_struct::func
VALUE(* func)(void *)
Definition: vm_core.h:970
ruby_stack_grow_direction
RUBY_EXTERN int ruby_stack_grow_direction
Definition: gc.h:77
ruby_get_stack_grow_direction
int ruby_get_stack_grow_direction(volatile VALUE *addr)
Definition: gc.c:4620
ptr
struct RIMemo * ptr
Definition: debug.c:74
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
rb_gc_disable_no_rest
VALUE rb_gc_disable_no_rest(void)
Definition: gc.c:9225
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
NOINLINE
NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p))
rb_objspace_garbage_object_p
int rb_objspace_garbage_object_p(VALUE obj)
Definition: gc.c:3605
rb_objspace_data_type_memsize
RUBY_SYMBOL_EXPORT_BEGIN size_t rb_objspace_data_type_memsize(VALUE obj)
Definition: gc.c:2417
fflush
int fflush(FILE *)
rb_objspace_reachable_objects_from_root
void rb_objspace_reachable_objects_from_root(void(func)(const char *category, VALUE, void *), void *data)
Definition: gc.c:9476
rb_obj_info
const char * rb_obj_info(VALUE obj)
Definition: gc.c:11655
rb_objspace_internal_object_p
int rb_objspace_internal_object_p(VALUE obj)
Definition: gc.c:3095
rb_objspace_reachable_objects_from
void rb_objspace_reachable_objects_from(VALUE obj, void(func)(VALUE, void *), void *data)
Definition: gc.c:9448
stdout
#define stdout
Definition: rb_mjit_min_header-2.7.0.h:1484
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
st
enum ruby_tag_type st
Definition: rb_mjit_min_header-2.7.0.h:11111
RUBY_EXTERN
#define RUBY_EXTERN
Definition: missing.h:77
rb_raw_obj_info
const char * rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
Definition: gc.c:11419
rb_objspace_marked_object_p
int rb_objspace_marked_object_p(VALUE obj)
Definition: gc.c:5222
rb_objspace_each_objects_without_setup
void rb_objspace_each_objects_without_setup(int(*callback)(void *, void *, size_t, void *), void *data)
rb_thread_struct
Definition: vm_core.h:910
rb_objspace_each_objects
void rb_objspace_each_objects(int(*callback)(void *start, void *end, size_t stride, void *data), void *data)
rb_objspace_markable_object_p
int rb_objspace_markable_object_p(VALUE obj)
Definition: gc.c:3598