Ruby 4.0.7p0 (2026-09-15 revision 229531a6cfbf07e3caef30dbac24a2a3f3fed482)
mmtk.c
1#include <pthread.h>
2#include <stdbool.h>
3
4#include "ruby/assert.h"
5#include "ruby/atomic.h"
6#include "ruby/debug.h"
7
8#include "gc/gc.h"
9#include "gc/gc_impl.h"
10#include "gc/mmtk/mmtk.h"
11
12#include "ccan/list/list.h"
13#include "darray.h"
14
15#ifdef __APPLE__
16#include <sys/sysctl.h>
17#endif
18
19struct objspace {
20 bool measure_gc_time;
21 bool gc_stress;
22
23 size_t gc_count;
24 size_t total_gc_time;
25 size_t total_allocated_objects;
26
27 st_table *finalizer_table;
28 struct MMTk_final_job *finalizer_jobs;
29 rb_postponed_job_handle_t finalizer_postponed_job;
30
31 struct ccan_list_head ractor_caches;
32 unsigned long live_ractor_cache_count;
33
34 pthread_mutex_t mutex;
35 rb_atomic_t mutator_blocking_count;
36 bool world_stopped;
37 pthread_cond_t cond_world_stopped;
38 pthread_cond_t cond_world_started;
39 size_t start_the_world_count;
40
41 struct rb_gc_vm_context vm_context;
42
43 unsigned int fork_hook_vm_lock_lev;
44};
45
47 struct ccan_list_node list_node;
48
49 MMTk_Mutator *mutator;
50 bool gc_mutator_p;
51
52 MMTk_BumpPointer *bump_pointer;
53};
54
56 struct MMTk_final_job *next;
57 enum {
58 MMTK_FINAL_JOB_DFREE,
59 MMTK_FINAL_JOB_FINALIZE,
60 } kind;
61 union {
62 struct {
63 void (*func)(void *);
64 void *data;
65 } dfree;
66 struct {
67 /* HACK: we store the object ID on the 0th element of this array. */
68 VALUE finalizer_array;
69 } finalize;
70 } as;
71};
72
73#ifdef RB_THREAD_LOCAL_SPECIFIER
74RB_THREAD_LOCAL_SPECIFIER struct MMTk_GCThreadTLS *rb_mmtk_gc_thread_tls;
75#else
76# error We currently need language-supported TLS
77#endif
78
79#include <pthread.h>
80
81static void
82rb_mmtk_init_gc_worker_thread(MMTk_VMWorkerThread gc_thread_tls)
83{
84 rb_mmtk_gc_thread_tls = gc_thread_tls;
85}
86
87static bool
88rb_mmtk_is_mutator(void)
89{
90 return ruby_native_thread_p();
91}
92
93static void
94rb_mmtk_stop_the_world(void)
95{
96 struct objspace *objspace = rb_gc_get_objspace();
97
98 int err;
99 if ((err = pthread_mutex_lock(&objspace->mutex)) != 0) {
100 rb_bug("ERROR: cannot lock objspace->mutex: %s", strerror(err));
101 }
102
103 while (!objspace->world_stopped) {
104 pthread_cond_wait(&objspace->cond_world_stopped, &objspace->mutex);
105 }
106
107 if ((err = pthread_mutex_unlock(&objspace->mutex)) != 0) {
108 rb_bug("ERROR: cannot release objspace->mutex: %s", strerror(err));
109 }
110}
111
112static void
113rb_mmtk_resume_mutators(void)
114{
115 struct objspace *objspace = rb_gc_get_objspace();
116
117 int err;
118 if ((err = pthread_mutex_lock(&objspace->mutex)) != 0) {
119 rb_bug("ERROR: cannot lock objspace->mutex: %s", strerror(err));
120 }
121
122 objspace->world_stopped = false;
123 objspace->gc_count++;
124 pthread_cond_broadcast(&objspace->cond_world_started);
125
126 if ((err = pthread_mutex_unlock(&objspace->mutex)) != 0) {
127 rb_bug("ERROR: cannot release objspace->mutex: %s", strerror(err));
128 }
129}
130
131static void
132rb_mmtk_block_for_gc(MMTk_VMMutatorThread mutator)
133{
134 struct objspace *objspace = rb_gc_get_objspace();
135
136 size_t starting_gc_count = objspace->gc_count;
137 RUBY_ATOMIC_INC(objspace->mutator_blocking_count);
138 int lock_lev = RB_GC_VM_LOCK();
139 RUBY_ATOMIC_DEC(objspace->mutator_blocking_count);
140 int err;
141 if ((err = pthread_mutex_lock(&objspace->mutex)) != 0) {
142 rb_bug("ERROR: cannot lock objspace->mutex: %s", strerror(err));
143 }
144
145 if (objspace->gc_count == starting_gc_count) {
146 rb_gc_event_hook(0, RUBY_INTERNAL_EVENT_GC_START);
147
148 rb_gc_initialize_vm_context(&objspace->vm_context);
149
150 mutator->gc_mutator_p = true;
151
152 struct timespec gc_start_time;
153 if (objspace->measure_gc_time) {
154 clock_gettime(CLOCK_MONOTONIC, &gc_start_time);
155 }
156
157 rb_gc_save_machine_context();
158
159 rb_gc_vm_barrier();
160
161 objspace->world_stopped = true;
162
163 pthread_cond_broadcast(&objspace->cond_world_stopped);
164
165 // Wait for GC end
166 while (objspace->world_stopped) {
167 pthread_cond_wait(&objspace->cond_world_started, &objspace->mutex);
168 }
169
170 if (objspace->measure_gc_time) {
171 struct timespec gc_end_time;
172 clock_gettime(CLOCK_MONOTONIC, &gc_end_time);
173
174 objspace->total_gc_time +=
175 (gc_end_time.tv_sec - gc_start_time.tv_sec) * (1000 * 1000 * 1000) +
176 (gc_end_time.tv_nsec - gc_start_time.tv_nsec);
177 }
178 }
179
180 if ((err = pthread_mutex_unlock(&objspace->mutex)) != 0) {
181 rb_bug("ERROR: cannot release objspace->mutex: %s", strerror(err));
182 }
183 RB_GC_VM_UNLOCK(lock_lev);
184}
185
186static size_t
187rb_mmtk_number_of_mutators(void)
188{
189 struct objspace *objspace = rb_gc_get_objspace();
190 return objspace->live_ractor_cache_count;
191}
192
193static void
194rb_mmtk_get_mutators(void (*visit_mutator)(MMTk_Mutator *mutator, void *data), void *data)
195{
196 struct objspace *objspace = rb_gc_get_objspace();
197 struct MMTk_ractor_cache *ractor_cache;
198
199 ccan_list_for_each(&objspace->ractor_caches, ractor_cache, list_node) {
200 visit_mutator(ractor_cache->mutator, data);
201 }
202}
203
204static void
205rb_mmtk_scan_gc_roots(void)
206{
207 struct objspace *objspace = rb_gc_get_objspace();
208
209 // FIXME: Make `rb_gc_mark_roots` aware that the current thread may not have EC.
210 // See: https://github.com/ruby/mmtk/issues/22
211 rb_gc_worker_thread_set_vm_context(&objspace->vm_context);
212 rb_gc_mark_roots(objspace, NULL);
213 rb_gc_worker_thread_unset_vm_context(&objspace->vm_context);
214}
215
216static int
217pin_value(st_data_t key, st_data_t value, st_data_t data)
218{
219 rb_gc_impl_mark_and_pin((void *)data, (VALUE)value);
220
221 return ST_CONTINUE;
222}
223
224static void
225rb_mmtk_scan_objspace(void)
226{
227 struct objspace *objspace = rb_gc_get_objspace();
228
229 if (objspace->finalizer_table != NULL) {
230 st_foreach(objspace->finalizer_table, pin_value, (st_data_t)objspace);
231 }
232
233 struct MMTk_final_job *job = objspace->finalizer_jobs;
234 while (job != NULL) {
235 switch (job->kind) {
236 case MMTK_FINAL_JOB_DFREE:
237 break;
238 case MMTK_FINAL_JOB_FINALIZE:
239 rb_gc_impl_mark(objspace, job->as.finalize.finalizer_array);
240 break;
241 default:
242 rb_bug("rb_mmtk_scan_objspace: unknown final job type %d", job->kind);
243 }
244
245 job = job->next;
246 }
247}
248
249static void
250rb_mmtk_scan_object_ruby_style(MMTk_ObjectReference object)
251{
252 rb_gc_mark_children(rb_gc_get_objspace(), (VALUE)object);
253}
254
255static void
256rb_mmtk_call_gc_mark_children(MMTk_ObjectReference object)
257{
258 rb_gc_mark_children(rb_gc_get_objspace(), (VALUE)object);
259}
260
261static void
262rb_mmtk_call_obj_free(MMTk_ObjectReference object)
263{
264 VALUE obj = (VALUE)object;
265 struct objspace *objspace = rb_gc_get_objspace();
266
267 if (RB_UNLIKELY(rb_gc_event_hook_required_p(RUBY_INTERNAL_EVENT_FREEOBJ))) {
268 rb_gc_worker_thread_set_vm_context(&objspace->vm_context);
269 rb_gc_event_hook(obj, RUBY_INTERNAL_EVENT_FREEOBJ);
270 rb_gc_worker_thread_unset_vm_context(&objspace->vm_context);
271 }
272
273 rb_gc_obj_free(objspace, obj);
274}
275
276static size_t
277rb_mmtk_vm_live_bytes(void)
278{
279 return 0;
280}
281
282static void
283make_final_job(struct objspace *objspace, VALUE obj, VALUE table)
284{
285 RUBY_ASSERT(RB_FL_TEST(obj, RUBY_FL_FINALIZE));
286 RUBY_ASSERT(mmtk_is_reachable((MMTk_ObjectReference)table));
287 RUBY_ASSERT(RB_BUILTIN_TYPE(table) == T_ARRAY);
288
289 RB_FL_UNSET(obj, RUBY_FL_FINALIZE);
290
291 struct MMTk_final_job *job = xmalloc(sizeof(struct MMTk_final_job));
292 job->next = objspace->finalizer_jobs;
293 job->kind = MMTK_FINAL_JOB_FINALIZE;
294 job->as.finalize.finalizer_array = table;
295
296 objspace->finalizer_jobs = job;
297}
298
299static int
300rb_mmtk_update_finalizer_table_i(st_data_t key, st_data_t value, st_data_t data)
301{
302 RUBY_ASSERT(RB_FL_TEST(key, RUBY_FL_FINALIZE));
303 RUBY_ASSERT(mmtk_is_reachable((MMTk_ObjectReference)value));
304 RUBY_ASSERT(RB_BUILTIN_TYPE(value) == T_ARRAY);
305
306 struct objspace *objspace = (struct objspace *)data;
307
308 if (!mmtk_is_reachable((MMTk_ObjectReference)key)) {
309 make_final_job(objspace, (VALUE)key, (VALUE)value);
310
311 rb_postponed_job_trigger(objspace->finalizer_postponed_job);
312
313 return ST_DELETE;
314 }
315
316 return ST_CONTINUE;
317}
318
319static void
320rb_mmtk_update_finalizer_table(void)
321{
322 struct objspace *objspace = rb_gc_get_objspace();
323
324 // TODO: replace with st_foreach_with_replace when GC is moving
325 st_foreach(objspace->finalizer_table, rb_mmtk_update_finalizer_table_i, (st_data_t)objspace);
326}
327
328static int
329rb_mmtk_update_table_i(VALUE val, void *data)
330{
331 if (!mmtk_is_reachable((MMTk_ObjectReference)val)) {
332 return ST_DELETE;
333 }
334
335 return ST_CONTINUE;
336}
337
338static int
339rb_mmtk_global_tables_count(void)
340{
341 return RB_GC_VM_WEAK_TABLE_COUNT;
342}
343
344static void
345rb_mmtk_update_global_tables(int table)
346{
347 RUBY_ASSERT(table < RB_GC_VM_WEAK_TABLE_COUNT);
348
349 rb_gc_vm_weak_table_foreach(rb_mmtk_update_table_i, NULL, NULL, true, (enum rb_gc_vm_weak_tables)table);
350}
351
352static bool
353rb_mmtk_special_const_p(MMTk_ObjectReference object)
354{
355 VALUE obj = (VALUE)object;
356
357 return RB_SPECIAL_CONST_P(obj);
358}
359
360static void
361rb_mmtk_mutator_thread_panic_handler(void)
362{
363 rb_bug("Ruby mutator thread panicked");
364}
365
366// Bootup
367MMTk_RubyUpcalls ruby_upcalls = {
368 rb_mmtk_init_gc_worker_thread,
369 rb_mmtk_is_mutator,
370 rb_mmtk_stop_the_world,
371 rb_mmtk_resume_mutators,
372 rb_mmtk_block_for_gc,
373 rb_mmtk_number_of_mutators,
374 rb_mmtk_get_mutators,
375 rb_mmtk_scan_gc_roots,
376 rb_mmtk_scan_objspace,
377 rb_mmtk_scan_object_ruby_style,
378 rb_mmtk_call_gc_mark_children,
379 rb_mmtk_call_obj_free,
380 rb_mmtk_vm_live_bytes,
381 rb_mmtk_update_global_tables,
382 rb_mmtk_global_tables_count,
383 rb_mmtk_update_finalizer_table,
384 rb_mmtk_special_const_p,
385 rb_mmtk_mutator_thread_panic_handler,
386};
387
388// Use max 80% of the available memory by default for MMTk
389#define RB_MMTK_HEAP_LIMIT_PERC 80
390#define RB_MMTK_DEFAULT_HEAP_MIN (1024 * 1024)
391#define RB_MMTK_DEFAULT_HEAP_MAX (rb_mmtk_system_physical_memory() / 100 * RB_MMTK_HEAP_LIMIT_PERC)
392
393enum mmtk_heap_mode {
394 RB_MMTK_DYNAMIC_HEAP,
395 RB_MMTK_FIXED_HEAP
396};
397
398MMTk_Builder *
399rb_mmtk_builder_init(void)
400{
401 MMTk_Builder *builder = mmtk_builder_default();
402 return builder;
403}
404
405void *
406rb_gc_impl_objspace_alloc(void)
407{
408 MMTk_Builder *builder = rb_mmtk_builder_init();
409 mmtk_init_binding(builder, NULL, &ruby_upcalls, (MMTk_ObjectReference)Qundef);
410
411 return calloc(1, sizeof(struct objspace));
412}
413
414static void gc_run_finalizers(void *data);
415
416void
417rb_gc_impl_objspace_init(void *objspace_ptr)
418{
419 struct objspace *objspace = objspace_ptr;
420
421 objspace->measure_gc_time = true;
422
423 objspace->finalizer_table = st_init_numtable();
424 objspace->finalizer_postponed_job = rb_postponed_job_preregister(0, gc_run_finalizers, objspace);
425
426 ccan_list_head_init(&objspace->ractor_caches);
427
428 objspace->mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
429 objspace->cond_world_stopped = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
430 objspace->cond_world_started = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
431}
432
433void
434rb_gc_impl_objspace_free(void *objspace_ptr)
435{
436 free(objspace_ptr);
437}
438
439void *
440rb_gc_impl_ractor_cache_alloc(void *objspace_ptr, void *ractor)
441{
442 struct objspace *objspace = objspace_ptr;
443 if (objspace->live_ractor_cache_count == 0) {
444 mmtk_initialize_collection(ractor);
445 }
446 objspace->live_ractor_cache_count++;
447
448 struct MMTk_ractor_cache *cache = malloc(sizeof(struct MMTk_ractor_cache));
449 ccan_list_add(&objspace->ractor_caches, &cache->list_node);
450
451 cache->mutator = mmtk_bind_mutator(cache);
452 cache->bump_pointer = mmtk_get_bump_pointer_allocator(cache->mutator);
453
454 return cache;
455}
456
457void
458rb_gc_impl_ractor_cache_free(void *objspace_ptr, void *cache_ptr)
459{
460 struct objspace *objspace = objspace_ptr;
461 struct MMTk_ractor_cache *cache = cache_ptr;
462
463 ccan_list_del(&cache->list_node);
464
465 RUBY_ASSERT(objspace->live_ractor_cache_count > 1);
466 objspace->live_ractor_cache_count--;
467
468 mmtk_destroy_mutator(cache->mutator);
469}
470
471void rb_gc_impl_set_params(void *objspace_ptr) { }
472
473static VALUE gc_verify_internal_consistency(VALUE self) { return Qnil; }
474
475#define MMTK_HEAP_COUNT 6
476#define MMTK_MAX_OBJ_SIZE 640
477
478static size_t heap_sizes[MMTK_HEAP_COUNT + 1] = {
479 32, 40, 80, 160, 320, MMTK_MAX_OBJ_SIZE, 0
480};
481
482void
483rb_gc_impl_init(void)
484{
485 VALUE gc_constants = rb_hash_new();
486 rb_hash_aset(gc_constants, ID2SYM(rb_intern("BASE_SLOT_SIZE")), SIZET2NUM(sizeof(VALUE) * 5));
487 rb_hash_aset(gc_constants, ID2SYM(rb_intern("RBASIC_SIZE")), SIZET2NUM(sizeof(struct RBasic)));
488 rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVALUE_OVERHEAD")), INT2NUM(0));
489 rb_hash_aset(gc_constants, ID2SYM(rb_intern("RVARGC_MAX_ALLOCATE_SIZE")), LONG2FIX(MMTK_MAX_OBJ_SIZE));
490 // Pretend we have 5 size pools
491 rb_hash_aset(gc_constants, ID2SYM(rb_intern("SIZE_POOL_COUNT")), LONG2FIX(5));
492 OBJ_FREEZE(gc_constants);
493 rb_define_const(rb_mGC, "INTERNAL_CONSTANTS", gc_constants);
494
495 // no-ops for compatibility
496 rb_define_singleton_method(rb_mGC, "verify_internal_consistency", gc_verify_internal_consistency, 0);
497
501 rb_define_singleton_method(rb_mGC, "latest_compact_info", rb_f_notimplement, 0);
502 rb_define_singleton_method(rb_mGC, "verify_compaction_references", rb_f_notimplement, -1);
503}
504
505size_t *
506rb_gc_impl_heap_sizes(void *objspace_ptr)
507{
508 return heap_sizes;
509}
510
511int
512rb_mmtk_obj_free_iter_wrapper(VALUE obj, void *data)
513{
514 struct objspace *objspace = data;
515
516 if (!RB_TYPE_P(obj, T_NONE)) {
517 rb_gc_obj_free_vm_weak_references(obj);
518 rb_gc_obj_free(objspace, obj);
519 }
520
521 return 0;
522}
523
524// Shutdown
525static void each_object(struct objspace *objspace, int (*func)(VALUE, void *), void *data);
526
527void
528rb_gc_impl_shutdown_free_objects(void *objspace_ptr)
529{
530 mmtk_set_gc_enabled(false);
531 each_object(objspace_ptr, rb_mmtk_obj_free_iter_wrapper, objspace_ptr);
532 mmtk_set_gc_enabled(true);
533}
534
535// GC
536void
537rb_gc_impl_start(void *objspace_ptr, bool full_mark, bool immediate_mark, bool immediate_sweep, bool compact)
538{
539 mmtk_handle_user_collection_request(rb_gc_get_ractor_newobj_cache(), true, full_mark);
540}
541
542bool
543rb_gc_impl_during_gc_p(void *objspace_ptr)
544{
545 // TODO
546 return false;
547}
548
549static void
550rb_gc_impl_prepare_heap_i(MMTk_ObjectReference obj, void *d)
551{
552 rb_gc_prepare_heap_process_object((VALUE)obj);
553}
554
555void
556rb_gc_impl_prepare_heap(void *objspace_ptr)
557{
558 mmtk_enumerate_objects(rb_gc_impl_prepare_heap_i, NULL);
559}
560
561void
562rb_gc_impl_gc_enable(void *objspace_ptr)
563{
564 mmtk_set_gc_enabled(true);
565}
566
567void
568rb_gc_impl_gc_disable(void *objspace_ptr, bool finish_current_gc)
569{
570 mmtk_set_gc_enabled(false);
571}
572
573bool
574rb_gc_impl_gc_enabled_p(void *objspace_ptr)
575{
576 return mmtk_gc_enabled_p();
577}
578
579void
580rb_gc_impl_stress_set(void *objspace_ptr, VALUE flag)
581{
582 struct objspace *objspace = objspace_ptr;
583
584 objspace->gc_stress = RTEST(flag);
585}
586
587VALUE
588rb_gc_impl_stress_get(void *objspace_ptr)
589{
590 struct objspace *objspace = objspace_ptr;
591
592 return objspace->gc_stress ? Qtrue : Qfalse;
593}
594
595VALUE
596rb_gc_impl_config_get(void *objspace_ptr)
597{
598 VALUE hash = rb_hash_new();
599
600 rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_worker_count")), RB_ULONG2NUM(mmtk_worker_count()));
601 rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_plan")), rb_str_new_cstr((const char *)mmtk_plan()));
602 rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_mode")), rb_str_new_cstr((const char *)mmtk_heap_mode()));
603 size_t heap_min = mmtk_heap_min();
604 if (heap_min > 0) rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_min")), RB_ULONG2NUM(heap_min));
605 rb_hash_aset(hash, ID2SYM(rb_intern_const("mmtk_heap_max")), RB_ULONG2NUM(mmtk_heap_max()));
606
607 return hash;
608}
609
610void
611rb_gc_impl_config_set(void *objspace_ptr, VALUE hash)
612{
613 // TODO
614}
615
616// Object allocation
617
618static VALUE
619rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size)
620{
621 MMTk_BumpPointer *bump_pointer = ractor_cache->bump_pointer;
622 if (bump_pointer == NULL) return 0;
623
624 uintptr_t new_cursor = bump_pointer->cursor + size;
625
626 if (new_cursor > bump_pointer->limit) {
627 return 0;
628 }
629 else {
630 VALUE obj = (VALUE)bump_pointer->cursor;
631 bump_pointer->cursor = new_cursor;
632 return obj;
633 }
634}
635
636VALUE
637rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags, bool wb_protected, size_t alloc_size)
638{
639#define MMTK_ALLOCATION_SEMANTICS_DEFAULT 0
640 struct objspace *objspace = objspace_ptr;
641 struct MMTk_ractor_cache *ractor_cache = cache_ptr;
642
643 if (alloc_size > MMTK_MAX_OBJ_SIZE) rb_bug("too big");
644 for (int i = 0; i < MMTK_HEAP_COUNT; i++) {
645 if (alloc_size == heap_sizes[i]) break;
646 if (alloc_size < heap_sizes[i]) {
647 alloc_size = heap_sizes[i];
648 break;
649 }
650 }
651
652 if (objspace->gc_stress) {
653 mmtk_handle_user_collection_request(ractor_cache, false, false);
654 }
655
656 alloc_size += sizeof(VALUE);
657
658 VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
659 if (!alloc_obj) {
660 alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
661 }
662
663 alloc_obj++;
664 alloc_obj[-1] = alloc_size - sizeof(VALUE);
665 alloc_obj[0] = flags;
666 alloc_obj[1] = klass;
667
668 // TODO: implement fast path for mmtk_post_alloc
669 mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, alloc_size, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
670
671 // TODO: only add when object needs obj_free to be called
672 mmtk_add_obj_free_candidate(alloc_obj);
673
674 objspace->total_allocated_objects++;
675
676 return (VALUE)alloc_obj;
677}
678
679size_t
680rb_gc_impl_obj_slot_size(VALUE obj)
681{
682 return ((VALUE *)obj)[-1];
683}
684
685size_t
686rb_gc_impl_heap_id_for_size(void *objspace_ptr, size_t size)
687{
688 for (int i = 0; i < MMTK_HEAP_COUNT; i++) {
689 if (size == heap_sizes[i]) return i;
690 if (size < heap_sizes[i]) return i;
691 }
692
693 rb_bug("size too big");
694}
695
696bool
697rb_gc_impl_size_allocatable_p(size_t size)
698{
699 return size <= MMTK_MAX_OBJ_SIZE;
700}
701
702// Malloc
703void *
704rb_gc_impl_malloc(void *objspace_ptr, size_t size, bool gc_allowed)
705{
706 // TODO: don't use system malloc
707 return malloc(size);
708}
709
710void *
711rb_gc_impl_calloc(void *objspace_ptr, size_t size, bool gc_allowed)
712{
713 // TODO: don't use system calloc
714 return calloc(1, size);
715}
716
717void *
718rb_gc_impl_realloc(void *objspace_ptr, void *ptr, size_t new_size, size_t old_size, bool gc_allowed)
719{
720 // TODO: don't use system realloc
721 return realloc(ptr, new_size);
722}
723
724void
725rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size)
726{
727 // TODO: don't use system free
728 free(ptr);
729}
730
731void rb_gc_impl_adjust_memory_usage(void *objspace_ptr, ssize_t diff) { }
732
733// Marking
734void
735rb_gc_impl_mark(void *objspace_ptr, VALUE obj)
736{
737 if (RB_SPECIAL_CONST_P(obj)) return;
738
739 rb_mmtk_gc_thread_tls->object_closure.c_function(rb_mmtk_gc_thread_tls->object_closure.rust_closure,
740 rb_mmtk_gc_thread_tls->gc_context,
741 (MMTk_ObjectReference)obj,
742 false);
743}
744
745void
746rb_gc_impl_mark_and_move(void *objspace_ptr, VALUE *ptr)
747{
748 if (RB_SPECIAL_CONST_P(*ptr)) return;
749
750 // TODO: make it movable
751 rb_gc_impl_mark(objspace_ptr, *ptr);
752}
753
754void
755rb_gc_impl_mark_and_pin(void *objspace_ptr, VALUE obj)
756{
757 if (RB_SPECIAL_CONST_P(obj)) return;
758
759 // TODO: also pin
760 rb_gc_impl_mark(objspace_ptr, obj);
761}
762
763void
764rb_gc_impl_mark_maybe(void *objspace_ptr, VALUE obj)
765{
766 if (rb_gc_impl_pointer_to_heap_p(objspace_ptr, (const void *)obj)) {
767 rb_gc_impl_mark_and_pin(objspace_ptr, obj);
768 }
769}
770
771void
772rb_gc_impl_mark_weak(void *objspace_ptr, VALUE *ptr)
773{
774 mmtk_mark_weak((MMTk_ObjectReference *)ptr);
775}
776
777void
778rb_gc_impl_remove_weak(void *objspace_ptr, VALUE parent_obj, VALUE *ptr)
779{
780 mmtk_remove_weak((MMTk_ObjectReference *)ptr);
781}
782
783// Compaction
784bool
785rb_gc_impl_object_moved_p(void *objspace_ptr, VALUE obj)
786{
787 rb_bug("unimplemented");
788}
789
790bool
791rb_gc_impl_pinned_p(void *objspace_ptr, VALUE obj)
792{
793 /* MMTk tracks pinning separately */
794 return false;
795}
796
797VALUE
798rb_gc_impl_location(void *objspace_ptr, VALUE value)
799{
800 rb_bug("unimplemented");
801}
802
803// Write barriers
804void
805rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
806{
807 struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache();
808
809 if (SPECIAL_CONST_P(b)) return;
810
811 mmtk_object_reference_write_post(cache->mutator, (MMTk_ObjectReference)a);
812}
813
814void
815rb_gc_impl_writebarrier_unprotect(void *objspace_ptr, VALUE obj)
816{
817 mmtk_register_wb_unprotected_object((MMTk_ObjectReference)obj);
818}
819
820void
821rb_gc_impl_writebarrier_remember(void *objspace_ptr, VALUE obj)
822{
823 struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache();
824
825 mmtk_object_reference_write_post(cache->mutator, (MMTk_ObjectReference)obj);
826}
827
828// Heap walking
829static void
830each_objects_i(MMTk_ObjectReference obj, void *d)
831{
832 rb_darray(VALUE) *objs = d;
833
834 rb_darray_append(objs, (VALUE)obj);
835}
836
837static void
838each_object(struct objspace *objspace, int (*func)(VALUE, void *), void *data)
839{
840 rb_darray(VALUE) objs;
841 rb_darray_make(&objs, 0);
842
843 mmtk_enumerate_objects(each_objects_i, &objs);
844
845 VALUE *obj_ptr;
846 rb_darray_foreach(objs, i, obj_ptr) {
847 if (!mmtk_is_mmtk_object((MMTk_ObjectReference)*obj_ptr)) continue;
848
849 if (func(*obj_ptr, data) != 0) {
850 break;
851 }
852 }
853
854 rb_darray_free(objs);
855}
856
858 int (*func)(void *, void *, size_t, void *);
859 void *data;
860};
861
862static int
863rb_gc_impl_each_objects_i(VALUE obj, void *d)
864{
865 struct rb_gc_impl_each_objects_data *data = d;
866
867 size_t slot_size = rb_gc_impl_obj_slot_size(obj);
868
869 return data->func((void *)obj, (void *)(obj + slot_size), slot_size, data->data);
870}
871
872void
873rb_gc_impl_each_objects(void *objspace_ptr, int (*func)(void *, void *, size_t, void *), void *data)
874{
875 struct rb_gc_impl_each_objects_data each_objects_data = {
876 .func = func,
877 .data = data
878 };
879
880 each_object(objspace_ptr, rb_gc_impl_each_objects_i, &each_objects_data);
881}
882
884 void (*func)(VALUE, void *);
885 void *data;
886};
887
888static int
889rb_gc_impl_each_object_i(VALUE obj, void *d)
890{
891 struct rb_gc_impl_each_object_data *data = d;
892
893 data->func(obj, data->data);
894
895 return 0;
896}
897
898void
899rb_gc_impl_each_object(void *objspace_ptr, void (*func)(VALUE, void *), void *data)
900{
901 struct rb_gc_impl_each_object_data each_object_data = {
902 .func = func,
903 .data = data
904 };
905
906 each_object(objspace_ptr, rb_gc_impl_each_object_i, &each_object_data);
907}
908
909// Finalizers
910static VALUE
911gc_run_finalizers_get_final(long i, void *data)
912{
913 VALUE table = (VALUE)data;
914
915 return RARRAY_AREF(table, i + 1);
916}
917
918static void
919gc_run_finalizers(void *data)
920{
921 struct objspace *objspace = data;
922
923 rb_gc_set_pending_interrupt();
924
925 while (objspace->finalizer_jobs != NULL) {
926 struct MMTk_final_job *job = objspace->finalizer_jobs;
927 objspace->finalizer_jobs = job->next;
928
929 switch (job->kind) {
930 case MMTK_FINAL_JOB_DFREE:
931 job->as.dfree.func(job->as.dfree.data);
932 break;
933 case MMTK_FINAL_JOB_FINALIZE: {
934 VALUE finalizer_array = job->as.finalize.finalizer_array;
935
936 rb_gc_run_obj_finalizer(
937 RARRAY_AREF(finalizer_array, 0),
938 RARRAY_LEN(finalizer_array) - 1,
939 gc_run_finalizers_get_final,
940 (void *)finalizer_array
941 );
942
943 RB_GC_GUARD(finalizer_array);
944 break;
945 }
946 }
947
948 xfree(job);
949 }
950
951 rb_gc_unset_pending_interrupt();
952}
953
954void
955rb_gc_impl_make_zombie(void *objspace_ptr, VALUE obj, void (*dfree)(void *), void *data)
956{
957 if (dfree == NULL) return;
958
959 struct objspace *objspace = objspace_ptr;
960
961 struct MMTk_final_job *job = xmalloc(sizeof(struct MMTk_final_job));
962 job->kind = MMTK_FINAL_JOB_DFREE;
963 job->as.dfree.func = dfree;
964 job->as.dfree.data = data;
965
966 struct MMTk_final_job *prev;
967 do {
968 job->next = objspace->finalizer_jobs;
969 prev = RUBY_ATOMIC_PTR_CAS(objspace->finalizer_jobs, job->next, job);
970 } while (prev != job->next);
971
972 if (!ruby_free_at_exit_p()) {
973 rb_postponed_job_trigger(objspace->finalizer_postponed_job);
974 }
975}
976
977VALUE
978rb_gc_impl_define_finalizer(void *objspace_ptr, VALUE obj, VALUE block)
979{
980 struct objspace *objspace = objspace_ptr;
981 VALUE table;
982 st_data_t data;
983
984 RBASIC(obj)->flags |= FL_FINALIZE;
985
986 int lev = RB_GC_VM_LOCK();
987
988 if (st_lookup(objspace->finalizer_table, obj, &data)) {
989 table = (VALUE)data;
990
991 /* avoid duplicate block, table is usually small */
992 {
993 long len = RARRAY_LEN(table);
994 long i;
995
996 for (i = 0; i < len; i++) {
997 VALUE recv = RARRAY_AREF(table, i);
998 if (rb_equal(recv, block)) {
999 RB_GC_VM_UNLOCK(lev);
1000 return recv;
1001 }
1002 }
1003 }
1004
1005 rb_ary_push(table, block);
1006 }
1007 else {
1008 table = rb_ary_new3(2, rb_obj_id(obj), block);
1009 rb_obj_hide(table);
1010 st_add_direct(objspace->finalizer_table, obj, table);
1011 }
1012
1013 RB_GC_VM_UNLOCK(lev);
1014
1015 return block;
1016}
1017
1018void
1019rb_gc_impl_undefine_finalizer(void *objspace_ptr, VALUE obj)
1020{
1021 struct objspace *objspace = objspace_ptr;
1022
1023 st_data_t data = obj;
1024
1025 int lev = RB_GC_VM_LOCK();
1026 st_delete(objspace->finalizer_table, &data, 0);
1027 RB_GC_VM_UNLOCK(lev);
1028
1029 FL_UNSET(obj, FL_FINALIZE);
1030}
1031
1032void
1033rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
1034{
1035 struct objspace *objspace = objspace_ptr;
1036 VALUE table;
1037 st_data_t data;
1038
1039 if (!FL_TEST(obj, FL_FINALIZE)) return;
1040
1041 int lev = RB_GC_VM_LOCK();
1042 if (RB_LIKELY(st_lookup(objspace->finalizer_table, obj, &data))) {
1043 table = rb_ary_dup((VALUE)data);
1044 RARRAY_ASET(table, 0, rb_obj_id(dest));
1045 st_insert(objspace->finalizer_table, dest, table);
1046 FL_SET(dest, FL_FINALIZE);
1047 }
1048 else {
1049 rb_bug("rb_gc_copy_finalizer: FL_FINALIZE set but not found in finalizer_table: %s", rb_obj_info(obj));
1050 }
1051 RB_GC_VM_UNLOCK(lev);
1052}
1053
1054static int
1055move_finalizer_from_table_i(st_data_t key, st_data_t val, st_data_t arg)
1056{
1057 struct objspace *objspace = (struct objspace *)arg;
1058
1059 make_final_job(objspace, (VALUE)key, (VALUE)val);
1060
1061 return ST_DELETE;
1062}
1063
1064void
1065rb_gc_impl_shutdown_call_finalizer(void *objspace_ptr)
1066{
1067 struct objspace *objspace = objspace_ptr;
1068
1069 while (objspace->finalizer_table->num_entries) {
1070 st_foreach(objspace->finalizer_table, move_finalizer_from_table_i, (st_data_t)objspace);
1071
1072 gc_run_finalizers(objspace);
1073 }
1074
1075 unsigned int lev = RB_GC_VM_LOCK();
1076 {
1077 struct MMTk_RawVecOfObjRef registered_candidates = mmtk_get_all_obj_free_candidates();
1078 for (size_t i = 0; i < registered_candidates.len; i++) {
1079 VALUE obj = (VALUE)registered_candidates.ptr[i];
1080
1081 if (rb_gc_shutdown_call_finalizer_p(obj)) {
1082 rb_gc_obj_free(objspace_ptr, obj);
1083 RBASIC(obj)->flags = 0;
1084 }
1085 }
1086 mmtk_free_raw_vec_of_obj_ref(registered_candidates);
1087 }
1088 RB_GC_VM_UNLOCK(lev);
1089
1090 gc_run_finalizers(objspace);
1091}
1092
1093// Forking
1094
1095void
1096rb_gc_impl_before_fork(void *objspace_ptr)
1097{
1098 struct objspace *objspace = objspace_ptr;
1099
1100 retry:
1101 objspace->fork_hook_vm_lock_lev = RB_GC_VM_LOCK();
1102 rb_gc_vm_barrier();
1103
1104 /* At this point, we know that all the Ractors are paused because of the
1105 * rb_gc_vm_barrier above. Since rb_mmtk_block_for_gc is a barrier point,
1106 * one or more Ractors could be paused there. However, mmtk_before_fork is
1107 * not compatible with that because it assumes that the MMTk workers are idle,
1108 * but the workers are not idle because they are busy working on a GC.
1109 *
1110 * This essentially implements a trylock. It will optimistically lock but will
1111 * release the lock if it detects that any other Ractors are waiting in
1112 * rb_mmtk_block_for_gc.
1113 */
1114 rb_atomic_t mutator_blocking_count = RUBY_ATOMIC_LOAD(objspace->mutator_blocking_count);
1115 if (mutator_blocking_count != 0) {
1116 RB_GC_VM_UNLOCK(objspace->fork_hook_vm_lock_lev);
1117 goto retry;
1118 }
1119
1120 mmtk_before_fork();
1121}
1122
1123void
1124rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid)
1125{
1126 struct objspace *objspace = objspace_ptr;
1127
1128 mmtk_after_fork(rb_gc_get_ractor_newobj_cache());
1129
1130 RB_GC_VM_UNLOCK(objspace->fork_hook_vm_lock_lev);
1131}
1132
1133// Statistics
1134
1135void
1136rb_gc_impl_set_measure_total_time(void *objspace_ptr, VALUE flag)
1137{
1138 struct objspace *objspace = objspace_ptr;
1139
1140 objspace->measure_gc_time = RTEST(flag);
1141}
1142
1143bool
1144rb_gc_impl_get_measure_total_time(void *objspace_ptr)
1145{
1146 struct objspace *objspace = objspace_ptr;
1147
1148 return objspace->measure_gc_time;
1149}
1150
1151unsigned long long
1152rb_gc_impl_get_total_time(void *objspace_ptr)
1153{
1154 struct objspace *objspace = objspace_ptr;
1155
1156 return objspace->total_gc_time;
1157}
1158
1159size_t
1160rb_gc_impl_gc_count(void *objspace_ptr)
1161{
1162 struct objspace *objspace = objspace_ptr;
1163
1164 return objspace->gc_count;
1165}
1166
1167VALUE
1168rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE hash_or_key)
1169{
1170 VALUE hash = Qnil, key = Qnil;
1171
1172 if (SYMBOL_P(hash_or_key)) {
1173 key = hash_or_key;
1174 }
1175 else if (RB_TYPE_P(hash_or_key, T_HASH)) {
1176 hash = hash_or_key;
1177 }
1178 else {
1179 rb_bug("gc_info_decode: non-hash or symbol given");
1180 }
1181
1182#define SET(name, attr) \
1183 if (key == ID2SYM(rb_intern_const(#name))) \
1184 return (attr); \
1185 else if (hash != Qnil) \
1186 rb_hash_aset(hash, ID2SYM(rb_intern_const(#name)), (attr));
1187
1188 /* Hack to get StackProf working because it calls rb_gc_latest_gc_info with
1189 * the :state key and expects a result. This always returns the :none state. */
1190 SET(state, ID2SYM(rb_intern_const("none")));
1191#undef SET
1192
1193 if (!NIL_P(key)) {
1194 // Matched key should return above
1195 return Qundef;
1196 }
1197
1198 return hash;
1199}
1200
1201enum gc_stat_sym {
1202 gc_stat_sym_count,
1203 gc_stat_sym_time,
1204 gc_stat_sym_total_allocated_objects,
1205 gc_stat_sym_total_bytes,
1206 gc_stat_sym_used_bytes,
1207 gc_stat_sym_free_bytes,
1208 gc_stat_sym_starting_heap_address,
1209 gc_stat_sym_last_heap_address,
1210 gc_stat_sym_last
1211};
1212
1213static VALUE gc_stat_symbols[gc_stat_sym_last];
1214
1215static void
1216setup_gc_stat_symbols(void)
1217{
1218 if (gc_stat_symbols[0] == 0) {
1219#define S(s) gc_stat_symbols[gc_stat_sym_##s] = ID2SYM(rb_intern_const(#s))
1220 S(count);
1221 S(time);
1222 S(total_allocated_objects);
1223 S(total_bytes);
1224 S(used_bytes);
1225 S(free_bytes);
1226 S(starting_heap_address);
1227 S(last_heap_address);
1228 }
1229}
1230
1231VALUE
1232rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
1233{
1234 struct objspace *objspace = objspace_ptr;
1235 VALUE hash = Qnil, key = Qnil;
1236
1237 setup_gc_stat_symbols();
1238
1239 if (RB_TYPE_P(hash_or_sym, T_HASH)) {
1240 hash = hash_or_sym;
1241 }
1242 else if (SYMBOL_P(hash_or_sym)) {
1243 key = hash_or_sym;
1244 }
1245 else {
1246 rb_bug("non-hash or symbol given");
1247 }
1248
1249#define SET(name, attr) \
1250 if (key == gc_stat_symbols[gc_stat_sym_##name]) \
1251 return SIZET2NUM(attr); \
1252 else if (hash != Qnil) \
1253 rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr));
1254
1255 SET(count, objspace->gc_count);
1256 SET(time, objspace->total_gc_time / (1000 * 1000));
1257 SET(total_allocated_objects, objspace->total_allocated_objects);
1258 SET(total_bytes, mmtk_total_bytes());
1259 SET(used_bytes, mmtk_used_bytes());
1260 SET(free_bytes, mmtk_free_bytes());
1261 SET(starting_heap_address, (size_t)mmtk_starting_heap_address());
1262 SET(last_heap_address, (size_t)mmtk_last_heap_address());
1263#undef SET
1264
1265 if (!NIL_P(key)) {
1266 // Matched key should return above
1267 return Qundef;
1268 }
1269
1270 return hash;
1271}
1272
1273VALUE
1274rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym)
1275{
1276 if (RB_TYPE_P(hash_or_sym, T_HASH)) {
1277 return hash_or_sym;
1278 }
1279 else {
1280 return Qundef;
1281 }
1282}
1283
1284// Miscellaneous
1285
1286#define RB_GC_OBJECT_METADATA_ENTRY_COUNT 1
1287static struct rb_gc_object_metadata_entry object_metadata_entries[RB_GC_OBJECT_METADATA_ENTRY_COUNT + 1];
1288
1290rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj)
1291{
1292 static ID ID_object_id;
1293
1294 if (!ID_object_id) {
1295#define I(s) ID_##s = rb_intern(#s);
1296 I(object_id);
1297#undef I
1298 }
1299
1300 size_t n = 0;
1301
1302#define SET_ENTRY(na, v) do { \
1303 RUBY_ASSERT(n <= RB_GC_OBJECT_METADATA_ENTRY_COUNT); \
1304 object_metadata_entries[n].name = ID_##na; \
1305 object_metadata_entries[n].val = v; \
1306 n++; \
1307} while (0)
1308
1309 if (rb_obj_id_p(obj)) SET_ENTRY(object_id, rb_obj_id(obj));
1310
1311 object_metadata_entries[n].name = 0;
1312 object_metadata_entries[n].val = 0;
1313
1314 return object_metadata_entries;
1315}
1316
1317bool
1318rb_gc_impl_pointer_to_heap_p(void *objspace_ptr, const void *ptr)
1319{
1320 if (ptr == NULL) return false;
1321 if ((uintptr_t)ptr % sizeof(void*) != 0) return false;
1322 return mmtk_is_mmtk_object((MMTk_Address)ptr);
1323}
1324
1325bool
1326rb_gc_impl_garbage_object_p(void *objspace_ptr, VALUE obj)
1327{
1328 return false;
1329}
1330
1331void rb_gc_impl_set_event_hook(void *objspace_ptr, const rb_event_flag_t event) { }
1332
1333void
1334rb_gc_impl_copy_attributes(void *objspace_ptr, VALUE dest, VALUE obj)
1335{
1336 if (mmtk_object_wb_unprotected_p((MMTk_ObjectReference)obj)) {
1337 rb_gc_impl_writebarrier_unprotect(objspace_ptr, dest);
1338 }
1339
1340 rb_gc_impl_copy_finalizer(objspace_ptr, dest, obj);
1341}
1342
1343// GC Identification
1344
1345const char *
1346rb_gc_impl_active_gc_name(void)
1347{
1348 return "mmtk";
1349}
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
Atomic operations.
#define RUBY_ATOMIC_INC(var)
Atomically increments the value pointed by var.
Definition atomic.h:214
#define RUBY_ATOMIC_PTR_CAS(var, oldval, newval)
Identical to RUBY_ATOMIC_CAS, except it expects its arguments are void*.
Definition atomic.h:365
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
Definition atomic.h:69
#define RUBY_ATOMIC_DEC(var)
Atomically decrements the value pointed by var.
Definition atomic.h:223
#define RUBY_ATOMIC_LOAD(var)
Atomic load.
Definition atomic.h:175
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
unsigned int rb_postponed_job_handle_t
The type of a handle returned from rb_postponed_job_preregister and passed to rb_postponed_job_trigge...
Definition debug.h:703
void rb_postponed_job_trigger(rb_postponed_job_handle_t h)
Triggers a pre-registered job registered with rb_postponed_job_preregister, scheduling it for executi...
Definition vm_trace.c:1952
rb_postponed_job_handle_t rb_postponed_job_preregister(unsigned int flags, rb_postponed_job_func_t func, void *data)
Pre-registers a func in Ruby's postponed job preregistration table, returning an opaque handle which ...
Definition vm_trace.c:1918
#define RUBY_INTERNAL_EVENT_FREEOBJ
Object swept.
Definition event.h:94
#define RUBY_INTERNAL_EVENT_GC_START
GC started.
Definition event.h:95
uint32_t rb_event_flag_t
Represents event(s).
Definition event.h:108
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
Definition fl_type.h:238
#define xfree
Old name of ruby_xfree.
Definition xmalloc.h:58
#define Qundef
Old name of RUBY_Qundef.
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:134
#define T_NONE
Old name of RUBY_T_NONE.
Definition value_type.h:74
#define SIZET2NUM
Old name of RB_SIZE2NUM.
Definition size_t.h:62
#define xmalloc
Old name of ruby_xmalloc.
Definition xmalloc.h:53
#define LONG2FIX
Old name of RB_INT2FIX.
Definition long.h:49
#define FL_FINALIZE
Old name of RUBY_FL_FINALIZE.
Definition fl_type.h:61
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
#define FL_SET
Old name of RB_FL_SET.
Definition fl_type.h:128
#define rb_ary_new3
Old name of rb_ary_new_from_args.
Definition array.h:658
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
Definition int.h:43
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
Definition value_type.h:56
#define NIL_P
Old name of RB_NIL_P.
#define FL_TEST
Old name of RB_FL_TEST.
Definition fl_type.h:130
#define FL_UNSET
Old name of RB_FL_UNSET.
Definition fl_type.h:132
#define SYMBOL_P
Old name of RB_SYMBOL_P.
Definition value_type.h:88
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
Definition object.c:100
VALUE rb_mGC
GC module.
Definition gc.c:424
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
Definition object.c:176
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1515
VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker)
Raises rb_eNotImpError.
Definition vm_method.c:863
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
Definition io.h:2
int len
Length of the buffer.
Definition io.h:8
#define RB_ULONG2NUM
Just another name of rb_ulong2num_inline.
Definition long.h:59
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
Definition memory.h:167
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:51
#define RARRAY_AREF(a, i)
Definition rarray.h:403
#define RBASIC(obj)
Convenient casting macro.
Definition rbasic.h:40
int ruby_native_thread_p(void)
Queries if the thread which calls this function is a ruby's thread.
Definition thread.c:5830
#define RTEST
This is an old name of RB_TEST.
C99 shim for <stdbool.h>.
void * rust_closure
The pointer to the Rust-level closure object.
Definition mmtk.h:50
MMTk_ObjectClosureFunction c_function
The function to be called from C.
Definition mmtk.h:46
Ruby object's base components.
Definition rbasic.h:69
Definition gc_impl.h:15
Definition st.h:79
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40