Ruby  3.3.0dev (2023-02-28 revision 2d6097a0f588527a6b23679fc1503c361c068200)
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 
65 #ifndef RGENGC_WB_PROTECTED_ARRAY
66 # define RGENGC_WB_PROTECTED_ARRAY 1
67 #endif
68 
76 #ifndef RGENGC_WB_PROTECTED_HASH
77 # define RGENGC_WB_PROTECTED_HASH 1
78 #endif
79 
87 #ifndef RGENGC_WB_PROTECTED_STRUCT
88 # define RGENGC_WB_PROTECTED_STRUCT 1
89 #endif
90 
98 #ifndef RGENGC_WB_PROTECTED_STRING
99 # define RGENGC_WB_PROTECTED_STRING 1
100 #endif
101 
109 #ifndef RGENGC_WB_PROTECTED_OBJECT
110 # define RGENGC_WB_PROTECTED_OBJECT 1
111 #endif
112 
120 #ifndef RGENGC_WB_PROTECTED_REGEXP
121 # define RGENGC_WB_PROTECTED_REGEXP 1
122 #endif
123 
131 #ifndef RGENGC_WB_PROTECTED_MATCH
132 # define RGENGC_WB_PROTECTED_MATCH 1
133 #endif
134 
142 #ifndef RGENGC_WB_PROTECTED_CLASS
143 # define RGENGC_WB_PROTECTED_CLASS 1
144 #endif
145 
153 #ifndef RGENGC_WB_PROTECTED_FLOAT
154 # define RGENGC_WB_PROTECTED_FLOAT 1
155 #endif
156 
164 #ifndef RGENGC_WB_PROTECTED_COMPLEX
165 # define RGENGC_WB_PROTECTED_COMPLEX 1
166 #endif
167 
175 #ifndef RGENGC_WB_PROTECTED_RATIONAL
176 # define RGENGC_WB_PROTECTED_RATIONAL 1
177 #endif
178 
186 #ifndef RGENGC_WB_PROTECTED_BIGNUM
187 # define RGENGC_WB_PROTECTED_BIGNUM 1
188 #endif
189 
201 #ifndef RGENGC_WB_PROTECTED_NODE_CREF
202 # define RGENGC_WB_PROTECTED_NODE_CREF 1
203 #endif
204 
223 #define RB_OBJ_WRITE(old, slot, young) \
224  RBIMPL_CAST(rb_obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young), __FILE__, __LINE__))
225 
235 #define RB_OBJ_WRITTEN(old, oldv, young) \
236  RBIMPL_CAST(rb_obj_written((VALUE)(old), (VALUE)(oldv), (VALUE)(young), __FILE__, __LINE__))
239 #define OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
240 #define OBJ_PROMOTED RB_OBJ_PROMOTED
241 #define OBJ_WB_UNPROTECT RB_OBJ_WB_UNPROTECT
250 #define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__)
251 
263 #define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \
264  (RGENGC_WB_PROTECTED_##type ? OBJ_WB_UNPROTECT(obj) : obj)
265 
272 #define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging
273 
275 #define RB_OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
276 #define RB_OBJ_PROMOTED RB_OBJ_PROMOTED
287 void rb_gc_writebarrier(VALUE old, VALUE young);
288 
296 
298 
309 static inline bool
311 {
313  return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED);
314 }
315 
329 static inline bool
331 {
332  if (! RB_FL_ABLE(obj)) {
333  return false;
334  }
335  else {
336  return RB_OBJ_PROMOTED_RAW(obj);
337  }
338 }
339 
349 static inline VALUE
351  VALUE x,
353  const char *filename,
355  int line)
356 {
358  return x;
359 }
360 
361 #define RGENGC_LOGGING_OBJ_WRITTEN rb_gc_obj_written_logging
362 
376 static inline VALUE
377 rb_obj_written(
378  VALUE a,
380  VALUE oldv,
381  VALUE b,
383  const char *filename,
385  int line)
386 {
387  if (!RB_SPECIAL_CONST_P(b)) {
388  rb_gc_writebarrier(a, b);
389  }
390 
391  return a;
392 }
393 
407 static inline VALUE
408 rb_obj_write(
409  VALUE a, VALUE *slot, VALUE b,
411  const char *filename,
413  int line)
414 {
415 #ifdef RGENGC_LOGGING_WRITE
416  RGENGC_LOGGING_WRITE(a, slot, b, filename, line);
417 #endif
418 
419  *slot = b;
420 
421  rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line);
422  return a;
423 }
424 
425 #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:476
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_ANY().
Definition: fl_type.h:550
@ 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:350
void rb_gc_writebarrier(VALUE old, VALUE young)
This is the implementation of RB_OBJ_WRITE().
Definition: gc.c:9092
void rb_gc_writebarrier_unprotect(VALUE obj)
This is the implementation of RB_OBJ_WB_UNPROTECT().
Definition: gc.c:9130
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:330
static bool RB_OBJ_PROMOTED_RAW(VALUE obj)
This is the implementation of RB_OBJ_PROMOTED().
Definition: rgengc.h:310
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