Ruby: internal/gc.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions | Variables
gc.h File Reference

Internal header for GC. More...

`#include "ruby/internal/config.h"`
`#include <stddef.h>`
`#include "internal/compilers.h"`
`#include "ruby/ruby.h"`

Go to the source code of this file.

## Data Structures
struct | ractor_newobj_cache

## Macros
#define | RB_NEWOBJ_OF(var, T, c, f)
#define | RB_EC_NEWOBJ_OF(ec, var, T, c, f)
#define | NEWOBJ_OF(var, T, c, f) RB_NEWOBJ_OF((var), T, (c), (f))
#define | RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */
#define | UNALIGNED_MEMBER_ACCESS(expr) (expr)
#define | UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
#define | RB_OBJ_WRITE(a, slot, b)
#define | SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))
#define | ruby_sized_xrealloc ruby_sized_xrealloc_inlined
#define | ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined
#define | ruby_sized_xfree ruby_sized_xfree_inlined

## Typedefs
typedef struct ractor_newobj_cache | rb_ractor_newobj_cache_t

## Functions
RUBY_ATTR_MALLOC void * | ruby_mimmalloc (size_t size)
void | ruby_mimfree (void *ptr)
void | rb_objspace_set_event_hook (const rb_event_flag_t event)
VALUE | rb_objspace_gc_enable (struct rb_objspace *)
VALUE | rb_objspace_gc_disable (struct rb_objspace *)
void | ruby_gc_set_params (void)
void | rb_copy_wb_protected_attribute (VALUE dest, VALUE obj)
| __attribute__ ((__alloc_align__(1))) RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t
size_t | RUBY_ATTR_ALLOC_SIZE ((2))
size_t | rb_size_mul_or_raise (size_t, size_t, VALUE)
size_t | rb_size_mul_add_or_raise (size_t, size_t, size_t, VALUE)
RUBY_ATTR_MALLOC void * | rb_xmalloc_mul_add (size_t, size_t, size_t)
void * | rb_xrealloc_mul_add (const void *, size_t, size_t, size_t)
RUBY_ATTR_MALLOC void * | rb_xmalloc_mul_add_mul (size_t, size_t, size_t, size_t)
RUBY_ATTR_MALLOC void * | rb_xcalloc_mul_add_mul (size_t, size_t, size_t, size_t)
VALUE | rb_class_allocate_instance (VALUE klass)
const char * | rb_objspace_data_type_name (VALUE obj)
VALUE | rb_wb_protected_newobj_of (VALUE, VALUE)
VALUE | rb_wb_unprotected_newobj_of (VALUE, VALUE)
VALUE | rb_ec_wb_protected_newobj_of (struct rb_execution_context_struct *ec, VALUE klass, VALUE flags)
size_t | rb_obj_memsize_of (VALUE)
void | rb_gc_verify_internal_consistency (void)
size_t | rb_obj_gc_flags (VALUE, ID[], size_t)
void | rb_gc_mark_values (long n, const VALUE *values)
void | rb_gc_mark_vm_stack_values (long n, const VALUE *values)
void * | ruby_sized_xrealloc (void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2))
void * | ruby_sized_xrealloc2 (void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2
void void | ruby_sized_xfree (void *x, size_t size)
void | rb_gc_ractor_newobj_cache_clear (rb_ractor_newobj_cache_t *newobj_cache)
int | rb_ec_stack_check (struct rb_execution_context_struct *ec)
void | rb_gc_writebarrier_remember (VALUE obj)
const char * | rb_obj_info (VALUE obj)

## Variables
VALUE * | ruby_initial_gc_stress_ptr
int | ruby_disable_gc

## Detailed Description

Internal header for GC.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file gc.h.

## Macro Definition Documentation

## ◆ NEWOBJ_OF

#define NEWOBJ_OF | ( |  | var,
|  |  | T,
|  |  | c,
|  |  | f
| ) |  | RB_NEWOBJ_OF((var), T, (c), (f))

Definition at line 39 of file gc.h.

## ◆ RB_EC_NEWOBJ_OF

