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(__powerpc__) || defined(__powerpc64__)) && defined(__GNUC__) && !defined(_AIX)
10 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mr\t%0, %%r1" : "=r" (*(p)))
11 #elif (defined(__powerpc__) || defined(__powerpc64__)) && defined(__GNUC__) && defined(_AIX)
12 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mr %0,1" : "=r" (*(p)))
13 #elif defined(__aarch64__) && defined(__GNUC__)
14 #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mov\t%0, sp" : "=r" (*(p)))
16 NOINLINE(void rb_gc_set_stack_end(VALUE
**stack_end_p
));
17 #define SET_MACHINE_STACK_END(p) rb_gc_set_stack_end(p)
18 #define USE_CONSERVATIVE_STACK_END
21 #define RB_GC_SAVE_MACHINE_CONTEXT(th) \
23 FLUSH_REGISTER_WINDOWS; \
24 setjmp((th)->ec->machine.regs); \
25 SET_MACHINE_STACK_END(&(th)->ec->machine.stack_end); \
30 #ifndef RUBY_MARK_FREE_DEBUG
31 #define RUBY_MARK_FREE_DEBUG 0
34 #if RUBY_MARK_FREE_DEBUG
35 extern int ruby_gc_debug_indent
;
38 rb_gc_debug_indent(void)
40 ruby_debug_printf("%*s", ruby_gc_debug_indent
, "");
44 rb_gc_debug_body(const char *mode
, const char *msg
, int st
, void *ptr
)
47 ruby_gc_debug_indent
--;
50 ruby_debug_printf("%s: %s %s (%p)\n", mode
, st
? "->" : "<-", msg
, ptr
);
53 ruby_gc_debug_indent
++;
59 #define RUBY_MARK_ENTER(msg) rb_gc_debug_body("mark", (msg), 1, ptr)
60 #define RUBY_MARK_LEAVE(msg) rb_gc_debug_body("mark", (msg), 0, ptr)
61 #define RUBY_FREE_ENTER(msg) rb_gc_debug_body("free", (msg), 1, ptr)
62 #define RUBY_FREE_LEAVE(msg) rb_gc_debug_body("free", (msg), 0, ptr)
63 #define RUBY_GC_INFO rb_gc_debug_indent(), ruby_debug_printf
66 #define RUBY_MARK_ENTER(msg)
67 #define RUBY_MARK_LEAVE(msg)
68 #define RUBY_FREE_ENTER(msg)
69 #define RUBY_FREE_LEAVE(msg)
70 #define RUBY_GC_INFO if(0)printf
73 #define RUBY_MARK_MOVABLE_UNLESS_NULL(ptr) do { \
74 VALUE markobj = (ptr); \
75 if (RTEST(markobj)) {rb_gc_mark_movable(markobj);} \
77 #define RUBY_MARK_UNLESS_NULL(ptr) do { \
78 VALUE markobj = (ptr); \
79 if (RTEST(markobj)) {rb_gc_mark(markobj);} \
81 #define RUBY_FREE_UNLESS_NULL(ptr) if(ptr){ruby_xfree(ptr);(ptr)=NULL;}
83 #if STACK_GROW_DIRECTION > 0
84 # define STACK_UPPER(x, a, b) (a)
85 #elif STACK_GROW_DIRECTION < 0
86 # define STACK_UPPER(x, a, b) (b)
88 RUBY_EXTERN
int ruby_stack_grow_direction
;
89 int ruby_get_stack_grow_direction(volatile VALUE
*addr
);
90 # define stack_growup_p(x) ( \
91 (ruby_stack_grow_direction ? \
92 ruby_stack_grow_direction : \
93 ruby_get_stack_grow_direction(x)) > 0)
94 # define STACK_UPPER(x, a, b) (stack_growup_p(x) ? (a) : (b))
98 STACK_GROW_DIR_DETECTION is used with STACK_DIR_UPPER.
100 On most normal systems, stacks grow from high address to lower address. In
101 this case, STACK_DIR_UPPER(a, b) will return (b), but on exotic systems where
102 the stack grows UP (from low address to high address), it will return (a).
105 #if STACK_GROW_DIRECTION
106 #define STACK_GROW_DIR_DETECTION
107 #define STACK_DIR_UPPER(a,b) STACK_UPPER(0, (a), (b))
109 #define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection
110 #define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, (a), (b))
112 #define IS_STACK_DIR_UPPER() STACK_DIR_UPPER(1,0)
114 const char *rb_obj_info(VALUE obj
);
115 const char *rb_raw_obj_info(char *buff
, const int buff_size
, VALUE obj
);
117 VALUE
rb_gc_disable_no_rest(void);
119 struct rb_thread_struct
;
121 RUBY_SYMBOL_EXPORT_BEGIN
123 /* exports for objspace module */
124 size_t rb_objspace_data_type_memsize(VALUE obj
);
125 void rb_objspace_reachable_objects_from(VALUE obj
, void (func
)(VALUE
, void *), void *data
);
126 void rb_objspace_reachable_objects_from_root(void (func
)(const char *category
, VALUE
, void *), void *data
);
127 int rb_objspace_markable_object_p(VALUE obj
);
128 int rb_objspace_internal_object_p(VALUE obj
);
129 int rb_objspace_marked_object_p(VALUE obj
);
131 void rb_objspace_each_objects(
132 int (*callback
)(void *start
, void *end
, size_t stride
, void *data
),
135 void rb_objspace_each_objects_without_setup(
136 int (*callback
)(void *, void *, size_t, void *),
139 RUBY_SYMBOL_EXPORT_END
141 #endif /* RUBY_GC_H */