w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gc.c File Reference
#include <string.h>
#include <stdlib.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/class.h>
#include <mruby/data.h>
#include <mruby/istruct.h>
#include <mruby/hash.h>
#include <mruby/proc.h>
#include <mruby/range.h>
#include <mruby/variable.h>
#include <mruby/gc.h>
#include <mruby/error.h>
#include <mruby/throw.h>
#include <mruby/presym.h>
Include dependency graph for gc.c:

Go to the source code of this file.

Classes

struct  free_obj
 
struct  RVALUE_initializer
 
struct  RVALUE
 

Macros

#define GC_INVOKE_TIME_REPORT(s)
 
#define GC_TIME_START
 
#define GC_TIME_STOP_AND_REPORT
 
#define DEBUG(x)
 
#define MRB_HEAP_PAGE_SIZE   1024
 
#define GC_STEP_SIZE   1024
 
#define GC_GRAY   0
 
#define GC_WHITE_A   1
 
#define GC_WHITE_B   (1 << 1)
 
#define GC_BLACK   (1 << 2)
 
#define GC_RED   7
 
#define GC_WHITES   (GC_WHITE_A | GC_WHITE_B)
 
#define GC_COLOR_MASK   7
 
#define paint_gray(o)   ((o)->color = GC_GRAY)
 
#define paint_black(o)   ((o)->color = GC_BLACK)
 
#define paint_white(o)   ((o)->color = GC_WHITES)
 
#define paint_partial_white(s, o)   ((o)->color = (s)->current_white_part)
 
#define is_gray(o)   ((o)->color == GC_GRAY)
 
#define is_white(o)   ((o)->color & GC_WHITES)
 
#define is_black(o)   ((o)->color == GC_BLACK)
 
#define is_red(o)   ((o)->color == GC_RED)
 
#define flip_white_part(s)   ((s)->current_white_part = other_white_part(s))
 
#define other_white_part(s)   ((s)->current_white_part ^ GC_WHITES)
 
#define is_dead(s, o)   (((o)->color & other_white_part(s) & GC_WHITES) || (o)->tt == MRB_TT_FREE)
 
#define objects(p)   ((RVALUE *)p->objects)
 
#define DEFAULT_GC_INTERVAL_RATIO   200
 
#define DEFAULT_GC_STEP_RATIO   200
 
#define MAJOR_GC_INC_RATIO   120
 
#define MAJOR_GC_TOOMANY   10000
 
#define is_generational(gc)   ((gc)->generational)
 
#define is_major_gc(gc)   (is_generational(gc) && (gc)->full)
 
#define is_minor_gc(gc)   (is_generational(gc) && !(gc)->full)
 
#define GC_ROOT_SYM   MRB_SYM(_gc_root_)
 

Functions

void mrb_raise_nomemory (mrb_state *mrb)
 
voidmrb_realloc_simple (mrb_state *mrb, void *p, size_t len)
 
voidmrb_realloc (mrb_state *mrb, void *p, size_t len)
 
voidmrb_malloc (mrb_state *mrb, size_t len)
 
voidmrb_malloc_simple (mrb_state *mrb, size_t len)
 
voidmrb_calloc (mrb_state *mrb, size_t nelem, size_t len)
 
void mrb_free (mrb_state *mrb, void *p)
 
voidmrb_alloca (mrb_state *mrb, size_t size)
 
static mrb_bool heap_p (mrb_gc *gc, struct RBasic *object)
 
mrb_bool mrb_object_dead_p (mrb_state *mrb, struct RBasic *object)
 
static void link_heap_page (mrb_gc *gc, mrb_heap_page *page)
 
static void unlink_heap_page (mrb_gc *gc, mrb_heap_page *page)
 
static void link_free_heap_page (mrb_gc *gc, mrb_heap_page *page)
 
static void unlink_free_heap_page (mrb_gc *gc, mrb_heap_page *page)
 
static void add_heap (mrb_state *mrb, mrb_gc *gc)
 
void mrb_gc_init (mrb_state *mrb, mrb_gc *gc)
 
static void obj_free (mrb_state *mrb, struct RBasic *obj, int end)
 
static void free_heap (mrb_state *mrb, mrb_gc *gc)
 
void mrb_gc_destroy (mrb_state *mrb, mrb_gc *gc)
 
static void gc_protect (mrb_state *mrb, mrb_gc *gc, struct RBasic *p)
 
void mrb_gc_protect (mrb_state *mrb, mrb_value obj)
 
void mrb_gc_register (mrb_state *mrb, mrb_value obj)
 