#define RB_EC_NEWOBJ_OF | ( |  | ec,
|  |  | var,
|  |  | T,
|  |  | c,
|  |  | f
| ) |  |

Value:
T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED) : \
rb_wb_unprotected_newobj_of((c), (f)))
T
unsigned char T
Definition: cls_uchar_va.c:10
FL_WB_PROTECTED
#define FL_WB_PROTECTED
Definition: fl_type.h:50
rb_wb_unprotected_newobj_of
VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE)
Definition: gc.c:2342
f
#define f

Definition at line 34 of file gc.h.

## ◆ RB_NEWOBJ_OF

#define RB_NEWOBJ_OF | ( |  | var,
|  |  | T,
|  |  | c,
|  |  | f
| ) |  |

Value:
T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED) : \
rb_wb_unprotected_newobj_of((c), (f)))

Definition at line 29 of file gc.h.

## ◆ RB_OBJ_GC_FLAGS_MAX

#define RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */

Definition at line 40 of file gc.h.

## ◆ RB_OBJ_WRITE

#define RB_OBJ_WRITE | ( |  | a,
|  |  | slot,
|  |  | b
| ) |  |

Value:
rb_obj_write((VALUE)(a), UNALIGNED_MEMBER_ACCESS((VALUE *)(slot)), \
(VALUE)(b), __FILE__, __LINE__)
UNALIGNED_MEMBER_ACCESS
#define UNALIGNED_MEMBER_ACCESS(expr)
Definition: gc.h:43
VALUE
unsigned long VALUE
Definition: value.h:38

Definition at line 60 of file gc.h.

## ◆ ruby_sized_xfree

#define ruby_sized_xfree ruby_sized_xfree_inlined

Definition at line 166 of file gc.h.

## ◆ ruby_sized_xrealloc

#define ruby_sized_xrealloc ruby_sized_xrealloc_inlined

Definition at line 164 of file gc.h.

## ◆ ruby_sized_xrealloc2

#define ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined

Definition at line 165 of file gc.h.

## ◆ SIZED_REALLOC_N

#define SIZED_REALLOC_N | ( |  | v,
|  |  | T,
|  |  | m,
|  |  | n
| ) |  | ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))

Definition at line 159 of file gc.h.

## ◆ UNALIGNED_MEMBER_ACCESS

#define UNALIGNED_MEMBER_ACCESS | ( |  | expr | ) | (expr)

Definition at line 43 of file gc.h.

## ◆ UNALIGNED_MEMBER_PTR

#define UNALIGNED_MEMBER_PTR | ( |  | ptr,
|  |  | mem
| ) |  | UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)

Definition at line 59 of file gc.h.

## Typedef Documentation

## ◆ rb_ractor_newobj_cache_t

typedef struct ractor_newobj_cache rb_ractor_newobj_cache_t

## Function Documentation

## ◆ __attribute__()

__attribute__ | ( | (__alloc_align__(1)) |  | ) |

## ◆ rb_class_allocate_instance()

VALUE rb_class_allocate_instance | ( | VALUE | klass | ) |

Definition at line 2482 of file gc.c.

References heap_page::flags, Qundef, RGENGC_WB_PROTECTED_OBJECT, ROBJECT_EMBED, and T_OBJECT.

## ◆ rb_copy_wb_protected_attribute()

void rb_copy_wb_protected_attribute | ( | VALUE | dest,
|  | VALUE | obj
| ) |  |

Definition at line 7876 of file gc.c.

References GET_HEAP_WB_UNPROTECTED_BITS, MARK_IN_BITMAP, and rb_objspace.

## ◆ rb_ec_stack_check()

int rb_ec_stack_check | ( | struct rb_execution_context_struct * | ec | ) |

Definition at line 5546 of file gc.c.

## ◆ rb_ec_wb_protected_newobj_of()

VALUE rb_ec_wb_protected_newobj_of | ( | struct rb_execution_context_struct * | ec,
|  | VALUE | klass,
|  | VALUE | flags
| ) |  |

Definition at line 2356 of file gc.c.

References FL_WB_PROTECTED, heap_page::flags, GC_ASSERT, and TRUE.

## ◆ rb_gc_mark_values()

