Ruby  2.0.0p648(2015-12-16revision53162)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
gc.c File Reference
#include "ruby/ruby.h"
#include "ruby/st.h"
#include "ruby/re.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "eval_intern.h"
#include "vm_core.h"
#include "internal.h"
#include "gc.h"
#include "constant.h"
#include "ruby_atomic.h"
#include "probes.h"
#include <stdio.h>
#include <setjmp.h>
#include <sys/types.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  ruby_gc_params_t
 
struct  gc_profile_record
 
struct  RVALUE
 
struct  heaps_slot
 
struct  heaps_header
 
struct  heaps_free_bitmap
 
struct  gc_list
 
struct  stack_chunk
 
struct  mark_stack
 
struct  rb_objspace
 
struct  rb_objspace::mark_func_data_struct
 
struct  each_obj_args
 
struct  os_each_struct
 
struct  force_finalize_list
 
struct  mark_tbl_arg
 
struct  weakmap
 

Macros

#define VALGRIND_MAKE_MEM_DEFINED(p, n)   0
 
#define VALGRIND_MAKE_MEM_UNDEFINED(p, n)   0
 
#define rb_setjmp(env)   RUBY_SETJMP(env)
 
#define rb_jmp_buf   rb_jmpbuf_t
 
#define GC_MALLOC_LIMIT   8000000
 
#define HEAP_MIN_SLOTS   10000
 
#define FREE_MIN   4096
 
#define nomem_error   GET_VM()->special_exceptions[ruby_error_nomemory]
 
#define GC_PROFILE_MORE_DETAIL   0
 
#define STACK_CHUNK_SIZE   500
 
#define CALC_EXACT_MALLOC_SIZE   0
 
#define rb_objspace   (*GET_VM()->objspace)
 
#define ruby_initial_gc_stress   initial_params.gc_stress
 
#define malloc_limit   objspace->malloc_params.limit
 
#define malloc_increase   objspace->malloc_params.increase
 
#define heaps   objspace->heap.ptr
 
#define heaps_length   objspace->heap.length
 
#define heaps_used   objspace->heap.used
 
#define lomem   objspace->heap.range[0]
 
#define himem   objspace->heap.range[1]
 
#define heaps_inc   objspace->heap.increment
 
#define heaps_freed   objspace->heap.freed
 
#define dont_gc   objspace->flags.dont_gc
 
#define during_gc   objspace->flags.during_gc
 
#define finalizing   objspace->flags.finalizing
 
#define finalizer_table   objspace->final.table
 
#define deferred_final_list   objspace->final.deferred
 
#define global_List   objspace->global_list
 
#define ruby_gc_stress   objspace->gc_stress
 
#define initial_malloc_limit   initial_params.initial_malloc_limit
 
#define initial_heap_min_slots   initial_params.initial_heap_min_slots
 
#define initial_free_min   initial_params.initial_free_min
 
#define is_lazy_sweeping(objspace)   ((objspace)->heap.sweep_slots != 0)
 
#define nonspecial_obj_id(obj)   (VALUE)((SIGNED_VALUE)(obj)|FIXNUM_FLAG)
 
#define obj_id_to_ref(objid)   ((objid) ^ FIXNUM_FLAG) /* unset FIXNUM_FLAG */
 
#define RANY(o)   ((RVALUE*)(o))
 
#define has_free_object   (objspace->heap.free_slots && objspace->heap.free_slots->freelist)
 
#define HEAP_HEADER(p)   ((struct heaps_header *)(p))
 
#define GET_HEAP_HEADER(x)   (HEAP_HEADER((uintptr_t)(x) & ~(HEAP_ALIGN_MASK)))
 
#define GET_HEAP_SLOT(x)   (GET_HEAP_HEADER(x)->base)
 
#define GET_HEAP_BITMAP(x)   (GET_HEAP_HEADER(x)->bits)
 
#define NUM_IN_SLOT(p)   (((uintptr_t)(p) & HEAP_ALIGN_MASK)/sizeof(RVALUE))
 
#define BITMAP_INDEX(p)   (NUM_IN_SLOT(p) / (sizeof(uintptr_t) * CHAR_BIT))
 
#define BITMAP_OFFSET(p)   (NUM_IN_SLOT(p) & ((sizeof(uintptr_t) * CHAR_BIT)-1))
 
#define MARKED_IN_BITMAP(bits, p)   (bits[BITMAP_INDEX(p)] & ((uintptr_t)1 << BITMAP_OFFSET(p)))
 
#define HEAP_ALIGN_LOG   14
 
#define CEILDIV(i, mod)   (((i) + (mod) - 1)/(mod))
 
#define NUM2PTR(x)   NUM2ULONG(x)
 
#define COUNT_TYPE(t)   case (t): type = ID2SYM(rb_intern(#t)); break;
 
#define MARK_IN_BITMAP(bits, p)   (bits[BITMAP_INDEX(p)] = bits[BITMAP_INDEX(p)] | ((uintptr_t)1 << BITMAP_OFFSET(p)))
 
#define SET_STACK_END   SET_MACHINE_STACK_END(&th->machine_stack_end)
 
#define STACK_START   (th->machine_stack_start)
 
#define STACK_END   (th->machine_stack_end)
 
#define STACK_LEVEL_MAX   (th->machine_stack_maxsize/sizeof(VALUE))
 
#define STACK_LENGTH
 
#define STACKFRAME_FOR_CALL_CFUNC   512
 
#define rb_gc_mark_locations(start, end)   gc_mark_locations(objspace, (start), (end))
 
#define GET_STACK_BOUNDS(start, end, appendix)
 
#define numberof(array)   (int)(sizeof(array) / sizeof((array)[0]))
 
#define STR_ASSOC   FL_USER3 /* copied from string.c */
 
#define GC_NOTIFY   0
 
#define TRY_WITH_GC(alloc)
 
#define GC_PROFILE_RECORD_DEFAULT_SIZE   100
 

Typedefs

typedef struct gc_profile_record gc_profile_record
 
typedef struct RVALUE RVALUE
 
typedef struct stack_chunk stack_chunk_t
 
typedef struct mark_stack mark_stack_t
 
typedef struct rb_objspace rb_objspace_t
 
typedef int each_obj_callback(void *, void *, size_t, void *)
 

Enumerations

enum  {
  HEAP_ALIGN = (1UL << HEAP_ALIGN_LOG), HEAP_ALIGN_MASK = (~(~0UL << HEAP_ALIGN_LOG)), REQUIRED_SIZE_BY_MALLOC = (sizeof(size_t) * 5), HEAP_SIZE = (HEAP_ALIGN - REQUIRED_SIZE_BY_MALLOC),
  HEAP_OBJ_LIMIT = (unsigned int)((HEAP_SIZE - sizeof(struct heaps_header))/sizeof(struct RVALUE)), HEAP_BITMAP_LIMIT = CEILDIV(CEILDIV(HEAP_SIZE, sizeof(struct RVALUE)), sizeof(uintptr_t) * CHAR_BIT)
}
 

Functions

static void rb_objspace_call_finalizer (rb_objspace_t *objspace)
 
static VALUE define_final0 (VALUE obj, VALUE block)
 
VALUE rb_define_final (VALUE obj, VALUE block)
 
VALUE rb_undefine_final (VALUE obj)
 
static void run_final (rb_objspace_t *objspace, VALUE obj)
 
static void initial_expand_heap (rb_objspace_t *objspace)
 
static void negative_size_allocation_error (const char *)
 
static void * aligned_malloc (size_t, size_t)
 
static void aligned_free (void *)
 
static void init_mark_stack (mark_stack_t *stack)
 
static VALUE lazy_sweep_enable (void)
 
static int garbage_collect (rb_objspace_t *)
 
static int gc_prepare_free_objects (rb_objspace_t *)
 
static void mark_tbl (rb_objspace_t *, st_table *)
 
static void rest_sweep (rb_objspace_t *)
 
static void gc_mark_stacked_objects (rb_objspace_t *)
 
static double getrusage_time (void)
 
static void gc_prof_timer_start (rb_objspace_t *)
 
static void gc_prof_timer_stop (rb_objspace_t *, int)
 
static void gc_prof_mark_timer_start (rb_objspace_t *)
 
static void gc_prof_mark_timer_stop (rb_objspace_t *)
 
static void gc_prof_sweep_timer_start (rb_objspace_t *)
 
static void gc_prof_sweep_timer_stop (rb_objspace_t *)
 
static void gc_prof_set_malloc_info (rb_objspace_t *)
 
rb_objspace_trb_objspace_alloc (void)
 
static void free_stack_chunks (mark_stack_t *)
 
void rb_objspace_free (rb_objspace_t *objspace)
 
void rb_global_variable (VALUE *var)
 
static void allocate_sorted_heaps (rb_objspace_t *objspace, size_t next_heaps_length)
 
static void link_free_heap_slot (rb_objspace_t *objspace, struct heaps_slot *slot)
 
static void unlink_free_heap_slot (rb_objspace_t *objspace, struct heaps_slot *slot)
 
static void assign_heap_slot (rb_objspace_t *objspace)
 
static void add_heap_slots (rb_objspace_t *objspace, size_t add)
 
static void init_heap (rb_objspace_t *objspace)
 
static void set_heaps_increment (rb_objspace_t *objspace)
 
static int heaps_increment (rb_objspace_t *objspace)
 
static VALUE newobj (VALUE klass, VALUE flags)
 
