Ruby: gc/gc_impl.h Source File

Ruby 3.4.3p32 (2025-04-14 revision d0b7e5b6a04bde21ca483d20a1546b28b401c2d4)

gc_impl.h
1#ifndef GC_GC_IMPL_H
2#define GC_GC_IMPL_H
11#include "ruby/ruby.h"
12
13#ifdef BUILDING_MODULAR_GC
14# define GC_IMPL_FN
15#else
16// `GC_IMPL_FN` is an implementation detail of `!USE_MODULAR_GC` builds
17// to have the default GC in the same translation unit as gc.c for
18// the sake of optimizer visibility. It expands to nothing unless
19// you're the default GC.
20//
21// For the default GC, do not copy-paste this when implementing
22// these functions. This takes advantage of internal linkage winning
23// when appearing first. See C99 6.2.2p4.
24# define GC_IMPL_FN static
25#endif
26
27// Bootup
28GC_IMPL_FN void *rb_gc_impl_objspace_alloc(void);
29GC_IMPL_FN void rb_gc_impl_objspace_init(void *objspace_ptr);
30GC_IMPL_FN void rb_gc_impl_objspace_free(void *objspace_ptr);
31GC_IMPL_FN void *rb_gc_impl_ractor_cache_alloc(void *objspace_ptr, void *ractor);
32GC_IMPL_FN void rb_gc_impl_ractor_cache_free(void *objspace_ptr, void *cache);
33GC_IMPL_FN void rb_gc_impl_set_params(void *objspace_ptr);
34GC_IMPL_FN void rb_gc_impl_init(void);
35GC_IMPL_FN size_t *rb_gc_impl_heap_sizes(void *objspace_ptr);
36// Shutdown
37GC_IMPL_FN void rb_gc_impl_shutdown_free_objects(void *objspace_ptr);
38// GC
39GC_IMPL_FN void rb_gc_impl_start(void *objspace_ptr, bool full_mark, bool immediate_mark, bool immediate_sweep, bool compact);
40GC_IMPL_FN bool rb_gc_impl_during_gc_p(void *objspace_ptr);
41GC_IMPL_FN void rb_gc_impl_prepare_heap(void *objspace_ptr);
42GC_IMPL_FN void rb_gc_impl_gc_enable(void *objspace_ptr);
43GC_IMPL_FN void rb_gc_impl_gc_disable(void *objspace_ptr, bool finish_current_gc);
44GC_IMPL_FN bool rb_gc_impl_gc_enabled_p(void *objspace_ptr);
45GC_IMPL_FN void rb_gc_impl_stress_set(void *objspace_ptr, VALUE flag);
46GC_IMPL_FN VALUE rb_gc_impl_stress_get(void *objspace_ptr);
47GC_IMPL_FN VALUE rb_gc_impl_config_get(void *objspace_ptr);
48GC_IMPL_FN void rb_gc_impl_config_set(void *objspace_ptr, VALUE hash);
49// Object allocation
50GC_IMPL_FN VALUE rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, bool wb_protected, size_t alloc_size);
51GC_IMPL_FN size_t rb_gc_impl_obj_slot_size(VALUE obj);
52GC_IMPL_FN size_t rb_gc_impl_heap_id_for_size(void *objspace_ptr, size_t size);
53GC_IMPL_FN bool rb_gc_impl_size_allocatable_p(size_t size);
54// Malloc
55/*
56 * BEWARE: These functions may or may not run under GVL.
57 *
58 * You might want to make them thread-safe.
59 * Garbage collecting inside is possible if and only if you
60 * already have GVL. Also raising exceptions without one is a
61 * total disaster.
62 *
63 * When you absolutely cannot allocate the requested amount of
64 * memory just return NULL (with appropriate errno set).
65 * The caller side takes care of that situation.
66 */
67GC_IMPL_FN void *rb_gc_impl_malloc(void *objspace_ptr, size_t size);
68GC_IMPL_FN void *rb_gc_impl_calloc(void *objspace_ptr, size_t size);
69GC_IMPL_FN void *rb_gc_impl_realloc(void *objspace_ptr, void *ptr, size_t new_size, size_t old_size);
70GC_IMPL_FN void rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size);
71GC_IMPL_FN void rb_gc_impl_adjust_memory_usage(void *objspace_ptr, ssize_t diff);
72// Marking
73GC_IMPL_FN void rb_gc_impl_mark(void *objspace_ptr, VALUE obj);
74GC_IMPL_FN void rb_gc_impl_mark_and_move(void *objspace_ptr, VALUE *ptr);
75GC_IMPL_FN void rb_gc_impl_mark_and_pin(void *objspace_ptr, VALUE obj);
76GC_IMPL_FN void rb_gc_impl_mark_maybe(void *objspace_ptr, VALUE obj);
77GC_IMPL_FN void rb_gc_impl_mark_weak(void *objspace_ptr, VALUE *ptr);
78GC_IMPL_FN void rb_gc_impl_remove_weak(void *objspace_ptr, VALUE parent_obj, VALUE *ptr);
79// Compaction
80GC_IMPL_FN bool rb_gc_impl_object_moved_p(void *objspace_ptr, VALUE obj);
81GC_IMPL_FN VALUE rb_gc_impl_location(void *objspace_ptr, VALUE value);
82// Write barriers
83GC_IMPL_FN void rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b);
84GC_IMPL_FN void rb_gc_impl_writebarrier_unprotect(void *objspace_ptr, VALUE obj);
85GC_IMPL_FN void rb_gc_impl_writebarrier_remember(void *objspace_ptr, VALUE obj);
86// Heap walking
87GC_IMPL_FN void rb_gc_impl_each_objects(void *objspace_ptr, int (*callback)(void *, void *, size_t, void *), void *data);
88GC_IMPL_FN void rb_gc_impl_each_object(void *objspace_ptr, void (*func)(VALUE obj, void *data), void *data);
89// Finalizers
90GC_IMPL_FN void rb_gc_impl_make_zombie(void *objspace_ptr, VALUE obj, void (*dfree)(void *), void *data);
91GC_IMPL_FN VALUE rb_gc_impl_define_finalizer(void *objspace_ptr, VALUE obj, VALUE block);
92GC_IMPL_FN void rb_gc_impl_undefine_finalizer(void *objspace_ptr, VALUE obj);
93GC_IMPL_FN void rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj);
94GC_IMPL_FN void rb_gc_impl_shutdown_call_finalizer(void *objspace_ptr);
95// Object ID
96GC_IMPL_FN VALUE rb_gc_impl_object_id(void *objspace_ptr, VALUE obj);
97GC_IMPL_FN VALUE rb_gc_impl_object_id_to_ref(void *objspace_ptr, VALUE object_id);
98// Forking
99GC_IMPL_FN void rb_gc_impl_before_fork(void *objspace_ptr);
100GC_IMPL_FN void rb_gc_impl_after_fork(void *objspace_ptr, rb_pid_t pid);
101// Statistics
102GC_IMPL_FN void rb_gc_impl_set_measure_total_time(void *objspace_ptr, VALUE flag);
103GC_IMPL_FN bool rb_gc_impl_get_measure_total_time(void *objspace_ptr);
104GC_IMPL_FN unsigned long long rb_gc_impl_get_total_time(void *objspace_ptr);
105GC_IMPL_FN size_t rb_gc_impl_gc_count(void *objspace_ptr);
106GC_IMPL_FN VALUE rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE key);
107GC_IMPL_FN VALUE rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym);
108GC_IMPL_FN VALUE rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym);
109GC_IMPL_FN const char *rb_gc_impl_active_gc_name(void);
110// Miscellaneous
111GC_IMPL_FN size_t rb_gc_impl_obj_flags(void *objspace_ptr, VALUE obj, ID* flags, size_t max);
112GC_IMPL_FN bool rb_gc_impl_pointer_to_heap_p(void *objspace_ptr, const void *ptr);
113GC_IMPL_FN bool rb_gc_impl_garbage_object_p(void *objspace_ptr, VALUE obj);
114GC_IMPL_FN void rb_gc_impl_set_event_hook(void *objspace_ptr, const rb_event_flag_t event);
115GC_IMPL_FN void rb_gc_impl_copy_attributes(void *objspace_ptr, VALUE dest, VALUE obj);
116
117#undef GC_IMPL_FN
118
119#endif
rb_event_flag_t
uint32_t rb_event_flag_t
Represents event(s).
Definition event.h:108
ruby.h
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40