void rb_gc_mark_values | ( | long | n,
|  | const VALUE * | values
| ) |  |

Definition at line 5596 of file gc.c.

References rb_objspace.

Referenced by rb_vm_mark().

## ◆ rb_gc_mark_vm_stack_values()

void rb_gc_mark_vm_stack_values | ( | long | n,
|  | const VALUE * | values
| ) |  |

Definition at line 5619 of file gc.c.

References rb_objspace.

Referenced by rb_execution_context_mark().

## ◆ rb_gc_ractor_newobj_cache_clear()

void rb_gc_ractor_newobj_cache_clear | ( | rb_ractor_newobj_cache_t * | newobj_cache | ) |

Definition at line 7937 of file gc.c.

References RVALUE::as, RVALUE::free, heap_page::freelist, ractor_newobj_cache::freelist, RVALUE::next, NULL, RUBY_DEBUG_LOG, and ractor_newobj_cache::using_page.

## ◆ rb_gc_verify_internal_consistency()

void rb_gc_verify_internal_consistency | ( | void |  | ) |

Definition at line 7137 of file gc.c.

## ◆ rb_gc_writebarrier_remember()

void rb_gc_writebarrier_remember | ( | VALUE | obj | ) |

Definition at line 7814 of file gc.c.

References gc_report, is_incremental_marking, and rb_objspace.

Referenced by rb_ary_cancel_sharing(), rb_hash_keys(), and rb_hash_values().

## ◆ rb_obj_gc_flags()

size_t rb_obj_gc_flags | ( | VALUE | ,
|  | ID | [],
|  | size_t |
| ) |  |

## ◆ rb_obj_info()

const char * rb_obj_info | ( | VALUE | obj | ) |

Definition at line 12499 of file gc.c.

Referenced by rb_raw_obj_info().

## ◆ rb_obj_memsize_of()

size_t rb_obj_memsize_of | ( | VALUE | obj | ) |

Definition at line 4296 of file gc.c.

References TRUE.

## ◆ rb_objspace_data_type_name()

const char * rb_objspace_data_type_name | ( | VALUE | obj | ) |

Definition at line 2534 of file gc.c.

Referenced by rb_raw_obj_info().

## ◆ rb_objspace_gc_disable()

VALUE rb_objspace_gc_disable | ( | struct rb_objspace * | objspace | ) |

Definition at line 9932 of file gc.c.

Referenced by rb_gc_disable().

## ◆ rb_objspace_gc_enable()

VALUE rb_objspace_gc_enable | ( | struct rb_objspace * | objspace | ) |

Definition at line 9895 of file gc.c.

References dont_gc_off, dont_gc_val, Qfalse, and Qtrue.

Referenced by Init_VM(), and rb_gc_enable().

## ◆ rb_objspace_set_event_hook()

void rb_objspace_set_event_hook | ( | const rb_event_flag_t | event | ) |

Definition at line 2052 of file gc.c.

References rb_objspace::flags, rb_objspace::has_hook, rb_objspace::hook_events, rb_objspace, and RUBY_INTERNAL_EVENT_OBJSPACE_MASK.

## ◆ rb_size_mul_add_or_raise()

size_t rb_size_mul_add_or_raise | ( | size_t | x,
|  | size_t | y,
|  | size_t | z,
|  | VALUE | exc
| ) |  |

Definition at line 215 of file gc.c.

## ◆ rb_size_mul_or_raise()

size_t rb_size_mul_or_raise | ( | size_t | x,
|  | size_t | y,
|  | VALUE | exc
| ) |  |

Definition at line 188 of file gc.c.

## ◆ rb_wb_protected_newobj_of()

VALUE rb_wb_protected_newobj_of | ( | VALUE | klass,
|  | VALUE | flags
| ) |  |

Definition at line 2349 of file gc.c.

References FL_WB_PROTECTED, heap_page::flags, GC_ASSERT, and TRUE.

## ◆ rb_wb_unprotected_newobj_of()

VALUE rb_wb_unprotected_newobj_of | ( | VALUE | klass,
|  | VALUE | flags
| ) |  |

Definition at line 2342 of file gc.c.