VALUE rb_newobj (void)
 
VALUE rb_newobj_of (VALUE klass, VALUE flags)
 
NODErb_node_newnode (enum node_type type, VALUE a0, VALUE a1, VALUE a2)
 
VALUE rb_data_object_alloc (VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree)
 
VALUE rb_data_typed_object_alloc (VALUE klass, void *datap, const rb_data_type_t *type)
 
size_t rb_objspace_data_type_memsize (VALUE obj)
 
const char * rb_objspace_data_type_name (VALUE obj)
 
static void gc_mark (rb_objspace_t *objspace, VALUE ptr)
 
static void gc_mark_children (rb_objspace_t *objspace, VALUE ptr)
 
static int is_pointer_to_heap (rb_objspace_t *objspace, void *ptr)
 
static int free_method_entry_i (ID key, rb_method_entry_t *me, st_data_t data)
 
void rb_free_m_table (st_table *tbl)
 
static int free_const_entry_i (ID key, rb_const_entry_t *ce, st_data_t data)
 
void rb_free_const_table (st_table *tbl)
 
static int obj_free (rb_objspace_t *, VALUE)
 
static struct heaps_slotadd_slot_local_freelist (rb_objspace_t *objspace, RVALUE *p)
 
static void unlink_heap_slot (rb_objspace_t *objspace, struct heaps_slot *slot)
 
static void free_unused_heaps (rb_objspace_t *objspace)
 
static void make_deferred (RVALUE *p)
 
static void make_io_deferred (RVALUE *p)
 
void Init_heap (void)
 
static VALUE objspace_each_objects (VALUE arg)
 
void rb_objspace_each_objects (each_obj_callback *callback, void *data)
 
static int internal_object_p (VALUE obj)
 
int rb_objspace_internal_object_p (VALUE obj)
 
static int os_obj_of_i (void *vstart, void *vend, size_t stride, void *data)
 
static VALUE os_obj_of (VALUE of)
 
static VALUE os_each_obj (int argc, VALUE *argv, VALUE os)
 
static VALUE undefine_final (VALUE os, VALUE obj)
 
static VALUE define_final (int argc, VALUE *argv, VALUE os)
 
void rb_gc_copy_finalizer (VALUE dest, VALUE obj)
 
static VALUE run_single_final (VALUE arg)
 
static void run_finalizer (rb_objspace_t *objspace, VALUE obj, VALUE table)
 
static void finalize_list (rb_objspace_t *objspace, RVALUE *p)
 
static void finalize_deferred (rb_objspace_t *objspace)
 
void rb_gc_finalize_deferred (void)
 
static int force_chain_object (st_data_t key, st_data_t val, st_data_t arg)
 
void rb_gc_call_finalizer_at_exit (void)
 
static int is_id_value (rb_objspace_t *objspace, VALUE ptr)
 
static int is_swept_object (rb_objspace_t *objspace, VALUE ptr)
 
static int is_dead_object (rb_objspace_t *objspace, VALUE ptr)
 
static int is_live_object (rb_objspace_t *objspace, VALUE ptr)
 
static VALUE id2ref (VALUE obj, VALUE objid)
 
VALUE rb_obj_id (VALUE obj)
 
static int set_zero (st_data_t key, st_data_t val, st_data_t arg)
 
static VALUE count_objects (int argc, VALUE *argv, VALUE os)
 
static void gc_clear_slot_bits (struct heaps_slot *slot)
 
static size_t objspace_live_num (rb_objspace_t *objspace)
 
static void slot_sweep (rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
 
static int ready_to_gc (rb_objspace_t *objspace)
 
static void before_gc_sweep (rb_objspace_t *objspace)
 
static void after_gc_sweep (rb_objspace_t *objspace)
 
static int lazy_sweep (rb_objspace_t *objspace)
 
static void gc_marks (rb_objspace_t *objspace)
 
static void gc_sweep (rb_objspace_t *objspace)
 
static void push_mark_stack (mark_stack_t *, VALUE)
 
static int pop_mark_stack (mark_stack_t *, VALUE *)
 
static void shrink_stack_chunk_cache (mark_stack_t *stack)
 
static stack_chunk_tstack_chunk_alloc (void)
 
static int is_mark_stask_empty (mark_stack_t *stack)
 
static void add_stack_chunk_cache (mark_stack_t *stack, stack_chunk_t *chunk)
 
static void push_mark_stack_chunk (mark_stack_t *stack)
 
static void pop_mark_stack_chunk (mark_stack_t *stack)
 
int ruby_get_stack_grow_direction (volatile VALUE *addr)
 
size_t ruby_stack_length (VALUE **p)
 
static int stack_check (int water_mark)
 
int ruby_stack_check (void)
 
static void mark_locations_array (rb_objspace_t *objspace, register VALUE *x, register long n)
 
static void gc_mark_locations (rb_objspace_t *objspace, VALUE *start, VALUE *end)
 
void rb_gc_mark_locations (VALUE *start, VALUE *end)
 
static int mark_entry (st_data_t key, st_data_t value, st_data_t data)
 
static int mark_key (st_data_t key, st_data_t value, st_data_t data)
 
static void mark_set (rb_objspace_t *objspace, st_table *tbl)
 
void rb_mark_set (st_table *tbl)
 
static int mark_keyvalue (st_data_t key, st_data_t value, st_data_t data)
 
static void mark_hash (rb_objspace_t *objspace, st_table *tbl)
 
void rb_mark_hash (st_table *tbl)
 
static void mark_method_entry (rb_objspace_t *objspace, const rb_method_entry_t *me)
 
void rb_mark_method_entry (const rb_method_entry_t *me)
 
static int mark_method_entry_i (ID key, const rb_method_entry_t *me, st_data_t data)
 
static void mark_m_tbl (rb_objspace_t *objspace, st_table *tbl)
 
static int mark_const_entry_i (ID key, const rb_const_entry_t *ce, st_data_t data)
 
static void mark_const_tbl (rb_objspace_t *objspace, st_table *tbl)
 
static void mark_current_machine_context (rb_objspace_t *objspace, rb_thread_t *th)
 
void rb_gc_mark_machine_stack (rb_thread_t *th)
 
void rb_mark_tbl (st_table *tbl)
 
void rb_gc_mark_maybe (VALUE obj)
 
static int gc_mark_ptr (rb_objspace_t *objspace, VALUE ptr)
 
static int markable_object_p (rb_objspace_t *objspace, VALUE ptr)
 
int rb_objspace_markable_object_p (VALUE obj)
 
void rb_gc_mark (VALUE ptr)
 
void rb_gc_force_recycle (VALUE p)
 
void rb_gc_register_mark_object (VALUE obj)
 
void rb_gc_register_address (VALUE *addr)
 
void rb_gc_unregister_address (VALUE *addr)
 
static void * gc_with_gvl (void *ptr)
 
static int garbage_collect_with_gvl (rb_objspace_t *objspace)
 
int rb_garbage_collect (void)
 
void Init_stack (volatile VALUE *addr)
 
VALUE rb_gc_start (void)
 
void rb_gc (void)
 
int rb_during_gc (void)
 
static VALUE gc_count (VALUE self)
 
static VALUE gc_stat (int argc, VALUE *argv, VALUE self)
 
static VALUE gc_stress_get (VALUE self)
 
static VALUE gc_stress_set (VALUE self, VALUE flag)
 
VALUE rb_gc_enable (void)
 
VALUE rb_gc_disable (void)
 
void rb_gc_set_params (void)
 
void rb_objspace_reachable_objects_from (VALUE obj, void(func)(VALUE, void *), void *data)
 
static void vm_xfree (rb_objspace_t *objspace, void *ptr)
 
static void * negative_size_allocation_error_with_gvl (void *ptr)
 
static void * ruby_memerror_body (void *dummy)
 
static void ruby_memerror (void)
 
void rb_memerror (void)
 
static size_t vm_malloc_prepare (rb_objspace_t *objspace, size_t size)
 
static void * vm_malloc_fixup (rb_objspace_t *objspace, void *mem, size_t size)
 
static void * vm_xmalloc (rb_objspace_t *objspace, size_t size)
 
static void * vm_xrealloc (rb_objspace_t *objspace, void *ptr, size_t size)
 
void * ruby_xmalloc (size_t size)
 
static size_t xmalloc2_size (size_t n, size_t size)
 
void * ruby_xmalloc2 (size_t n, size_t size)
 
static void * vm_xcalloc (rb_objspace_t *objspace, size_t count, size_t elsize)
 
void * ruby_xcalloc (size_t n, size_t size)
 
void * ruby_xrealloc (void *ptr, size_t size)
 
void * ruby_xrealloc2 (void *ptr, size_t n, size_t size)
 
void ruby_xfree (void *x)
 
void * ruby_mimmalloc (size_t size)
 
static int wmap_mark_map (st_data_t key, st_data_t val, st_data_t arg)
 
static void wmap_mark (void *ptr)
 
static int wmap_free_map (st_data_t key, st_data_t val, st_data_t arg)
 
static void wmap_free (void *ptr)
 
size_t rb_ary_memsize (VALUE ary)
 
static int wmap_memsize_map (st_data_t key, st_data_t val, st_data_t arg)
 
static size_t wmap_memsize (const void *ptr)
 
static VALUE wmap_allocate (VALUE klass)
 
static int wmap_final_func (st_data_t *key, st_data_t *value, st_data_t arg, int existing)
 
static VALUE wmap_finalize (VALUE self, VALUE objid)
 
static VALUE wmap_aset (VALUE self, VALUE wmap, VALUE orig)
 
static VALUE wmap_aref (VALUE self, VALUE wmap)
 
static void gc_prof_set_heap_info (rb_objspace_t *, gc_profile_record *)
 
static VALUE gc_profile_clear (void)
 
static VALUE gc_profile_record_get (void)
 
static void gc_profile_dump_on (VALUE out, VALUE(*append)(VALUE, VALUE))
 
static VALUE gc_profile_result (void)
 
static VALUE gc_profile_report (int argc, VALUE *argv, VALUE self)
 
static VALUE gc_profile_total_time (VALUE self)
 
static VALUE gc_profile_enable_get (VALUE self)
 
static VALUE gc_profile_enable (void)
 
static VALUE gc_profile_disable (void)
 
void Init_GC (void)
 

Variables

static ruby_gc_params_t initial_params
 
int * ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress
 
int ruby_gc_debug_indent = 0
 
VALUE rb_mGC
 
st_tablerb_class_tbl
 
int ruby_disable_gc_stress = 0
 
int ruby_stack_grow_direction
 
static const rb_data_type_t weakmap_type
 

Macro Definition Documentation

◆ BITMAP_INDEX

#define BITMAP_INDEX (   p)    (NUM_IN_SLOT(p) / (sizeof(uintptr_t) * CHAR_BIT))

Definition at line 313 of file gc.c.

◆ BITMAP_OFFSET

#define BITMAP_OFFSET (   p)    (NUM_IN_SLOT(p) & ((sizeof(uintptr_t) * CHAR_BIT)-1))

Definition at line 314 of file gc.c.

◆ CALC_EXACT_MALLOC_SIZE

#define CALC_EXACT_MALLOC_SIZE   0

Definition at line 205 of file gc.c.

◆ CEILDIV

#define CEILDIV (   i,
  mod 
)    (((i) + (mod) - 1)/(mod))

