potion  0.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gc.c File Reference

Generational copying garbage collector, non-precise with Cheney loop. More...

#include <stdio.h>
#include <stdlib.h>
#include "potion.h"
#include "internal.h"
#include "gc.h"
#include "khash.h"
#include "table.h"
#include <sys/time.h>
+ Include dependency graph for gc.c:

Go to the source code of this file.

Macros

#define DBG_Gv(P,...)
 
#define DBG_G(P,...)
 
#define HAS_REAL_TYPE(v)   (P->vts == NULL || (((struct PNFwd *)v)->fwd == POTION_COPIED || PN_TYPECHECK(PN_VTYPE(v))))
 

Functions

static double mytime ()
 
PN_SIZE potion_stack_len (Potion *P, _PN **p)
 
static
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
PN_SIZE 
pngc_mark_array (Potion *P, register _PN *x, register long n, int type)
 
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
PN_SIZE 
potion_mark_stack (Potion *P, int type)
 
void * pngc_page_new (int *sz, const char exec)
 
void pngc_page_delete (void *mem, int sz)
 
static int NEW_BIRTH_REGION (struct PNMemory *M, void **wb, int sz)
 
static int potion_gc_minor (Potion *P, int sz)
 
static int potion_gc_major (Potion *P, int siz)
 
void potion_garbagecollect (Potion *P, int sz, int full)
 
PN_SIZE potion_type_size (Potion *P, const struct PNObject *ptr)
 
void * potion_gc_copy (Potion *P, struct PNObject *ptr)
 
void * potion_mark_minor (Potion *P, const struct PNObject *ptr)
 
void * potion_mark_major (Potion *P, const struct PNObject *ptr)
 
Potionpotion_gc_boot (void *sp)
 
void potion_gc_release (Potion *P)
 
PN potion_gc_actual (Potion *P, PN cl, PN self)
 
PN potion_gc_fixed (Potion *P, PN cl, PN self)
 
PN potion_gc_reserved (Potion *P, PN cl, PN self)
 

Detailed Description

Generational copying garbage collector, non-precise with Cheney loop.

Heavily based on Qish, a lightweight copying generational GC by Basile Starynkevitch. http://starynkevitch.net/Basile/qishintro.html

(c) 2008 why the lucky stiff, the freelance professor

Definition in file gc.c.

Macro Definition Documentation

#define DBG_Gv (   P,
  ... 
)
Value:
if (P->flags & DEBUG_GC && P->flags & DEBUG_VERBOSE) { \
printf(__VA_ARGS__); \
}

Definition at line 37 of file gc.c.

#define DBG_G (   P,
  ... 
)
Value:
if (P->flags & DEBUG_GC) { \
printf(__VA_ARGS__); \
}

Definition at line 41 of file gc.c.

#define HAS_REAL_TYPE (   v)    (P->vts == NULL || (((struct PNFwd *)v)->fwd == POTION_COPIED || PN_TYPECHECK(PN_VTYPE(v))))

Definition at line 57 of file gc.c.

Function Documentation

static double mytime ( )
static

Definition at line 25 of file gc.c.

PN_SIZE potion_stack_len ( Potion P,
_PN **  p 
)

Definition at line 50 of file gc.c.

static ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS PN_SIZE pngc_mark_array ( Potion P,
register _PN x,
register long  n,
int  type 
)
static

Definition at line 60 of file gc.c.

ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS PN_SIZE potion_mark_stack ( Potion P,
int  type 
)

Definition at line 98 of file gc.c.

void* pngc_page_new ( int *  sz,
const char  exec 
)

Definition at line 114 of file gc.c.

void pngc_page_delete ( void *  mem,
int  sz 
)

Definition at line 119 of file gc.c.

static int NEW_BIRTH_REGION ( struct PNMemory M,
void **  wb,
int  sz 
)
inlinestatic

Definition at line 123 of file gc.c.

static int potion_gc_minor ( Potion P,
int  sz 
)
static
Both this function and potion_gc_major embody a simple Cheney loop (also called a "two-finger collector.") http://en.wikipedia.org/wiki/Cheney%27s_algorithm (Again, many thanks to Basile Starynkevitch for his tutelage in this matter.)

Definition at line 143 of file gc.c.

static int potion_gc_major ( Potion P,
int  siz 
)
static

Definition at line 187 of file gc.c.

void potion_garbagecollect ( Potion P,
int  sz,
int  full 
)

Definition at line 266 of file gc.c.

PN_SIZE potion_type_size ( Potion P,
const struct PNObject ptr 
)

Definition at line 306 of file gc.c.

void* potion_gc_copy ( Potion P,
struct PNObject ptr 
)

Definition at line 394 of file gc.c.

void* potion_mark_minor ( Potion P,
const struct PNObject ptr 
)

Definition at line 413 of file gc.c.

void* potion_mark_major ( Potion P,
const struct PNObject ptr 
)

Definition at line 519 of file gc.c.

Potion* potion_gc_boot ( void *  sp)
Potion's GC is a generational copying GC. This is why the volatile keyword is used so liberally throughout the source code. PN types may suddenly move during any collection phase. They move from the birth area to the old area.

Potion actually begins by allocating an old area. This is for two reasons. First, the script may be too short to require an old area, so we want to avoid allocating two areas to start with. And second, since Potion loads its core classes into GC first, we save ourselves a severe promotion step by beginning with an automatic promotion to second generation. (Oh and this allows the core Potion struct pointer to be non-volatile.)

In short, this first page is never released, since the GC struct itself is on that page.

While this may pay a slight penalty in memory size for long-running scripts, perhaps I could add some occassional compaction to solve that as well.

See also
potion_init() which calls GC_PROTECT()

Definition at line 658 of file gc.c.

void potion_gc_release ( Potion P)

Definition at line 691 of file gc.c.

PN potion_gc_actual ( Potion P,
PN  cl,
PN  self 
)

Definition at line 714 of file gc.c.

PN potion_gc_fixed ( Potion P,
PN  cl,
PN  self 
)

Definition at line 724 of file gc.c.

PN potion_gc_reserved ( Potion P,
PN  cl,
PN  self 
)

Definition at line 732 of file gc.c.