Ruby  3.1.4p223 (2023-03-30 revision HEAD)
rgengc.h
Go to the documentation of this file.
1 #ifndef RBIMPL_RGENGC_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_RGENGC_H
32 #include "ruby/internal/stdbool.h"
33 #include "ruby/internal/value.h"
34 #include "ruby/assert.h"
35 
43 #undef USE_RGENGC
44 #define USE_RGENGC 1
45 
54 #ifndef USE_RINCGC
55 # define USE_RINCGC 1
56 #endif
57 
62 #ifndef USE_RGENGC_LOGGING_WB_UNPROTECT
63 # define USE_RGENGC_LOGGING_WB_UNPROTECT 0
64 #endif
65 
73 #ifndef RGENGC_WB_PROTECTED_ARRAY
74 # define RGENGC_WB_PROTECTED_ARRAY 1
75 #endif
76 
84 #ifndef RGENGC_WB_PROTECTED_HASH
85 # define RGENGC_WB_PROTECTED_HASH 1
86 #endif
87 
95 #ifndef RGENGC_WB_PROTECTED_STRUCT
96 # define RGENGC_WB_PROTECTED_STRUCT 1
97 #endif
98 
106 #ifndef RGENGC_WB_PROTECTED_STRING
107 # define RGENGC_WB_PROTECTED_STRING 1
108 #endif
109 
117 #ifndef RGENGC_WB_PROTECTED_OBJECT
118 # define RGENGC_WB_PROTECTED_OBJECT 1
119 #endif
120 
128 #ifndef RGENGC_WB_PROTECTED_REGEXP
129 # define RGENGC_WB_PROTECTED_REGEXP 1
130 #endif
131 
139 #ifndef RGENGC_WB_PROTECTED_CLASS
140 # define RGENGC_WB_PROTECTED_CLASS 1
141 #endif
142 
150 #ifndef RGENGC_WB_PROTECTED_FLOAT
151 # define RGENGC_WB_PROTECTED_FLOAT 1
152 #endif
153 
161 #ifndef RGENGC_WB_PROTECTED_COMPLEX
162 # define RGENGC_WB_PROTECTED_COMPLEX 1
163 #endif
164 
172 #ifndef RGENGC_WB_PROTECTED_RATIONAL
173 # define RGENGC_WB_PROTECTED_RATIONAL 1
174 #endif
175 
183 #ifndef RGENGC_WB_PROTECTED_BIGNUM
184 # define RGENGC_WB_PROTECTED_BIGNUM 1
185 #endif
186 
198 #ifndef RGENGC_WB_PROTECTED_NODE_CREF
199 # define RGENGC_WB_PROTECTED_NODE_CREF 1
200 #endif
201 
220 #define RB_OBJ_WRITE(old, slot, young) \
221  RBIMPL_CAST(rb_obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young), __FILE__, __LINE__))
222 
232 #define RB_OBJ_WRITTEN(old, oldv, young) \
233  RBIMPL_CAST(rb_obj_written((VALUE)(old), (VALUE)(oldv), (VALUE)(young), __FILE__, __LINE__))
236 #define OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
237 #define OBJ_PROMOTED RB_OBJ_PROMOTED
238 #define OBJ_WB_UNPROTECT RB_OBJ_WB_UNPROTECT
247 #define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__)
248 
260 #define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \
261  (RGENGC_WB_PROTECTED_##type ? OBJ_WB_UNPROTECT(obj) : obj)
262 
269 #define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging
270 
272 #define RB_OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
273 #define RB_OBJ_PROMOTED RB_OBJ_PROMOTED
284 void rb_gc_writebarrier(VALUE old, VALUE young);
285 
293 
294 #if USE_RGENGC_LOGGING_WB_UNPROTECT
307 void rb_gc_unprotect_logging(void *objptr, const char *filename, int line);
308 #endif
309 
311 
322 static inline bool
324 {
326  return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED);
327 }
328 
342 static inline bool
344 {
345  if (! RB_FL_ABLE(obj)) {
346  return false;
347  }
348  else {
349  return RB_OBJ_PROMOTED_RAW(obj);
350  }
351 }
352 
362 static inline VALUE
364  VALUE x,
366  const char *filename,
368  int line)
369 {
370 #if USE_RGENGC_LOGGING_WB_UNPROTECT
371  RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line);
372 #endif
374  return x;
375 }
376 
390 static inline VALUE
391 rb_obj_written(
392  VALUE a,
394  VALUE oldv,
395  VALUE b,
397  const char *filename,
399  int line)
400 {
401 #if USE_RGENGC_LOGGING_WB_UNPROTECT
402  RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
403 #endif
404 
405  if (!RB_SPECIAL_CONST_P(b)) {
406  rb_gc_writebarrier(a, b);
407  }
408 
409  return a;
410 }
411 
425 static inline VALUE
426 rb_obj_write(
427  VALUE a, VALUE *slot, VALUE b,
429  const char *filename,
431  int line)
432 {
433 #ifdef RGENGC_LOGGING_WRITE
434  RGENGC_LOGGING_WRITE(a, slot, b, filename, line);
435 #endif
436 
437  *slot = b;
438 
439  rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line);
440  return a;
441 }
442 
443 #endif /* RBIMPL_RGENGC_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:106
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:97
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition: fl_type.h:482
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_ANY().
Definition: fl_type.h:556
@ RUBY_FL_PROMOTED
This flag has something to do with our garbage collector.
Definition: fl_type.h:257
Defines RBIMPL_ATTR_MAYBE_UNUSED.
#define RBIMPL_ATTR_MAYBE_UNUSED()
Wraps (or simulates) [[maybe_unused]]
Definition: maybe_unused.h:33
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition: pure.h:38
static VALUE rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
This is the implementation of RB_OBJ_WB_UNPROTECT().
Definition: rgengc.h:363
void rb_gc_writebarrier(VALUE old, VALUE young)
This is the implementation of RB_OBJ_WRITE().
Definition: gc.c:8464
void rb_gc_writebarrier_unprotect(VALUE obj)
This is the implementation of RB_OBJ_WB_UNPROTECT().
Definition: gc.c:8500
#define RGENGC_LOGGING_WB_UNPROTECT
This is an implementation detail of rb_obj_wb_unprotect().
Definition: rgengc.h:269
static bool RB_OBJ_PROMOTED(VALUE obj)
Tests if the object is "promoted" – that is, whether the object experienced one or more GC marks.
Definition: rgengc.h:343
static bool RB_OBJ_PROMOTED_RAW(VALUE obj)
This is the implementation of RB_OBJ_PROMOTED().
Definition: rgengc.h:323
Defines enum ruby_special_consts.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
@ RUBY_Qundef
Represents so-called undef.
C99 shim for <stdbool.h>
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40