Definition at line 322 of file gc.c.

◆ COUNT_TYPE

#define COUNT_TYPE (   t)    case (t): type = ID2SYM(rb_intern(#t)); break;

Referenced by count_objects().

◆ deferred_final_list

#define deferred_final_list   objspace->final.deferred

Definition at line 285 of file gc.c.

Referenced by finalize_deferred(), rb_objspace_call_finalizer(), and slot_sweep().

◆ dont_gc

#define dont_gc   objspace->flags.dont_gc

Definition at line 281 of file gc.c.

Referenced by garbage_collect_with_gvl(), newobj(), rb_gc_disable(), rb_gc_enable(), and ready_to_gc().

◆ during_gc

#define during_gc   objspace->flags.during_gc

◆ finalizer_table

#define finalizer_table   objspace->final.table

◆ finalizing

#define finalizing   objspace->flags.finalizing

Definition at line 283 of file gc.c.

Referenced by rb_gc(), rb_gc_finalize_deferred(), rb_objspace_call_finalizer(), and slot_sweep().

◆ FREE_MIN

#define FREE_MIN   4096

Definition at line 73 of file gc.c.

◆ GC_MALLOC_LIMIT

#define GC_MALLOC_LIMIT   8000000

Definition at line 70 of file gc.c.

◆ GC_NOTIFY

#define GC_NOTIFY   0

Definition at line 3023 of file gc.c.

Referenced by garbage_collect().

◆ GC_PROFILE_MORE_DETAIL

#define GC_PROFILE_MORE_DETAIL   0

Definition at line 96 of file gc.c.

◆ GC_PROFILE_RECORD_DEFAULT_SIZE

#define GC_PROFILE_RECORD_DEFAULT_SIZE   100

Definition at line 3880 of file gc.c.

Referenced by gc_prof_timer_start(), and gc_profile_clear().

◆ GET_HEAP_BITMAP

#define GET_HEAP_BITMAP (   x)    (GET_HEAP_HEADER(x)->bits)

Definition at line 311 of file gc.c.

Referenced by gc_mark_ptr(), is_dead_object(), rb_gc_force_recycle(), and slot_sweep().

◆ GET_HEAP_HEADER

#define GET_HEAP_HEADER (   x)    (HEAP_HEADER((uintptr_t)(x) & ~(HEAP_ALIGN_MASK)))

Definition at line 309 of file gc.c.

◆ GET_HEAP_SLOT

#define GET_HEAP_SLOT (   x)    (GET_HEAP_HEADER(x)->base)

Definition at line 310 of file gc.c.

Referenced by add_slot_local_freelist().

◆ GET_STACK_BOUNDS

#define GET_STACK_BOUNDS (   start,
  end,
  appendix 
)
Value:
((start) = STACK_END, (end) = STACK_START) : ((start) = STACK_START, (end) = STACK_END+(appendix)))
#define STACK_START
Definition: gc.c:2254
#define STACK_END
Definition: gc.c:2255

Definition at line 2494 of file gc.c.

Referenced by mark_current_machine_context(), and rb_gc_mark_machine_stack().

◆ global_List

#define global_List   objspace->global_list

Definition at line 286 of file gc.c.

Referenced by gc_marks(), rb_gc_register_address(), rb_gc_unregister_address(), and rb_objspace_free().

◆ has_free_object

#define has_free_object   (objspace->heap.free_slots && objspace->heap.free_slots->freelist)

Definition at line 306 of file gc.c.

Referenced by gc_prepare_free_objects(), lazy_sweep(), newobj(), and ready_to_gc().

◆ HEAP_ALIGN_LOG

#define HEAP_ALIGN_LOG   14

Definition at line 319 of file gc.c.

◆ HEAP_HEADER

#define HEAP_HEADER (   p)    ((struct heaps_header *)(p))

Definition at line 308 of file gc.c.

◆ HEAP_MIN_SLOTS

#define HEAP_MIN_SLOTS   10000

Definition at line 72 of file gc.c.

Referenced by init_heap().

◆ heaps

#define heaps   objspace->heap.ptr

◆ heaps_freed

#define heaps_freed   objspace->heap.freed

Definition at line 280 of file gc.c.

Referenced by free_unused_heaps().

◆ heaps_inc

#define heaps_inc   objspace->heap.increment

Definition at line 279 of file gc.c.

Referenced by add_heap_slots(), heaps_increment(), and set_heaps_increment().

◆ heaps_length

#define heaps_length   objspace->heap.length

Definition at line 275 of file gc.c.

Referenced by add_heap_slots(), and set_heaps_increment().

◆ heaps_used

#define heaps_used   objspace->heap.used

◆ himem

#define himem   objspace->heap.range[1]

Definition at line 278 of file gc.c.

Referenced by assign_heap_slot(), and is_pointer_to_heap().

◆ initial_free_min

#define initial_free_min   initial_params.initial_free_min

Definition at line 290 of file gc.c.

Referenced by before_gc_sweep(), and rb_gc_set_params().

◆ initial_heap_min_slots

#define initial_heap_min_slots   initial_params.initial_heap_min_slots

Definition at line 289 of file gc.c.

Referenced by initial_expand_heap(), and rb_gc_set_params().

◆ initial_malloc_limit

#define initial_malloc_limit   initial_params.initial_malloc_limit

Definition at line 288 of file gc.c.

Referenced by after_gc_sweep(), rb_gc_set_params(), and rb_objspace_alloc().

◆ is_lazy_sweeping

#define is_lazy_sweeping (   objspace)    ((objspace)->heap.sweep_slots != 0)

Definition at line 292 of file gc.c.

Referenced by is_dead_object().

◆ lomem

#define lomem   objspace->heap.range[0]

Definition at line 277 of file gc.c.

Referenced by assign_heap_slot().

◆ malloc_increase

#define malloc_increase   objspace->malloc_params.increase

Definition at line 273 of file gc.c.

Referenced by after_gc_sweep(), vm_malloc_fixup(), vm_malloc_prepare(), and vm_xrealloc().

◆ malloc_limit

#define malloc_limit   objspace->malloc_params.limit

Definition at line 272 of file gc.c.

Referenced by after_gc_sweep(), rb_objspace_alloc(), and vm_malloc_prepare().

◆ MARK_IN_BITMAP

#define MARK_IN_BITMAP (   bits,
  p 
)    (bits[BITMAP_INDEX(p)] = bits[BITMAP_INDEX(p)] | ((uintptr_t)1 << BITMAP_OFFSET(p)))

Definition at line 2245 of file gc.c.

Referenced by gc_mark_ptr().

◆ MARKED_IN_BITMAP

#define MARKED_IN_BITMAP (   bits,
  p 
)    (bits[BITMAP_INDEX(p)] & ((uintptr_t)1 << BITMAP_OFFSET(p)))

Definition at line 315 of file gc.c.

Referenced by gc_mark_ptr(), is_dead_object(), rb_gc_force_recycle(), and slot_sweep().

◆ nomem_error

#define nomem_error   GET_VM()->special_exceptions[ruby_error_nomemory]

Definition at line 93 of file gc.c.

Referenced by Init_GC(), and rb_memerror().

◆ nonspecial_obj_id

#define nonspecial_obj_id (   obj)    (VALUE)((SIGNED_VALUE)(obj)|FIXNUM_FLAG)

Definition at line 295 of file gc.c.

Referenced by rb_obj_id(), run_finalizer(), and wmap_aset().

