Ruby: include/ruby/internal/rgengc.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

rgengc.h
Go to the documentation of this file.
1#ifndef RBIMPL_RGENGC_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RGENGC_H
27#include "ruby/internal/attr/artificial.h"
28#include "ruby/internal/attr/maybe_unused.h"
29#include "ruby/internal/attr/pure.h"
30#include "ruby/internal/dllexport.h"
31#include "ruby/internal/special_consts.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
276 RBIMPL_SYMBOL_EXPORT_BEGIN()
284void rb_gc_writebarrier(VALUE old, VALUE young);
285
292void rb_gc_writebarrier_unprotect(VALUE obj);
293
294#if USE_RGENGC_LOGGING_WB_UNPROTECT
307void rb_gc_unprotect_logging(void *objptr, const char *filename, int line);
308#endif
309
310 RBIMPL_SYMBOL_EXPORT_END()
311
312 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
313 RBIMPL_ATTR_ARTIFICIAL()
322static inline bool
323RB_OBJ_PROMOTED_RAW(VALUE obj)
324{
325 RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
326 return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED);
327}
328
329 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
330 RBIMPL_ATTR_ARTIFICIAL()
342static inline bool
343RB_OBJ_PROMOTED(VALUE obj)
344{
345 if (! RB_FL_ABLE(obj)) {
346 return false;
347 }
348 else {
349 return RB_OBJ_PROMOTED_RAW(obj);
350 }
351}
352
362static inline VALUE
363rb_obj_wb_unprotect(
364 VALUE x,
365 RBIMPL_ATTR_MAYBE_UNUSED()
366 const char *filename,
367 RBIMPL_ATTR_MAYBE_UNUSED()
368 int line)
369{
370#if USE_RGENGC_LOGGING_WB_UNPROTECT
371 RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line);
372#endif
373 rb_gc_writebarrier_unprotect(x);
374 return x;
375}
376
390static inline VALUE
391rb_obj_written(
392 VALUE a,
393 RBIMPL_ATTR_MAYBE_UNUSED()
394 VALUE oldv,
395 VALUE b,
396 RBIMPL_ATTR_MAYBE_UNUSED()
397 const char *filename,
398 RBIMPL_ATTR_MAYBE_UNUSED()
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
425static inline VALUE
426rb_obj_write(
427 VALUE a, VALUE *slot, VALUE b,
428 RBIMPL_ATTR_MAYBE_UNUSED()
429 const char *filename,
430 RBIMPL_ATTR_MAYBE_UNUSED()
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 */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition assert.h:229
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
RB_FL_ABLE
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition fl_type.h:476
RB_FL_ANY_RAW
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
@ RUBY_FL_PROMOTED
This flag has something to do with our garbage collector.
Definition fl_type.h:257
maybe_unused.h
Defines RBIMPL_ATTR_MAYBE_UNUSED.
RBIMPL_ATTR_MAYBE_UNUSED
#define RBIMPL_ATTR_MAYBE_UNUSED()
Wraps (or simulates) [[maybe_unused]]
Definition maybe_unused.h:35
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
rb_obj_wb_unprotect
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
rb_gc_writebarrier
void rb_gc_writebarrier(VALUE old, VALUE young)
This is the implementation of RB_OBJ_WRITE().
Definition gc.c:9025
rb_gc_writebarrier_unprotect
void rb_gc_writebarrier_unprotect(VALUE obj)
This is the implementation of RB_OBJ_WB_UNPROTECT().
Definition gc.c:9063
RGENGC_LOGGING_WB_UNPROTECT
#define RGENGC_LOGGING_WB_UNPROTECT
This is an implementation detail of rb_obj_wb_unprotect().
Definition rgengc.h:269
RB_OBJ_PROMOTED
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
RB_OBJ_PROMOTED_RAW
static bool RB_OBJ_PROMOTED_RAW(VALUE obj)
This is the implementation of RB_OBJ_PROMOTED().
Definition rgengc.h:323
special_consts.h
Defines enum ruby_special_consts.
RB_SPECIAL_CONST_P
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
Definition special_consts.h:327
RUBY_Qundef
@ RUBY_Qundef
Represents so-called undef.
Definition special_consts.h:91
stdbool.h
C99 shim for <stdbool.h>
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40