void mrb_gc_unregister (mrb_state *mrb, mrb_value obj)
 
struct RBasicmrb_obj_alloc (mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
 
static void add_gray_list (mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
 
static mrb_int ci_nregs (mrb_callinfo *ci)
 
static void mark_context_stack (mrb_state *mrb, struct mrb_context *c)
 
static void mark_context (mrb_state *mrb, struct mrb_context *c)
 
static void gc_mark_children (mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
 
void mrb_gc_mark (mrb_state *mrb, struct RBasic *obj)
 
static void root_scan_phase (mrb_state *mrb, mrb_gc *gc)
 
static size_t gc_gray_counts (mrb_state *mrb, mrb_gc *gc, struct RBasic *obj)
 
static void gc_mark_gray_list (mrb_state *mrb, mrb_gc *gc)
 
static size_t incremental_marking_phase (mrb_state *mrb, mrb_gc *gc, size_t limit)
 
static void final_marking_phase (mrb_state *mrb, mrb_gc *gc)
 
static void prepare_incremental_sweep (mrb_state *mrb, mrb_gc *gc)
 
static size_t incremental_sweep_phase (mrb_state *mrb, mrb_gc *gc, size_t limit)
 
static size_t incremental_gc (mrb_state *mrb, mrb_gc *gc, size_t limit)
 
static void incremental_gc_until (mrb_state *mrb, mrb_gc *gc, mrb_gc_state to_state)
 
static void incremental_gc_step (mrb_state *mrb, mrb_gc *gc)
 
static void clear_all_old (mrb_state *mrb, mrb_gc *gc)
 
void mrb_incremental_gc (mrb_state *mrb)
 
void mrb_full_gc (mrb_state *mrb)
 
void mrb_garbage_collect (mrb_state *mrb)
 
void mrb_field_write_barrier (mrb_state *mrb, struct RBasic *obj, struct RBasic *value)
 
void mrb_write_barrier (mrb_state *mrb, struct RBasic *obj)
 
static mrb_value gc_start (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_enable (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_disable (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_interval_ratio_get (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_interval_ratio_set (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_step_ratio_get (mrb_state *mrb, mrb_value obj)
 
static mrb_value gc_step_ratio_set (mrb_state *mrb, mrb_value obj)
 
static void change_gen_gc_mode (mrb_state *mrb, mrb_gc *gc, mrb_bool enable)
 
static mrb_value gc_generational_mode_get (mrb_state *mrb, mrb_value self)
 
static mrb_value gc_generational_mode_set (mrb_state *mrb, mrb_value self)
 
static void gc_each_objects (mrb_state *mrb, mrb_gc *gc, mrb_each_object_callback *callback, void *data)
 
void mrb_objspace_each_objects (mrb_state *mrb, mrb_each_object_callback *callback, void *data)
 
size_t mrb_objspace_page_slot_size (void)
 
void mrb_init_gc (mrb_state *mrb)
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   x)

Definition at line 189 of file gc.c.

◆ DEFAULT_GC_INTERVAL_RATIO

#define DEFAULT_GC_INTERVAL_RATIO   200

Definition at line 389 of file gc.c.

◆ DEFAULT_GC_STEP_RATIO

#define DEFAULT_GC_STEP_RATIO   200

Definition at line 390 of file gc.c.

◆ flip_white_part

#define flip_white_part (   s)    ((s)->current_white_part = other_white_part(s))

Definition at line 215 of file gc.c.

◆ GC_BLACK

#define GC_BLACK   (1 << 2)

Definition at line 202 of file gc.c.

◆ GC_COLOR_MASK

#define GC_COLOR_MASK   7

Definition at line 205 of file gc.c.

◆ GC_GRAY

#define GC_GRAY   0

Definition at line 199 of file gc.c.

◆ GC_INVOKE_TIME_REPORT

#define GC_INVOKE_TIME_REPORT (   s)

Definition at line 181 of file gc.c.

◆ GC_RED

#define GC_RED   7

Definition at line 203 of file gc.c.

◆ GC_ROOT_SYM

#define GC_ROOT_SYM   MRB_SYM(_gc_root_)

Definition at line 477 of file gc.c.

◆ GC_STEP_SIZE

#define GC_STEP_SIZE   1024

Definition at line 196 of file gc.c.

◆ GC_TIME_START

#define GC_TIME_START

Definition at line 182 of file gc.c.

◆ GC_TIME_STOP_AND_REPORT

#define GC_TIME_STOP_AND_REPORT

Definition at line 183 of file gc.c.

◆ GC_WHITE_A

#define GC_WHITE_A   1

Definition at line 200 of file gc.c.

◆ GC_WHITE_B

#define GC_WHITE_B   (1 << 1)

Definition at line 201 of file gc.c.

◆ GC_WHITES

#define GC_WHITES   (GC_WHITE_A | GC_WHITE_B)

Definition at line 204 of file gc.c.

◆ is_black

#define is_black (   o)    ((o)->color == GC_BLACK)

Definition at line 213 of file gc.c.

◆ is_dead

#define is_dead (   s,
 
)    (((o)->color & other_white_part(s) & GC_WHITES) || (o)->tt == MRB_TT_FREE)

Definition at line 217 of file gc.c.

◆ is_generational

#define is_generational (   gc)    ((gc)->generational)

Definition at line 393 of file gc.c.

◆ is_gray

#define is_gray (   o)    ((o)->color == GC_GRAY)

Definition at line 211 of file gc.c.

◆ is_major_gc

#define is_major_gc (   gc)    (is_generational(gc) && (gc)->full)

Definition at line 394 of file gc.c.

◆ is_minor_gc

#define is_minor_gc (   gc)    (is_generational(gc) && !(gc)->full)

Definition at line 395 of file gc.c.

◆ is_red

#define is_red (   o)    ((o)->color == GC_RED)

Definition at line 214 of file gc.c.

◆ is_white

#define is_white (   o)    ((o)->color & GC_WHITES)

Definition at line 212 of file gc.c.

◆ MAJOR_GC_INC_RATIO

#define MAJOR_GC_INC_RATIO   120

Definition at line 391 of file gc.c.

◆ MAJOR_GC_TOOMANY

#define MAJOR_GC_TOOMANY   10000

Definition at line 392 of file gc.c.

◆ MRB_HEAP_PAGE_SIZE

#define MRB_HEAP_PAGE_SIZE   1024

Definition at line 193 of file gc.c.

◆ objects

#define objects (   p)    ((RVALUE *)p->objects)

Definition at line 219 of file gc.c.

◆ other_white_part

#define other_white_part (   s)    ((s)->current_white_part ^ GC_WHITES)

Definition at line 216 of file gc.c.

◆ paint_black

#define paint_black (   o)    ((o)->color = GC_BLACK)

Definition at line 208 of file gc.c.

◆ paint_gray

#define paint_gray (   o)    ((o)->color = GC_GRAY)

Definition at line 207 of file gc.c.

◆ paint_partial_white

#define paint_partial_white (   s,
 
)    ((o)->color = (s)->current_white_part)

Definition at line 210 of file gc.c.

◆ paint_white

#define paint_white (   o)    ((o)->color = GC_WHITES)

Definition at line 209 of file gc.c.

Function Documentation

◆ add_gray_list()

static void add_gray_list ( mrb_state mrb,
mrb_gc gc,
struct RBasic obj 
)
inlinestatic

Definition at line 589 of file gc.c.

References abort(), gen-ucd-table::gc, RBasic::gcnext, MRB_TT_MAXDEFINE, paint_gray, and RBasic::tt.

Referenced by mrb_field_write_barrier(), and mrb_gc_mark().

◆ add_heap()

static void add_heap ( mrb_state mrb,
mrb_gc gc 
)
static

◆ change_gen_gc_mode()

static void change_gen_gc_mode ( mrb_state mrb,
mrb_gc gc,
mrb_bool  enable 
)
static

◆ ci_nregs()

static mrb_int ci_nregs ( mrb_callinfo ci)
static

Definition at line 602 of file gc.c.

References mrb_callinfo::argc, MRB_PROC_CFUNC_P, n, p, and mrb_callinfo::proc.

Referenced by gc_gray_counts(), and mark_context_stack().

◆ clear_all_old()

◆ final_marking_phase()

static void final_marking_phase ( mrb_state mrb,
mrb_gc gc 
)
static

◆ free_heap()

static void free_heap ( mrb_state mrb,
mrb_gc gc 
)
static

Definition at line 424 of file gc.c.

References e, gen-ucd-table::gc, mrb_free(), MRB_HEAP_PAGE_SIZE, MRB_TT_FREE, obj_free(), objects, p, page, and TRUE.

Referenced by mrb_gc_destroy().

◆ gc_disable()

static mrb_value gc_disable ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1438 of file gc.c.

References mrb_gc::disabled, mrb_state::gc, mrb_bool_value(), and TRUE.

Referenced by mrb_init_gc().

◆ gc_each_objects()

static void gc_each_objects ( mrb_state mrb,
mrb_gc gc,
mrb_each_object_callback callback,
void data 
)
static

Definition at line 1569 of file gc.c.

References as, data, gen-ucd-table::gc, i, MRB_EACH_OBJ_BREAK, MRB_HEAP_PAGE_SIZE, NULL, objects, p, and page.

Referenced by mrb_objspace_each_objects().

◆ gc_enable()

static mrb_value gc_enable ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1416 of file gc.c.

References mrb_gc::disabled, FALSE, mrb_state::gc, and mrb_bool_value().

Referenced by mrb_init_gc().

◆ gc_generational_mode_get()

static mrb_value gc_generational_mode_get ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1542 of file gc.c.

References mrb_state::gc, mrb_gc::generational, and mrb_bool_value().

Referenced by mrb_init_gc().

◆ gc_generational_mode_set()

static mrb_value gc_generational_mode_set ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1556 of file gc.c.

References change_gen_gc_mode(), enable, mrb_state::gc, mrb_gc::generational, mrb_bool_value(), and mrb_get_args().

Referenced by mrb_init_gc().

◆ gc_gray_counts()

◆ gc_interval_ratio_get()

static mrb_value gc_interval_ratio_get ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1456 of file gc.c.

References mrb_state::gc, mrb_gc::interval_ratio, and mrb_fixnum_value().

Referenced by mrb_init_gc().

◆ gc_interval_ratio_set()

static mrb_value gc_interval_ratio_set ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1471 of file gc.c.

References mrb_state::gc, int(), mrb_gc::interval_ratio, mrb_get_args(), and mrb_nil_value().

Referenced by mrb_init_gc().

◆ gc_mark_children()

◆ gc_mark_gray_list()

static void gc_mark_gray_list ( mrb_state mrb,
mrb_gc gc 
)
static

Definition at line 1051 of file gc.c.

References gen-ucd-table::gc, gc_mark_children(), and RBasic::gcnext.

Referenced by final_marking_phase().

◆ gc_protect()

static void gc_protect ( mrb_state mrb,
mrb_gc gc,
struct RBasic p 
)
static

Definition at line 451 of file gc.c.

References gen-ucd-table::gc, int(), mrb_exc_raise(), MRB_GC_ARENA_SIZE, mrb_obj_value(), mrb_realloc(), and p.

Referenced by mrb_gc_protect(), and mrb_obj_alloc().

◆ gc_start()

static mrb_value gc_start ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1396 of file gc.c.

References mrb_full_gc(), and mrb_nil_value().

Referenced by mrb_init_gc().

◆ gc_step_ratio_get()

static mrb_value gc_step_ratio_get ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1489 of file gc.c.

References mrb_state::gc, mrb_fixnum_value(), and mrb_gc::step_ratio.

Referenced by mrb_init_gc().

◆ gc_step_ratio_set()

static mrb_value gc_step_ratio_set ( mrb_state mrb,
mrb_value  obj 
)
static

Definition at line 1504 of file gc.c.

References mrb_state::gc, int(), mrb_get_args(), mrb_nil_value(), and mrb_gc::step_ratio.

Referenced by mrb_init_gc().

◆ heap_p()

static mrb_bool heap_p ( mrb_gc gc,
struct RBasic object 
)
static

Definition at line 302 of file gc.c.

References as, FALSE, gen-ucd-table::gc, MRB_HEAP_PAGE_SIZE, objects, p, page, and TRUE.

Referenced by mrb_object_dead_p().

◆ incremental_gc()

◆ incremental_gc_step()

static void incremental_gc_step ( mrb_state mrb,
mrb_gc gc 
)
static

◆ incremental_gc_until()

static void incremental_gc_until ( mrb_state mrb,
mrb_gc gc,
mrb_gc_state  to_state 
)
static

Definition at line 1206 of file gc.c.

References gen-ucd-table::gc, incremental_gc(), and SIZE_MAX.

Referenced by change_gen_gc_mode(), clear_all_old(), mrb_full_gc(), and mrb_incremental_gc().

◆ incremental_marking_phase()

static size_t incremental_marking_phase ( mrb_state mrb,
mrb_gc gc,
size_t  limit 
)
static

Definition at line 1061 of file gc.c.

References gen-ucd-table::gc, gc_gray_counts(), gc_mark_children(), RBasic::gcnext, and limit.

Referenced by incremental_gc().

◆ incremental_sweep_phase()

◆ link_free_heap_page()

static void link_free_heap_page ( mrb_gc gc,
mrb_heap_page page 
)
static

Definition at line 349 of file gc.c.

References gen-ucd-table::gc, and page.

Referenced by add_heap(), and incremental_sweep_phase().

◆ link_heap_page()

static void link_heap_page ( mrb_gc gc,
mrb_heap_page page 
)
static

Definition at line 327 of file gc.c.

References gen-ucd-table::gc, page, and cell::prev.

Referenced by add_heap().

◆ mark_context()

◆ mark_context_stack()

static void mark_context_stack ( mrb_state mrb,
struct mrb_context c 
)
static

Definition at line 624 of file gc.c.

References c, ci_nregs(), e, i, mrb_basic_ptr, mrb_gc_mark(), mrb_immediate_p, mrb_nil_value(), nil, NULL, and v.

Referenced by mark_context().

◆ mrb_alloca()

void* mrb_alloca ( mrb_state mrb,
size_t  size 
)

Definition at line 294 of file gc.c.

References mrb_malloc(), mrb_obj_alloc(), MRB_TT_STRING, s, size, and mrb_state::string_class.

Referenced by prepare_name_common().

◆ mrb_calloc()

void* mrb_calloc ( mrb_state mrb,
size_t  nelem,
size_t  len 
)

◆ mrb_field_write_barrier()

◆ mrb_free()

◆ mrb_full_gc()

◆ mrb_garbage_collect()

void mrb_garbage_collect ( mrb_state mrb)

Definition at line 1334 of file gc.c.

References mrb_full_gc().

Referenced by mrb_cloexec_open(), and mrb_pipe().

◆ mrb_gc_destroy()

void mrb_gc_destroy ( mrb_state mrb,
mrb_gc gc 
)

Definition at line 442 of file gc.c.

References free_heap(), gen-ucd-table::gc, and mrb_free().

Referenced by mrb_close().

◆ mrb_gc_init()

void mrb_gc_init ( mrb_state mrb,
mrb_gc gc 
)

◆ mrb_gc_mark()

void mrb_gc_mark ( mrb_state mrb,
struct RBasic obj 
)

◆ mrb_gc_protect()

◆ mrb_gc_register()

void mrb_gc_register ( mrb_state mrb,
mrb_value  obj 
)

◆ mrb_gc_unregister()

◆ mrb_incremental_gc()

◆ mrb_init_gc()

◆ mrb_malloc()

◆ mrb_malloc_simple()

void* mrb_malloc_simple ( mrb_state mrb,
size_t  len 
)

Definition at line 262 of file gc.c.

References len, and mrb_realloc_simple().

Referenced by mrb_pool_open(), page_alloc(), and tr_parse_pattern().

◆ mrb_obj_alloc()

◆ mrb_object_dead_p()

mrb_bool mrb_object_dead_p ( mrb_state mrb,
struct RBasic object 
)

Definition at line 320 of file gc.c.

References gen-ucd-table::gc, mrb_state::gc, heap_p(), is_dead, and TRUE.

Referenced by obj_free(), os_count_object_type(), and os_each_object_cb().

◆ mrb_objspace_each_objects()

◆ mrb_objspace_page_slot_size()

size_t mrb_objspace_page_slot_size ( void  )

Definition at line 1615 of file gc.c.

Referenced by os_memsize_of_object().

◆ mrb_raise_nomemory()

void mrb_raise_nomemory ( mrb_state mrb)

Definition at line 617 of file error.c.

Referenced by mrb_realloc().

◆ mrb_realloc()

◆ mrb_realloc_simple()

void* mrb_realloc_simple ( mrb_state mrb,
void p,
size_t  len 
)

◆ mrb_write_barrier()

◆ obj_free()

◆ prepare_incremental_sweep()

static void prepare_incremental_sweep ( mrb_state mrb,
mrb_gc gc 
)
static

Definition at line 1099 of file gc.c.

References gen-ucd-table::gc, and MRB_GC_STATE_SWEEP.

Referenced by clear_all_old(), and incremental_gc().

◆ root_scan_phase()

◆ unlink_free_heap_page()

static void unlink_free_heap_page ( mrb_gc gc,
mrb_heap_page page 
)
static

Definition at line 359 of file gc.c.

References gen-ucd-table::gc, and NULL.

Referenced by incremental_sweep_phase(), and mrb_obj_alloc().

◆ unlink_heap_page()

static void unlink_heap_page ( mrb_gc gc,
mrb_heap_page page 
)
static

Definition at line 336 of file gc.c.

References gen-ucd-table::gc, and NULL.

Referenced by incremental_sweep_phase().