◆ NUM2PTR

#define NUM2PTR (   x)    NUM2ULONG(x)

Referenced by id2ref().

◆ NUM_IN_SLOT

#define NUM_IN_SLOT (   p)    (((uintptr_t)(p) & HEAP_ALIGN_MASK)/sizeof(RVALUE))

Definition at line 312 of file gc.c.

◆ numberof

#define numberof (   array)    (int)(sizeof(array) / sizeof((array)[0]))

Definition at line 2499 of file gc.c.

Referenced by mark_current_machine_context().

◆ obj_id_to_ref

#define obj_id_to_ref (   objid)    ((objid) ^ FIXNUM_FLAG) /* unset FIXNUM_FLAG */

Definition at line 296 of file gc.c.

Referenced by id2ref(), and wmap_finalize().

◆ RANY

#define RANY (   o)    ((RVALUE*)(o))

◆ rb_gc_mark_locations

#define rb_gc_mark_locations (   start,
  end 
)    gc_mark_locations(objspace, (start), (end))

◆ rb_jmp_buf

#define rb_jmp_buf   rb_jmpbuf_t

Definition at line 67 of file gc.c.

Referenced by mark_current_machine_context().

◆ rb_objspace

#define rb_objspace   (*GET_VM()->objspace)

◆ rb_setjmp

#define rb_setjmp (   env)    RUBY_SETJMP(env)

Definition at line 66 of file gc.c.

Referenced by mark_current_machine_context().

◆ ruby_gc_stress

#define ruby_gc_stress   objspace->gc_stress

◆ ruby_initial_gc_stress

#define ruby_initial_gc_stress   initial_params.gc_stress

Definition at line 266 of file gc.c.

Referenced by rb_objspace_alloc().

◆ SET_STACK_END

#define SET_STACK_END   SET_MACHINE_STACK_END(&th->machine_stack_end)

Definition at line 2251 of file gc.c.

Referenced by gc_marks(), mark_current_machine_context(), ruby_stack_length(), and stack_check().

◆ STACK_CHUNK_SIZE

#define STACK_CHUNK_SIZE   500

Definition at line 188 of file gc.c.

Referenced by init_mark_stack().

◆ STACK_END

#define STACK_END   (th->machine_stack_end)

Definition at line 2255 of file gc.c.

Referenced by mark_current_machine_context(), and ruby_stack_length().

◆ STACK_LENGTH

#define STACK_LENGTH
Value:
: (size_t)(STACK_END - STACK_START + 1))
#define STACK_START
Definition: gc.c:2254
#define STACK_END
Definition: gc.c:2255

Definition at line 2263 of file gc.c.

Referenced by ruby_stack_length(), and stack_check().

◆ STACK_LEVEL_MAX

#define STACK_LEVEL_MAX   (th->machine_stack_maxsize/sizeof(VALUE))

Definition at line 2256 of file gc.c.

Referenced by stack_check().

◆ STACK_START

#define STACK_START   (th->machine_stack_start)

Definition at line 2254 of file gc.c.

Referenced by mark_current_machine_context(), and ruby_stack_length().

◆ STACKFRAME_FOR_CALL_CFUNC

#define STACKFRAME_FOR_CALL_CFUNC   512

Definition at line 2306 of file gc.c.

Referenced by ruby_stack_check().

◆ STR_ASSOC

#define STR_ASSOC   FL_USER3 /* copied from string.c */

◆ TRY_WITH_GC

#define TRY_WITH_GC (   alloc)
Value:
do { \
if (!(alloc) && \
(!garbage_collect_with_gvl(objspace) || \
!(alloc))) { \
ruby_memerror(); \
} \
} while (0)
static int garbage_collect_with_gvl(rb_objspace_t *objspace)
Definition: gc.c:3060

Definition at line 3509 of file gc.c.

Referenced by vm_xcalloc(), and vm_xmalloc().

◆ VALGRIND_MAKE_MEM_DEFINED

#define VALGRIND_MAKE_MEM_DEFINED (   p,
 
)    0

Definition at line 62 of file gc.c.

Referenced by mark_locations_array().

◆ VALGRIND_MAKE_MEM_UNDEFINED

#define VALGRIND_MAKE_MEM_UNDEFINED (   p,
 
)    0

Definition at line 63 of file gc.c.

Referenced by add_slot_local_freelist(), and slot_sweep().

Typedef Documentation

◆ each_obj_callback

typedef int each_obj_callback(void *, void *, size_t, void *)

Definition at line 1044 of file gc.c.

◆ gc_profile_record

◆ mark_stack_t

typedef struct mark_stack mark_stack_t

◆ rb_objspace_t

typedef struct rb_objspace rb_objspace_t

◆ RVALUE

typedef struct RVALUE RVALUE

◆ stack_chunk_t

typedef struct stack_chunk stack_chunk_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HEAP_ALIGN 
HEAP_ALIGN_MASK 
REQUIRED_SIZE_BY_MALLOC 
HEAP_SIZE 
HEAP_OBJ_LIMIT 
HEAP_BITMAP_LIMIT 

Definition at line 324 of file gc.c.

Function Documentation

◆ add_heap_slots()

static void add_heap_slots ( rb_objspace_t objspace,
size_t  add 
)
static

Definition at line 558 of file gc.c.

References add, allocate_sorted_heaps(), assign_heap_slot(), heaps_inc, heaps_length, heaps_used, and i.

Referenced by init_heap(), and initial_expand_heap().

◆ add_slot_local_freelist()

static struct heaps_slot* add_slot_local_freelist ( rb_objspace_t objspace,
RVALUE p 
)
inlinestatic

Definition at line 823 of file gc.c.

References heaps_slot::freelist, GET_HEAP_SLOT, p, and VALGRIND_MAKE_MEM_UNDEFINED.

Referenced by finalize_list(), and rb_gc_force_recycle().

◆ add_stack_chunk_cache()

static void add_stack_chunk_cache ( mark_stack_t stack,
stack_chunk_t chunk 
)
static

Definition at line 2135 of file gc.c.

References mark_stack::cache, mark_stack::cache_size, and stack_chunk::next.

Referenced by init_mark_stack(), and pop_mark_stack_chunk().

◆ after_gc_sweep()

static void after_gc_sweep ( rb_objspace_t objspace)
static

◆ aligned_free()

static void aligned_free ( void *  ptr)
static

Definition at line 3461 of file gc.c.

References free().

Referenced by assign_heap_slot(), free_unused_heaps(), and rb_objspace_free().

◆ aligned_malloc()

static void * aligned_malloc ( size_t  alignment,
size_t  size 
)
static

Definition at line 3426 of file gc.c.

References assert, malloc, NULL, and size.

Referenced by assign_heap_slot().

◆ allocate_sorted_heaps()

static void allocate_sorted_heaps ( rb_objspace_t objspace,
size_t  next_heaps_length 
)
static

◆ assign_heap_slot()

static void assign_heap_slot ( rb_objspace_t objspace)
static

◆ before_gc_sweep()

static void before_gc_sweep ( rb_objspace_t objspace)
static

◆ count_objects()

static VALUE count_objects ( int  argc,
VALUE argv,
VALUE  os 
)
static

◆ define_final()

static VALUE define_final ( int  argc,
VALUE argv,
VALUE  os 
)
static

◆ define_final0()

static VALUE define_final0 ( VALUE  obj,
VALUE  block 
)
static

◆ finalize_deferred()

static void finalize_deferred ( rb_objspace_t objspace)
static

◆ finalize_list()

static void finalize_list ( rb_objspace_t objspace,
RVALUE p 
)
static

◆ force_chain_object()

static int force_chain_object ( st_data_t  key,
st_data_t  val,
st_data_t  arg 
)
static

◆ free_const_entry_i()

static int free_const_entry_i ( ID  key,
rb_const_entry_t ce,
st_data_t  data 
)
static

Definition at line 807 of file gc.c.

References ST_CONTINUE, and xfree().

Referenced by rb_free_const_table().

◆ free_method_entry_i()

static int free_method_entry_i ( ID  key,
rb_method_entry_t me,
st_data_t  data 
)
static

Definition at line 791 of file gc.c.

References rb_method_entry_struct::mark, rb_free_method_entry(), and ST_CONTINUE.

Referenced by rb_free_m_table().

◆ free_stack_chunks()

static void free_stack_chunks ( mark_stack_t stack)
static

Definition at line 2191 of file gc.c.

References mark_stack::chunk, free(), heaps_slot::next, stack_chunk::next, and NULL.

Referenced by rb_objspace_free().

◆ free_unused_heaps()

static void free_unused_heaps ( rb_objspace_t objspace)
static

◆ garbage_collect()

static int garbage_collect ( rb_objspace_t objspace)
static

◆ garbage_collect_with_gvl()

static int garbage_collect_with_gvl ( rb_objspace_t objspace)
static

◆ gc_clear_slot_bits()

static void gc_clear_slot_bits ( struct heaps_slot slot)
static

Definition at line 1870 of file gc.c.

References heaps_slot::bits, and HEAP_BITMAP_LIMIT.

Referenced by slot_sweep().

◆ gc_count()

static VALUE gc_count ( VALUE  self)
static

Definition at line 3136 of file gc.c.

References rb_objspace::count, and UINT2NUM.

Referenced by Init_GC().

◆ gc_mark()

static void gc_mark ( rb_objspace_t objspace,
VALUE  ptr 
)
static