References FALSE, FL_WB_PROTECTED, heap_page::flags, and GC_ASSERT.

## ◆ rb_xcalloc_mul_add_mul()

RUBY_ATTR_MALLOC void * rb_xcalloc_mul_add_mul | ( | size_t | x,
|  | size_t | y,
|  | size_t | z,
|  | size_t | w
| ) |  |

Definition at line 10941 of file gc.c.

References rb_eArgError, and ruby_xcalloc().

## ◆ rb_xmalloc_mul_add()

RUBY_ATTR_MALLOC void * rb_xmalloc_mul_add | ( | size_t | x,
|  | size_t | y,
|  | size_t | z
| ) |  |

Definition at line 10920 of file gc.c.

References rb_eArgError, and ruby_xmalloc().

## ◆ rb_xmalloc_mul_add_mul()

RUBY_ATTR_MALLOC void * rb_xmalloc_mul_add_mul | ( | size_t | x,
|  | size_t | y,
|  | size_t | z,
|  | size_t | w
| ) |  |

Definition at line 10934 of file gc.c.

References rb_eArgError, and ruby_xmalloc().

## ◆ rb_xrealloc_mul_add()

void * rb_xrealloc_mul_add | ( | const void * | p,
|  | size_t | x,
|  | size_t | y,
|  | size_t | z
| ) |  |

Definition at line 10927 of file gc.c.

References rb_eArgError, and ruby_xrealloc().

## ◆ RUBY_ATTR_ALLOC_SIZE()

size_t RUBY_ATTR_ALLOC_SIZE | ( | (2) |  | ) |

## ◆ ruby_gc_set_params()

void ruby_gc_set_params | ( | void |  | ) |

Definition at line 10122 of file gc.c.

References FALSE, ruby_gc_params_t::growth_factor, ruby_gc_params_t::growth_max_slots, ruby_gc_params_t::heap_free_slots, ruby_gc_params_t::heap_free_slots_goal_ratio, ruby_gc_params_t::heap_free_slots_max_ratio, ruby_gc_params_t::heap_free_slots_min_ratio, ruby_gc_params_t::heap_init_slots, ruby_gc_params_t::malloc_limit_growth_factor, ruby_gc_params_t::malloc_limit_max, ruby_gc_params_t::malloc_limit_min, ruby_gc_params_t::oldmalloc_limit_growth_factor, ruby_gc_params_t::oldmalloc_limit_max, ruby_gc_params_t::oldmalloc_limit_min, ruby_gc_params_t::oldobject_limit_factor, rb_objspace, rb_objspace::rgengc, SIZE_MAX, and TRUE.

## ◆ ruby_mimfree()

void ruby_mimfree | ( | void * | ptr | ) |

Definition at line 10979 of file gc.c.

References free, and ptr.

Referenced by ruby_vm_destruct().

## ◆ ruby_mimmalloc()

RUBY_ATTR_MALLOC void * ruby_mimmalloc | ( | size_t | size | ) |

Definition at line 10951 of file gc.c.

References malloc, NULL, and malloc_obj_info::size.

Referenced by Init_BareVM(), rb_ractor_main_alloc(), and rb_threadptr_root_fiber_setup().

## ◆ ruby_sized_xfree()

void void ruby_sized_xfree | ( | void * | x,
|  | size_t | size
| ) |  |

Definition at line 10906 of file gc.c.

## ◆ ruby_sized_xrealloc()

void * ruby_sized_xrealloc | ( | void * | ptr,
|  | size_t | new_size,
|  | size_t | old_size
| ) |  |

Definition at line 10871 of file gc.c.

References ptr.

## ◆ ruby_sized_xrealloc2()

void * ruby_sized_xrealloc2 | ( | void * | ptr,
|  | size_t | new_count,
|  | size_t | element_size,
|  | size_t | old_count
| ) |  |

## Variable Documentation

## ◆ ruby_disable_gc

int ruby_disable_gc
| extern

Definition at line 982 of file gc.c.

## ◆ ruby_initial_gc_stress_ptr

VALUE* ruby_initial_gc_stress_ptr
| extern

Definition at line 879 of file gc.c.

Referenced by ruby_env_debug_option().