◆ gc_mark_children()

static void gc_mark_children ( rb_objspace_t objspace,
VALUE  ptr 
)
static

Definition at line 2606 of file gc.c.

References RNode::args, args, RVALUE::as, BUILTIN_TYPE, RNode::cnt, FL_EXIVAR, FL_TEST, gc_mark(), gc_mark_ptr(), if(), is_pointer_to_heap(), LIKELY, rb_objspace::mark_func_data, mark_locations_array(), markable_object_p(), nd_type, RVALUE::node, RNode::node, NODE_ALIAS, NODE_ALLOCA, NODE_AND, NODE_ARGS, NODE_ARGS_AUX, NODE_ARGSCAT, NODE_ARRAY, NODE_BACK_REF, NODE_BLOCK, NODE_BLOCK_ARG, NODE_BLOCK_PASS, NODE_BREAK, NODE_CALL, NODE_CASE, NODE_CDECL, NODE_CLASS, NODE_COLON2, NODE_COLON3, NODE_CREF, NODE_CVAR, NODE_CVASGN, NODE_DASGN, NODE_DASGN_CURR, NODE_DEFINED, NODE_DEFN, NODE_DEFS, NODE_DOT2, NODE_DOT3, NODE_DREGX, NODE_DREGX_ONCE, NODE_DSTR, NODE_DVAR, NODE_DXSTR, NODE_ENSURE, NODE_ERRINFO, NODE_EVSTR, NODE_FALSE, NODE_FCALL, NODE_FLIP2, NODE_FLIP3, NODE_FOR, NODE_GASGN, NODE_GVAR, NODE_HASH, NODE_IASGN, NODE_IASGN2, NODE_IF, NODE_ITER, NODE_IVAR, NODE_LASGN, NODE_LIT, NODE_LVAR, NODE_MASGN, NODE_MATCH, NODE_MATCH2, NODE_MATCH3, NODE_MODULE, NODE_NEXT, NODE_NIL, NODE_NTH_REF, NODE_OP_ASGN1, NODE_OP_ASGN_AND, NODE_OP_ASGN_OR, NODE_OPT_ARG, NODE_OPT_N, NODE_OR, NODE_POSTEXE, NODE_REDO, NODE_RESBODY, NODE_RESCUE, NODE_RETRY, NODE_RETURN, NODE_SCLASS, NODE_SCOPE, NODE_SELF, NODE_SPLAT, NODE_STR, NODE_SUPER, NODE_TO_ARY, NODE_TRUE, NODE_UNDEF, NODE_UNTIL, NODE_VALIAS, NODE_VCALL, NODE_WHEN, NODE_WHILE, NODE_XSTR, NODE_YIELD, NODE_ZARRAY, NODE_ZSUPER, RANY, rb_bug(), rb_mark_generic_ivar(), T_FIXNUM, T_NIL, T_NODE, RNode::u1, RNode::u2, RNode::u3, and RNode::value.

Referenced by gc_mark_stacked_objects(), and rb_objspace_reachable_objects_from().

◆ gc_mark_locations()

static void gc_mark_locations ( rb_objspace_t objspace,
VALUE start,
VALUE end 
)
static

Definition at line 2333 of file gc.c.

References mark_locations_array().

Referenced by rb_gc_mark_locations().

◆ gc_mark_ptr()

static int gc_mark_ptr ( rb_objspace_t objspace,
VALUE  ptr 
)
static

◆ gc_mark_stacked_objects()

static void gc_mark_stacked_objects ( rb_objspace_t objspace)
static

◆ gc_marks()

static void gc_marks ( rb_objspace_t objspace)
static

◆ gc_prepare_free_objects()

static int gc_prepare_free_objects ( rb_objspace_t objspace)
static

◆ gc_prof_mark_timer_start()

static void gc_prof_mark_timer_start ( rb_objspace_t objspace)
inlinestatic

Definition at line 3980 of file gc.c.

References RUBY_DTRACE_GC_MARK_BEGIN, and RUBY_DTRACE_GC_MARK_BEGIN_ENABLED.

Referenced by gc_marks().

◆ gc_prof_mark_timer_stop()

static void gc_prof_mark_timer_stop ( rb_objspace_t objspace)
inlinestatic

Definition at line 3988 of file gc.c.

References RUBY_DTRACE_GC_MARK_END, and RUBY_DTRACE_GC_MARK_END_ENABLED.

Referenced by gc_marks().

◆ gc_prof_set_heap_info()

static void gc_prof_set_heap_info ( rb_objspace_t objspace,
gc_profile_record record 
)
inlinestatic

◆ gc_prof_set_malloc_info()

static void gc_prof_set_malloc_info ( rb_objspace_t objspace)
inlinestatic

Definition at line 4012 of file gc.c.

Referenced by after_gc_sweep(), and gc_prepare_free_objects().

◆ gc_prof_sweep_timer_start()

static void gc_prof_sweep_timer_start ( rb_objspace_t objspace)
inlinestatic

◆ gc_prof_sweep_timer_stop()

static void gc_prof_sweep_timer_stop ( rb_objspace_t objspace)
inlinestatic

Definition at line 4004 of file gc.c.

References RUBY_DTRACE_GC_SWEEP_END, and RUBY_DTRACE_GC_SWEEP_END_ENABLED.

Referenced by garbage_collect(), and gc_prepare_free_objects().

◆ gc_prof_timer_start()

static void gc_prof_timer_start ( rb_objspace_t objspace)
inlinestatic

◆ gc_prof_timer_stop()

static void gc_prof_timer_stop ( rb_objspace_t objspace,
int  marked 
)
inlinestatic

◆ gc_profile_clear()

static VALUE gc_profile_clear ( void  )
static

◆ gc_profile_disable()

static VALUE gc_profile_disable ( void  )
static

Definition at line 4376 of file gc.c.

References FALSE, rb_objspace::profile, Qnil, rb_objspace, and rb_objspace::run.

Referenced by Init_GC().

◆ gc_profile_dump_on()

static void gc_profile_dump_on ( VALUE  out,
VALUE(*)(VALUE, VALUE append 
)
static

◆ gc_profile_enable()

static VALUE gc_profile_enable ( void  )
static

Definition at line 4359 of file gc.c.

References rb_objspace::profile, Qnil, rb_objspace, rb_objspace::run, and TRUE.

Referenced by Init_GC().

◆ gc_profile_enable_get()

static VALUE gc_profile_enable_get ( VALUE  self)
static

Definition at line 4344 of file gc.c.

References rb_objspace::profile, Qfalse, Qtrue, rb_objspace, and rb_objspace::run.

Referenced by Init_GC().

◆ gc_profile_record_get()

static VALUE gc_profile_record_get ( void  )
static

◆ gc_profile_report()

static VALUE gc_profile_report ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 4299 of file gc.c.

References argc, argv, gc_profile_dump_on(), Qnil, rb_io_write(), rb_scan_args(), and rb_stdout.

Referenced by Init_GC().

◆ gc_profile_result()

static VALUE gc_profile_result ( void  )
static

Definition at line 4282 of file gc.c.

References gc_profile_dump_on(), rb_str_buf_append(), and rb_str_buf_new().

Referenced by Init_GC().

◆ gc_profile_total_time()

static VALUE gc_profile_total_time ( VALUE  self)
static

◆ gc_stat()

static VALUE gc_stat ( int  argc,
VALUE argv,
VALUE  self 
)
static

◆ gc_stress_get()

static VALUE gc_stress_get ( VALUE  self)
static

Definition at line 3222 of file gc.c.

References Qfalse, Qtrue, rb_objspace, and ruby_gc_stress.

Referenced by Init_GC().

◆ gc_stress_set()

static VALUE gc_stress_set ( VALUE  self,
VALUE  flag 
)
static

Definition at line 3241 of file gc.c.

References rb_objspace, rb_secure(), RTEST, and ruby_gc_stress.

Referenced by Init_GC().

◆ gc_sweep()

static void gc_sweep ( rb_objspace_t objspace)
static

◆ gc_with_gvl()

static void* gc_with_gvl ( void *  ptr)
static

Definition at line 3054 of file gc.c.

References garbage_collect().

Referenced by garbage_collect_with_gvl().

◆ getrusage_time()

static double getrusage_time ( void  )
static

◆ heaps_increment()

static int heaps_increment ( rb_objspace_t objspace)
static

Definition at line 624 of file gc.c.

References assign_heap_slot(), FALSE, heaps_inc, and TRUE.

Referenced by after_gc_sweep(), gc_prepare_free_objects(), lazy_sweep(), and ready_to_gc().

◆ id2ref()

static VALUE id2ref ( VALUE  obj,
VALUE  objid 
)
static

◆ Init_GC()

void Init_GC ( void  )

◆ init_heap()

static void init_heap ( rb_objspace_t objspace)
static

◆ Init_heap()

void Init_heap ( void  )

Definition at line 1039 of file gc.c.

References init_heap().

Referenced by ruby_setup().

◆ init_mark_stack()

static void init_mark_stack ( mark_stack_t stack)
static

◆ Init_stack()

void Init_stack ( volatile VALUE addr)

Definition at line 3087 of file gc.c.

References ruby_init_stack().

◆ initial_expand_heap()

static void initial_expand_heap ( rb_objspace_t objspace)
static

Definition at line 597 of file gc.c.

References add_heap_slots(), HEAP_OBJ_LIMIT, heaps_used, and initial_heap_min_slots.

Referenced by rb_gc_set_params().

◆ internal_object_p()

static int internal_object_p ( VALUE  obj)
static

Definition at line 1147 of file gc.c.

References BUILTIN_TYPE, FL_SINGLETON, FL_TEST, p, T_CLASS, T_ICLASS, T_NODE, T_NONE, and T_ZOMBIE.

Referenced by os_obj_of_i(), and rb_objspace_internal_object_p().

◆ is_dead_object()

static int is_dead_object ( rb_objspace_t objspace,
VALUE  ptr 
)
inlinestatic

Definition at line 1585 of file gc.c.

References FALSE, GET_HEAP_BITMAP, is_lazy_sweeping, is_swept_object(), MARKED_IN_BITMAP, and TRUE.

Referenced by is_live_object().

◆ is_id_value()

static int is_id_value ( rb_objspace_t objspace,
VALUE  ptr 
)
inlinestatic

Definition at line 1563 of file gc.c.

References BUILTIN_TYPE, FALSE, is_pointer_to_heap(), T_FIXNUM, T_ICLASS, and TRUE.

Referenced by id2ref(), and wmap_aref().

◆ is_live_object()

static int is_live_object ( rb_objspace_t objspace,
VALUE  ptr 
)
inlinestatic

Definition at line 1595 of file gc.c.

References BUILTIN_TYPE, FALSE, is_dead_object(), RBASIC, and TRUE.

Referenced by id2ref(), and wmap_aref().

◆ is_mark_stask_empty()

static int is_mark_stask_empty ( mark_stack_t stack)
inlinestatic

Definition at line 2129 of file gc.c.

References mark_stack::chunk, and NULL.

Referenced by pop_mark_stack().

◆ is_pointer_to_heap()

static int is_pointer_to_heap ( rb_objspace_t objspace,
void *  ptr 
)
inlinestatic

◆ is_swept_object()

static int is_swept_object ( rb_objspace_t objspace,
VALUE  ptr 
)
inlinestatic

◆ lazy_sweep()

static int lazy_sweep ( rb_objspace_t objspace)
static

◆ lazy_sweep_enable()

static VALUE lazy_sweep_enable ( void  )
static

Definition at line 1861 of file gc.c.

References rb_objspace::dont_lazy_sweep, FALSE, rb_objspace::flags, Qnil, and rb_objspace.

Referenced by rb_objspace_each_objects().

◆ link_free_heap_slot()

static void link_free_heap_slot ( rb_objspace_t objspace,
struct heaps_slot slot 
)
static

◆ make_deferred()

static void make_deferred ( RVALUE p)
inlinestatic

Definition at line 889 of file gc.c.

References p, T_MASK, and T_ZOMBIE.

Referenced by make_io_deferred(), obj_free(), and rb_objspace_call_finalizer().

◆ make_io_deferred()

static void make_io_deferred ( RVALUE p)
inlinestatic

Definition at line 895 of file gc.c.

References make_deferred(), p, and rb_io_fptr_finalize().

Referenced by obj_free(), and rb_objspace_call_finalizer().

◆ mark_const_entry_i()

static int mark_const_entry_i ( ID  key,
const rb_const_entry_t ce,
st_data_t  data 
)
static

◆ mark_const_tbl()

static void mark_const_tbl ( rb_objspace_t objspace,
st_table tbl 
)
static

Definition at line 2481 of file gc.c.

References mark_const_entry_i(), mark_tbl_arg::objspace, and st_foreach().

◆ mark_current_machine_context()

static void mark_current_machine_context ( rb_objspace_t objspace,
rb_thread_t th 
)
static

◆ mark_entry()

static int mark_entry ( st_data_t  key,
st_data_t  value,
st_data_t  data 
)
static

Definition at line 2355 of file gc.c.

References gc_mark(), mark_tbl_arg::objspace, and ST_CONTINUE.

Referenced by mark_tbl().

◆ mark_hash()

static void mark_hash ( rb_objspace_t objspace,
st_table tbl 
)
static

Definition at line 2404 of file gc.c.

References mark_keyvalue(), mark_tbl_arg::objspace, and st_foreach().

Referenced by rb_mark_hash().

◆ mark_key()

static int mark_key ( st_data_t  key,
st_data_t  value,
st_data_t  data 
)
static

Definition at line 2372 of file gc.c.

References gc_mark(), key, mark_tbl_arg::objspace, and ST_CONTINUE.

Referenced by mark_set().

◆ mark_keyvalue()

static int mark_keyvalue ( st_data_t  key,
st_data_t  value,
st_data_t  data 
)
static

Definition at line 2395 of file gc.c.

References gc_mark(), key, mark_tbl_arg::objspace, and ST_CONTINUE.

Referenced by mark_hash().

◆ mark_locations_array()

static void mark_locations_array ( rb_objspace_t objspace,
register VALUE x,
register long  n 
)
static

◆ mark_m_tbl()

static void mark_m_tbl ( rb_objspace_t objspace,
st_table tbl 
)
static

Definition at line 2463 of file gc.c.

References mark_method_entry_i(), mark_tbl_arg::objspace, and st_foreach().

◆ mark_method_entry()

static void mark_method_entry ( rb_objspace_t objspace,
const rb_method_entry_t me 
)
static

◆ mark_method_entry_i()

static int mark_method_entry_i ( ID  key,
const rb_method_entry_t me,
st_data_t  data 
)
static

Definition at line 2455 of file gc.c.

References mark_method_entry(), mark_tbl_arg::objspace, and ST_CONTINUE.

Referenced by mark_m_tbl().

◆ mark_set()

static void mark_set ( rb_objspace_t objspace,
st_table tbl 
)
static

Definition at line 2380 of file gc.c.

References mark_key(), mark_tbl_arg::objspace, and st_foreach().

Referenced by rb_mark_set().

◆ mark_tbl()

static void mark_tbl ( rb_objspace_t objspace,
st_table tbl 
)
static

Definition at line 2363 of file gc.c.

References mark_entry(), st_table::num_entries, mark_tbl_arg::objspace, and st_foreach().

Referenced by gc_marks(), and rb_mark_tbl().

◆ markable_object_p()

static int markable_object_p ( rb_objspace_t objspace,
VALUE  ptr 
)
static

◆ negative_size_allocation_error()

static void negative_size_allocation_error ( const char *  msg)
static

◆ negative_size_allocation_error_with_gvl()

static void* negative_size_allocation_error_with_gvl ( void *  ptr)
static

Definition at line 3359 of file gc.c.

References rb_eNoMemError, and rb_raise().

Referenced by negative_size_allocation_error().

◆ newobj()

static VALUE newobj ( VALUE  klass,
VALUE  flags 
)
static

◆ obj_free()

static int obj_free ( rb_objspace_t objspace,
VALUE  obj 
)
static

◆ objspace_each_objects()

static VALUE objspace_each_objects ( VALUE  arg)
static

◆ objspace_live_num()

static size_t objspace_live_num ( rb_objspace_t objspace)
static

◆ os_each_obj()

static VALUE os_each_obj ( int  argc,
VALUE argv,
VALUE  os 
)
static

Definition at line 1242 of file gc.c.

References argc, argv, os_each_struct::of, os_obj_of(), rb_scan_args(), rb_secure(), and RETURN_ENUMERATOR.

Referenced by Init_GC().

◆ os_obj_of()

static VALUE os_obj_of ( VALUE  of)
static

Definition at line 1195 of file gc.c.

References os_each_struct::num, os_each_struct::of, os_obj_of_i(), rb_objspace_each_objects(), and SIZET2NUM.

Referenced by os_each_obj().

◆ os_obj_of_i()

static int os_obj_of_i ( void *  vstart,
void *  vend,
size_t  stride,
void *  data 
)
static

Definition at line 1176 of file gc.c.

References internal_object_p(), os_each_struct::num, os_each_struct::of, p, rb_obj_is_kind_of(), rb_yield(), and v.

Referenced by os_obj_of().

◆ pop_mark_stack()

static int pop_mark_stack ( mark_stack_t stack,
VALUE data 
)
static

◆ pop_mark_stack_chunk()

static void pop_mark_stack_chunk ( mark_stack_t stack)
static

◆ push_mark_stack()

static void push_mark_stack ( mark_stack_t stack,
VALUE  data 
)
static

Definition at line 2205 of file gc.c.

References mark_stack::chunk, stack_chunk::data, mark_stack::index, mark_stack::limit, and push_mark_stack_chunk().

Referenced by gc_mark().

◆ push_mark_stack_chunk()

static void push_mark_stack_chunk ( mark_stack_t stack)
static

◆ rb_ary_memsize()

size_t rb_ary_memsize ( VALUE  ary)

Definition at line 479 of file array.c.

References ARY_OWNS_HEAP_P, and RARRAY.

Referenced by wmap_memsize_map().

◆ rb_data_object_alloc()

VALUE rb_data_object_alloc ( VALUE  klass,
void *  datap,
RUBY_DATA_FUNC  dmark,
RUBY_DATA_FUNC  dfree 
)

Definition at line 709 of file gc.c.

References Check_Type, NEWOBJ, OBJSETUP, T_CLASS, and T_DATA.

◆ rb_data_typed_object_alloc()

VALUE rb_data_typed_object_alloc ( VALUE  klass,
void *  datap,
const rb_data_type_t type 
)

Definition at line 722 of file gc.c.

References Check_Type, NEWOBJ, OBJSETUP, T_CLASS, T_DATA, and type.

Referenced by iow_newobj().

◆ rb_define_final()

VALUE rb_define_final ( VALUE  obj,
VALUE  block 
)

Definition at line 1338 of file gc.c.

References define_final0(), rb_check_frozen, rb_eArgError, rb_intern, rb_obj_classname(), rb_raise(), and rb_respond_to().

Referenced by wmap_aset().

◆ rb_during_gc()

int rb_during_gc ( void  )

Definition at line 3119 of file gc.c.

References during_gc, and rb_objspace.

◆ rb_free_const_table()

void rb_free_const_table ( st_table tbl)

Definition at line 814 of file gc.c.

References free_const_entry_i(), st_foreach(), and st_free_table().

Referenced by init_copy(), obj_free(), and rb_mod_init_copy().

◆ rb_free_m_table()

void rb_free_m_table ( st_table tbl)

Definition at line 800 of file gc.c.

References free_method_entry_i(), st_foreach(), and st_free_table().

Referenced by obj_free(), and rb_mod_init_copy().

◆ rb_garbage_collect()

int rb_garbage_collect ( void  )

Definition at line 3079 of file gc.c.

References garbage_collect().

◆ rb_gc()

void rb_gc ( void  )

◆ rb_gc_call_finalizer_at_exit()

void rb_gc_call_finalizer_at_exit ( void  )

Definition at line 1484 of file gc.c.

References rb_objspace_call_finalizer().

Referenced by ruby_finalize_1().

◆ rb_gc_copy_finalizer()

void rb_gc_copy_finalizer ( VALUE  dest,
VALUE  obj 
)

Definition at line 1349 of file gc.c.

References finalizer_table, FL_FINALIZE, FL_SET, FL_TEST, rb_objspace, st_insert(), and st_lookup().

Referenced by init_copy().

◆ rb_gc_disable()

VALUE rb_gc_disable ( void  )

◆ rb_gc_enable()

VALUE rb_gc_enable ( void  )

◆ rb_gc_finalize_deferred()

void rb_gc_finalize_deferred ( void  )

Definition at line 1457 of file gc.c.

References ATOMIC_EXCHANGE, ATOMIC_SET, finalize_deferred(), finalizing, and rb_objspace.

Referenced by rb_threadptr_execute_interrupts().

◆ rb_gc_force_recycle()

void rb_gc_force_recycle ( VALUE  p)

◆ rb_gc_mark()

void rb_gc_mark ( VALUE  ptr)

◆ rb_gc_mark_locations()

void rb_gc_mark_locations ( VALUE start,
VALUE end 
)

Definition at line 2343 of file gc.c.

References gc_mark_locations().

◆ rb_gc_mark_machine_stack()

void rb_gc_mark_machine_stack ( rb_thread_t th)

Definition at line 2530 of file gc.c.

References GET_STACK_BOUNDS, rb_gc_mark_locations, and rb_objspace.

Referenced by rb_thread_mark().

◆ rb_gc_mark_maybe()

void rb_gc_mark_maybe ( VALUE  obj)

Definition at line 2549 of file gc.c.

References gc_mark(), and is_pointer_to_heap().

Referenced by gc_marks(), JSON_mark(), mark_global_entry(), val_marker(), and var_marker().

◆ rb_gc_register_address()

void rb_gc_register_address ( VALUE addr)

Definition at line 2989 of file gc.c.

References ALLOC, global_List, gc_list::next, rb_objspace, and gc_list::varptr.

Referenced by Init_coverage(), Init_curses(), and rb_global_variable().

◆ rb_gc_register_mark_object()

void rb_gc_register_mark_object ( VALUE  obj)

◆ rb_gc_set_params()

void rb_gc_set_params ( void  )

◆ rb_gc_start()

VALUE rb_gc_start ( void  )

Definition at line 3103 of file gc.c.

References Qnil, and rb_gc().

Referenced by Init_GC().

◆ rb_gc_unregister_address()

void rb_gc_unregister_address ( VALUE addr)

Definition at line 3001 of file gc.c.

References global_List, gc_list::next, rb_objspace, gc_list::varptr, and xfree().

Referenced by curses_finalize().

◆ rb_global_variable()

void rb_global_variable ( VALUE var)

Definition at line 426 of file gc.c.

References rb_gc_register_address().

Referenced by Init_ossl_asn1(), Init_RandomSeed(), Init_Regexp(), Init_tcltklib(), and Init_tkutil().

◆ rb_mark_hash()

void rb_mark_hash ( st_table tbl)

Definition at line 2413 of file gc.c.

References mark_hash().

Referenced by Init_win32ole(), mark_dump_arg(), and mark_load_arg().

◆ rb_mark_method_entry()

void rb_mark_method_entry ( const rb_method_entry_t me)

Definition at line 2449 of file gc.c.

References mark_method_entry().

Referenced by bm_mark(), rb_gc_mark_unlinked_live_method_entries(), and rb_thread_mark().

◆ rb_mark_set()

void rb_mark_set ( st_table tbl)

Definition at line 2389 of file gc.c.

References mark_set().

Referenced by mark_dump_arg().

◆ rb_mark_tbl()

void rb_mark_tbl ( st_table tbl)

◆ rb_memerror()

void rb_memerror ( void  )

◆ rb_newobj()

VALUE rb_newobj ( void  )

Definition at line 677 of file gc.c.

References newobj(), and T_NONE.

Referenced by rb_node_newnode().

◆ rb_newobj_of()

VALUE rb_newobj_of ( VALUE  klass,
VALUE  flags 
)

Definition at line 683 of file gc.c.

References newobj(), and OBJSETUP.

◆ rb_node_newnode()

NODE* rb_node_newnode ( enum node_type  type,
VALUE  a0,
VALUE  a1,
VALUE  a2 
)

Definition at line 694 of file gc.c.

References RNode::flags, nd_set_type, rb_newobj(), T_NODE, type, RNode::u1, RNode::u2, RNode::u3, and RNode::value.

◆ rb_obj_id()

VALUE rb_obj_id ( VALUE  obj)

◆ rb_objspace_alloc()

rb_objspace_t* rb_objspace_alloc ( void  )

Definition at line 374 of file gc.c.

References initial_malloc_limit, malloc, malloc_limit, ruby_gc_stress, and ruby_initial_gc_stress.

Referenced by Init_BareVM().

◆ rb_objspace_call_finalizer()

static void rb_objspace_call_finalizer ( rb_objspace_t objspace)
static

◆ rb_objspace_data_type_memsize()

size_t rb_objspace_data_type_memsize ( VALUE  obj)

Definition at line 738 of file gc.c.

References RTYPEDDATA_DATA, RTYPEDDATA_P, and RTYPEDDATA_TYPE.

Referenced by memsize_of().

◆ rb_objspace_data_type_name()

const char* rb_objspace_data_type_name ( VALUE  obj)

Definition at line 749 of file gc.c.

References RTYPEDDATA_P, and RTYPEDDATA_TYPE.

Referenced by cto_i().

◆ rb_objspace_each_objects()

void rb_objspace_each_objects ( each_obj_callback callback,
void *  data 
)

◆ rb_objspace_free()

void rb_objspace_free ( rb_objspace_t objspace)

◆ rb_objspace_internal_object_p()

int rb_objspace_internal_object_p ( VALUE  obj)

Definition at line 1170 of file gc.c.

References internal_object_p().

Referenced by reachable_object_from_i().

◆ rb_objspace_markable_object_p()

int rb_objspace_markable_object_p ( VALUE  obj)

Definition at line 2578 of file gc.c.

References markable_object_p().

Referenced by reachable_object_from_i(), and reachable_objects_from().

◆ rb_objspace_reachable_objects_from()

void rb_objspace_reachable_objects_from ( VALUE  obj,
void(func)(VALUE, void *)  ,
void *  data 
)

◆ rb_undefine_final()

VALUE rb_undefine_final ( VALUE  obj)

Definition at line 1272 of file gc.c.

References finalizer_table, FL_FINALIZE, FL_UNSET, rb_check_frozen, rb_objspace, and st_delete().

Referenced by undefine_final().

◆ ready_to_gc()

static int ready_to_gc ( rb_objspace_t objspace)
static

◆ rest_sweep()

static void rest_sweep ( rb_objspace_t objspace)
static

◆ ruby_get_stack_grow_direction()

int ruby_get_stack_grow_direction ( volatile VALUE addr)

Definition at line 2269 of file gc.c.

References ruby_stack_grow_direction, and SET_MACHINE_STACK_END.

◆ ruby_memerror()

static void ruby_memerror ( void  )
static

◆ ruby_memerror_body()

static void* ruby_memerror_body ( void *  dummy)
static

Definition at line 3383 of file gc.c.

References rb_memerror().

Referenced by ruby_memerror().

◆ ruby_mimmalloc()

void* ruby_mimmalloc ( size_t  size)

Definition at line 3664 of file gc.c.

References malloc, and size.

Referenced by Init_BareVM().

◆ ruby_xcalloc()

void* ruby_xcalloc ( size_t  n,
size_t  size 
)

Definition at line 3631 of file gc.c.

References size, and vm_xcalloc().

Referenced by rb_iseq_defined_string().

◆ ruby_xfree()

void ruby_xfree ( void *  x)

◆ ruby_xmalloc()

void* ruby_xmalloc ( size_t  size)

Definition at line 3596 of file gc.c.

References size, and vm_xmalloc().

Referenced by bt_init(), rb_dl_malloc(), rb_dlptr_malloc(), rb_fiddle_malloc(), and rb_fiddle_ptr_malloc().

◆ ruby_xmalloc2()

void* ruby_xmalloc2 ( size_t  n,
size_t  size 
)

Definition at line 3612 of file gc.c.

References size, vm_xmalloc(), and xmalloc2_size().

◆ ruby_xrealloc()

void* ruby_xrealloc ( void *  ptr,
size_t  size 
)

◆ ruby_xrealloc2()

void* ruby_xrealloc2 ( void *  ptr,
size_t  n,
size_t  size 
)

Definition at line 3643 of file gc.c.

References rb_eArgError, rb_raise(), ruby_xrealloc(), and size.

◆ run_final()

static void run_final ( rb_objspace_t objspace,
VALUE  obj 
)
static

◆ run_finalizer()

static void run_finalizer ( rb_objspace_t objspace,
VALUE  obj,
VALUE  table 
)
static

◆ run_single_final()

static VALUE run_single_final ( VALUE  arg)
static

Definition at line 1364 of file gc.c.

References args, Qnil, and rb_eval_cmd().

Referenced by run_finalizer().

◆ set_heaps_increment()

static void set_heaps_increment ( rb_objspace_t objspace)
static

Definition at line 607 of file gc.c.

References allocate_sorted_heaps(), heaps_inc, heaps_length, and heaps_used.

Referenced by after_gc_sweep(), gc_prepare_free_objects(), and ready_to_gc().

◆ set_zero()

static int set_zero ( st_data_t  key,
st_data_t  val,
st_data_t  arg 
)
static

Definition at line 1737 of file gc.c.

References hash(), INT2FIX, key, rb_hash_aset(), and ST_CONTINUE.

Referenced by count_objects().

◆ shrink_stack_chunk_cache()

static void shrink_stack_chunk_cache ( mark_stack_t stack)
static

◆ slot_sweep()

static void slot_sweep ( rb_objspace_t objspace,
struct heaps_slot sweep_slot 
)
static

◆ stack_check()

static int stack_check ( int  water_mark)
static

Definition at line 2290 of file gc.c.

References GET_THREAD(), SET_STACK_END, STACK_LENGTH, and STACK_LEVEL_MAX.

Referenced by ruby_stack_check().

◆ stack_chunk_alloc()

static stack_chunk_t* stack_chunk_alloc ( void  )
static

Definition at line 2117 of file gc.c.

References malloc, and rb_memerror().

Referenced by init_mark_stack(), and push_mark_stack_chunk().

◆ undefine_final()

static VALUE undefine_final ( VALUE  os,
VALUE  obj 
)
static

Definition at line 1266 of file gc.c.

References rb_undefine_final().

Referenced by Init_GC().

◆ unlink_free_heap_slot()

static void unlink_free_heap_slot ( rb_objspace_t objspace,
struct heaps_slot slot 
)
static

Definition at line 474 of file gc.c.

References heaps_slot::free_next, rb_objspace::free_slots, rb_objspace::heap, and NULL.

Referenced by newobj().

◆ unlink_heap_slot()

static void unlink_heap_slot ( rb_objspace_t objspace,
struct heaps_slot slot 
)
static

Definition at line 837 of file gc.c.

References rb_objspace::heap, heaps, heaps_slot::next, NULL, heaps_slot::prev, and rb_objspace::sweep_slots.

Referenced by slot_sweep().

◆ vm_malloc_fixup()

static void* vm_malloc_fixup ( rb_objspace_t objspace,
void *  mem,
size_t  size 
)
inlinestatic

Definition at line 3495 of file gc.c.

References ATOMIC_SIZE_ADD, ATOMIC_SIZE_INC, malloc_increase, rb_objspace::malloc_params, and size.

Referenced by vm_xcalloc(), and vm_xmalloc().

◆ vm_malloc_prepare()

static size_t vm_malloc_prepare ( rb_objspace_t objspace,
size_t  size 
)
inlinestatic

◆ vm_xcalloc()

static void* vm_xcalloc ( rb_objspace_t objspace,
size_t  count,
size_t  elsize 
)
static

Definition at line 3618 of file gc.c.

References calloc, count, size, TRY_WITH_GC, vm_malloc_fixup(), vm_malloc_prepare(), and xmalloc2_size().

Referenced by ruby_xcalloc().

◆ vm_xfree()

static void vm_xfree ( rb_objspace_t objspace,
void *  ptr 
)
static

Definition at line 3580 of file gc.c.

References ATOMIC_SIZE_DEC, ATOMIC_SIZE_SUB, free(), rb_objspace::malloc_params, and size.

Referenced by ruby_xfree(), and vm_xrealloc().

◆ vm_xmalloc()

static void* vm_xmalloc ( rb_objspace_t objspace,
size_t  size 
)
static

Definition at line 3518 of file gc.c.

References malloc, size, TRY_WITH_GC, vm_malloc_fixup(), and vm_malloc_prepare().

Referenced by ruby_xmalloc(), ruby_xmalloc2(), and vm_xrealloc().

◆ vm_xrealloc()

static void* vm_xrealloc ( rb_objspace_t objspace,
void *  ptr,
size_t  size 
)
static

◆ wmap_allocate()

static VALUE wmap_allocate ( VALUE  klass)
static

◆ wmap_aref()

static VALUE wmap_aref ( VALUE  self,
VALUE  wmap 
)
static

◆ wmap_aset()

static VALUE wmap_aset ( VALUE  self,
VALUE  wmap,
VALUE  orig 
)
static

◆ wmap_final_func()

static int wmap_final_func ( st_data_t key,
st_data_t value,
st_data_t  arg,
int  existing 
)
static

Definition at line 3794 of file gc.c.

References RARRAY_LEN, rb_ary_delete_same(), ST_CONTINUE, ST_DELETE, and ST_STOP.

Referenced by wmap_finalize().

◆ wmap_finalize()

static VALUE wmap_finalize ( VALUE  self,
VALUE  objid 
)
static

◆ wmap_free()

static void wmap_free ( void *  ptr)
static

Definition at line 3744 of file gc.c.

References weakmap::obj2wmap, st_foreach(), st_free_table(), weakmap::wmap2obj, and wmap_free_map().

◆ wmap_free_map()

static int wmap_free_map ( st_data_t  key,
st_data_t  val,
st_data_t  arg 
)
static

Definition at line 3737 of file gc.c.

References rb_ary_resize(), ST_CONTINUE, and val.

Referenced by wmap_free().

◆ wmap_mark()

static void wmap_mark ( void *  ptr)
static

Definition at line 3729 of file gc.c.

References weakmap::final, weakmap::obj2wmap, rb_gc_mark(), st_foreach(), and wmap_mark_map().

◆ wmap_mark_map()

static int wmap_mark_map ( st_data_t  key,
st_data_t  val,
st_data_t  arg 
)
static

Definition at line 3722 of file gc.c.

References gc_mark_ptr(), ST_CONTINUE, and val.

Referenced by wmap_mark().

◆ wmap_memsize()

static size_t wmap_memsize ( const void *  ptr)
static

◆ wmap_memsize_map()

static int wmap_memsize_map ( st_data_t  key,
st_data_t  val,
st_data_t  arg 
)
static

Definition at line 3754 of file gc.c.

References rb_ary_memsize(), ST_CONTINUE, and val.

Referenced by wmap_memsize().

◆ xmalloc2_size()

static size_t xmalloc2_size ( size_t  n,
size_t  size 
)
inlinestatic

Definition at line 3602 of file gc.c.

References rb_eArgError, rb_raise(), and size.

Referenced by ruby_xmalloc2(), and vm_xcalloc().

Variable Documentation

◆ initial_params

ruby_gc_params_t initial_params
static
Initial value:
= {
}
#define FALSE
Definition: nkf.h:174
#define GC_MALLOC_LIMIT
Definition: gc.c:70
#define FREE_MIN
Definition: gc.c:73
#define HEAP_MIN_SLOTS
Definition: gc.c:72

Definition at line 84 of file gc.c.

◆ rb_mGC

VALUE rb_mGC

Definition at line 334 of file gc.c.

Referenced by Init_GC().

◆ ruby_disable_gc_stress

int ruby_disable_gc_stress = 0

Definition at line 336 of file gc.c.

Referenced by newobj(), vm_malloc_prepare(), and vm_xrealloc().

◆ ruby_gc_debug_indent

int ruby_gc_debug_indent = 0

Definition at line 333 of file gc.c.

◆ ruby_initial_gc_stress_ptr

int* ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress

Definition at line 267 of file gc.c.

Referenced by set_debug_option().

◆ ruby_stack_grow_direction

int ruby_stack_grow_direction

Definition at line 2267 of file gc.c.

Referenced by ruby_get_stack_grow_direction().

◆ weakmap_type

const rb_data_type_t weakmap_type
static
Initial value:
= {
"weakmap",
{
}
}
static void wmap_mark(void *ptr)
Definition: gc.c:3729
static size_t wmap_memsize(const void *ptr)
Definition: gc.c:3761
static void wmap_free(void *ptr)
Definition: gc.c:3744

Definition at line 3773 of file gc.c.

Referenced by wmap_allocate(), wmap_aref(), wmap_aset(), and wmap_finalize().