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 "obx.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for gc.c:

Go to the source code of this file.

Classes

struct  _header
 

Macros

#define ASSERT(p)
 
#define DEBUG_PRINT(flags, args)
 
#define GC_TRACE(s)   if (debug['g']) { printf("%s", s); fflush(stdout); }
 
#define BYTES_PER_WORD   4
 
#define PAGE_WORDS   (PAGESIZE / BYTES_PER_WORD)
 
#define MB   1024*1024
 
#define INIT_SIZE   (2*MB) /* Initial heap size */
 
#define CHUNK_SIZE   (1*MB) /* Amount that heap grows */
 
#define round_down(x, n)   ((x)/(n)*(n))
 
#define round_up(x, n)   round_down((x)+(n)-1, n)
 
#define hdr(h)   h
 
#define header_alloc()   scratch_alloc(sizeof(header))
 
#define charptr(a)   ptrcast(char, a)
 
#define free_header(h)   hdr(h)->h_next = hdr_free; hdr_free = h;
 
#define empty(list)   (hdr(list)->h_next == (list))
 
#define insert(h, h2)
 
#define unlink(h)
 
#define headers(h, list)    h = hdr(list)->h_next; h != list; h = hdr(h)->h_next
 
#define PAGESIZE   4096
 
#define LOG_PAGESIZE   12
 
#define BOT_BITS   (LOG_PAGESIZE - 2)
 
#define BOT_SIZE   (1 << BOT_BITS)
 
#define TOP_BITS   (8*BYTES_PER_WORD - BOT_BITS - LOG_PAGESIZE)
 
#define TOP_SIZE   (1 << TOP_BITS)
 
#define mask(x, n)   ((x) & ((1 << (n)) - 1))
 
#define top_part(p)   ((p) >> (BOT_BITS + LOG_PAGESIZE))
 
#define bot_part(p)   mask((p) >> LOG_PAGESIZE, BOT_BITS)
 
#define get_header(p)    (*ptrcast(page_index, page_table[top_part(p)]))[bot_part(p)]
 
#define left_neighbour(h)   get_header(hdr(h)->h_memory - 1)
 
#define right_neighbour(h)   get_header(hdr(h)->h_memory + hdr(h)->h_size)
 
#define BIG_BLOCK   8
 
#define contiguous(h1, h2)
 
#define N_SIZES   (2*LOG_PAGESIZE)
 
#define MAX_SMALL_WORDS   (PAGE_WORDS/2)
 
#define MAX_SMALL_BYTES   (BYTES_PER_WORD * MAX_SMALL_WORDS)
 
#define pool_size(i)   size_bytes[i]
 
#define pool_block(i)   PAGESIZE
 
#define pool_count(i)   (pool_block(i) / pool_size(i))
 
#define pool_map(size)   size_map[(size)/BYTES_PER_WORD]
 
#define GRANULE   16 /* Should be about the size of a cache line */
 
#define THRESHOLD   0.5
 
#define BROKEN_HEART   0xbabeface
 
#define get_word(p, i)   ptrcast(word, p)[i]
 
#define desc(p)   ptrcast(word, get_word(p, 0))
 
#define mrk(j)   redirect((word *) &get_word(origin, i+j))
 
#define mask_signals()
 
#define unmask_signals()
 

Typedefs

typedef struct _headerhdrptr
 
typedef struct _header header
 
typedef hdrptr page_index[(1<<(12 - 2))]
 

Functions

voidscratch_alloc (unsigned size)
 
word map_segment (void *p, unsigned len)
 
word get_chunk (unsigned size)
 
word virtual_alloc (unsigned size)
 
static hdrptr alloc_header (void)
 
static hdrptr new_list (void)
 
static void page_setup (word base, unsigned size, hdrptr h)
 
static void init_pagetable (void)
 
static void make_free (hdrptr h)
 
static hdrptr free_block (hdrptr h, mybool mapped)
 
static hdrptr find_block (unsigned size, unsigned objsize)
 
static void new_size (int size, int block)
 
static void init_sizes (void)
 
void scavenge (value *sp, unsigned size)
 
static void add_block (int index)
 
word gc_alloc (unsigned size, value *sp)
 
static void redirect (word *p)
 
static word map_next (word p)
 
static void redir_map (unsigned map, word origin, int bmshift)
 
static void traverse_stack (value *xsp)
 
static void migrate (void)
 
void gc_dump (void)
 
valuegc_collect (value *sp)
 
void gc_init (void)
 
void gc_debug (char *flags)
 
int gc_heap_size ()
 
voidvm_alloc (int size)
 

Variables

static mybool debug [256]
 
voidsegmap [4096]
 
static int nsegs = 1
 
static word alloc_ptr = 0
 
static word alloc_limit
 
static hdrptr hdr_free = 0
 
static word page_table [(1<<(8 *4 -(12 - 2) - 12))]
 
static word empty_index
 
static hdrptr free_list [8+1]
 
static unsigned gencount = 1
 
static unsigned n_sizes
 
static unsigned size_bytes [(2 *12)]
 
static unsigned char size_map [((4096/4)/2)+1]
 
static hdrptr block_pool [(2 *12)+1]
 
static hdrptr old_pool [(2 *12)+1]
 
static word free_ptr [(2 *12)+1]
 
static int free_count [(2 *12)+1]
 
mybool gcflag = 1
 
static unsigned alloc_since_gc = 0
 
static unsigned pool_total = 0
 
static unsigned heap_size = 0
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   p)

Definition at line 55 of file gc.c.

◆ BIG_BLOCK

#define BIG_BLOCK   8

Definition at line 511 of file gc.c.

◆ BOT_BITS

#define BOT_BITS   (LOG_PAGESIZE - 2)

Definition at line 449 of file gc.c.

◆ bot_part

#define bot_part (   p)    mask((p) >> LOG_PAGESIZE, BOT_BITS)

Definition at line 457 of file gc.c.

◆ BOT_SIZE

#define BOT_SIZE   (1 << BOT_BITS)

Definition at line 450 of file gc.c.

◆ BROKEN_HEART

#define BROKEN_HEART   0xbabeface

Definition at line 870 of file gc.c.

◆ BYTES_PER_WORD

#define BYTES_PER_WORD   4

Definition at line 93 of file gc.c.

◆ charptr

#define charptr (   a)    ptrcast(char, a)

Definition at line 363 of file gc.c.

◆ CHUNK_SIZE

#define CHUNK_SIZE   (1*MB) /* Amount that heap grows */

Definition at line 98 of file gc.c.

◆ contiguous

#define contiguous (   h1,
  h2 
)
Value:
charptr(hdr(h1)->h_memory) + hdr(h1)->h_size \
== charptr(hdr(h2)->h_memory)
#define charptr(a)
Definition: gc.c:363
#define hdr(h)
Definition: gc.c:359

Definition at line 531 of file gc.c.

◆ DEBUG_PRINT

#define DEBUG_PRINT (   flags,
  args 
)

Definition at line 63 of file gc.c.

◆ desc

#define desc (   p)    ptrcast(word, get_word(p, 0))

Definition at line 873 of file gc.c.

◆ empty

#define empty (   list)    (hdr(list)->h_next == (list))

Definition at line 411 of file gc.c.

◆ free_header

#define free_header (   h)    hdr(h)->h_next = hdr_free; hdr_free = h;

Definition at line 397 of file gc.c.

◆ GC_TRACE

#define GC_TRACE (   s)    if (debug['g']) { printf("%s", s); fflush(stdout); }

Definition at line 67 of file gc.c.

◆ get_header

#define get_header (   p)     (*ptrcast(page_index, page_table[top_part(p)]))[bot_part(p)]

Definition at line 468 of file gc.c.

◆ get_word

#define get_word (   p,
  i 
)    ptrcast(word, p)[i]

Definition at line 872 of file gc.c.

◆ GRANULE

#define GRANULE   16 /* Should be about the size of a cache line */

Definition at line 699 of file gc.c.

◆ hdr

#define hdr (   h)    h

Definition at line 359 of file gc.c.

◆ header_alloc

#define header_alloc ( )    scratch_alloc(sizeof(header))

Definition at line 360 of file gc.c.

◆ headers

#define headers (   h,
  list 
)     h = hdr(list)->h_next; h != list; h = hdr(h)->h_next

Definition at line 422 of file gc.c.

◆ INIT_SIZE

#define INIT_SIZE   (2*MB) /* Initial heap size */

Definition at line 97 of file gc.c.

◆ insert

#define insert (   h,
  h2 
)
Value:
hdr(h2)->h_next = h; hdr(h2)->h_prev = hdr(h)->h_prev; \
hdr(hdr(h)->h_prev)->h_next = h2; hdr(h)->h_prev = h2;
int h
Definition: dviconv.c:9

Definition at line 413 of file gc.c.

◆ left_neighbour

#define left_neighbour (   h)    get_header(hdr(h)->h_memory - 1)

Definition at line 473 of file gc.c.

◆ LOG_PAGESIZE

#define LOG_PAGESIZE   12

Definition at line 447 of file gc.c.

◆ mask

#define mask (   x,
  n 
)    ((x) & ((1 << (n)) - 1))

Definition at line 454 of file gc.c.

◆ mask_signals

#define mask_signals ( )

Definition at line 1184 of file gc.c.

◆ MAX_SMALL_BYTES

#define MAX_SMALL_BYTES   (BYTES_PER_WORD * MAX_SMALL_WORDS)

Definition at line 680 of file gc.c.

◆ MAX_SMALL_WORDS

#define MAX_SMALL_WORDS   (PAGE_WORDS/2)

Definition at line 678 of file gc.c.

◆ MB

#define MB   1024*1024

Definition at line 96 of file gc.c.

◆ mrk

#define mrk (   j)    redirect((word *) &get_word(origin, i+j))

◆ N_SIZES

#define N_SIZES   (2*LOG_PAGESIZE)

Definition at line 673 of file gc.c.

◆ PAGE_WORDS

#define PAGE_WORDS   (PAGESIZE / BYTES_PER_WORD)

Definition at line 94 of file gc.c.

◆ PAGESIZE

#define PAGESIZE   4096

Definition at line 446 of file gc.c.

◆ pool_block

#define pool_block (   i)    PAGESIZE

Definition at line 691 of file gc.c.

◆ pool_count

#define pool_count (   i)    (pool_block(i) / pool_size(i))

Definition at line 694 of file gc.c.

◆ pool_map

#define pool_map (   size)    size_map[(size)/BYTES_PER_WORD]

Definition at line 697 of file gc.c.

◆ pool_size

#define pool_size (   i)    size_bytes[i]

Definition at line 685 of file gc.c.

◆ right_neighbour

#define right_neighbour (   h)    get_header(hdr(h)->h_memory + hdr(h)->h_size)

Definition at line 474 of file gc.c.

◆ round_down

#define round_down (   x,
  n 
)    ((x)/(n)*(n))

Definition at line 100 of file gc.c.

◆ round_up

#define round_up (   x,
  n 
)    round_down((x)+(n)-1, n)

Definition at line 101 of file gc.c.

◆ THRESHOLD

#define THRESHOLD   0.5

Definition at line 788 of file gc.c.

◆ TOP_BITS

#define TOP_BITS   (8*BYTES_PER_WORD - BOT_BITS - LOG_PAGESIZE)

Definition at line 451 of file gc.c.

◆ top_part

#define top_part (   p)    ((p) >> (BOT_BITS + LOG_PAGESIZE))

Definition at line 456 of file gc.c.

◆ TOP_SIZE

#define TOP_SIZE   (1 << TOP_BITS)

Definition at line 452 of file gc.c.

◆ unlink

#define unlink (   h)
Value:
hdr(hdr(h)->h_prev)->h_next = hdr(h)->h_next; \
hdr(hdr(h)->h_next)->h_prev = hdr(h)->h_prev

Definition at line 417 of file gc.c.

◆ unmask_signals

#define unmask_signals ( )

Definition at line 1185 of file gc.c.

Typedef Documentation

◆ hdrptr

typedef struct _header* hdrptr

Definition at line 358 of file gc.c.

◆ header

typedef struct _header header

◆ page_index

typedef hdrptr page_index[(1<<(12 - 2))]

Definition at line 463 of file gc.c.

Function Documentation

◆ add_block()

static void add_block ( int  index)
static

Definition at line 804 of file gc.c.

References block_pool, find_block(), free_count, free_ptr, h, hdr, index, insert, pool_block, pool_count, pool_size, and pool_total.

Referenced by gc_alloc(), and redirect().

◆ alloc_header()

static hdrptr alloc_header ( void  )
static

Definition at line 379 of file gc.c.

References h, hdr, hdr_free, and header_alloc.

Referenced by find_block(), and new_list().

◆ find_block()

static hdrptr find_block ( unsigned  size,
unsigned  objsize 
)
static

◆ free_block()

static hdrptr free_block ( hdrptr  h,
mybool  mapped 
)
static

◆ gc_alloc()

◆ gc_collect()

◆ gc_debug()

void gc_debug ( char *  flags)

Definition at line 1306 of file gc.c.

References debug, flags, i, and TRUE.

◆ gc_dump()

void gc_dump ( void  )

◆ gc_heap_size()

int gc_heap_size ( void  )

Definition at line 1313 of file gc.c.

References heap_size.

Referenced by P_gc_heap_size().

◆ gc_init()

void gc_init ( void  )

Definition at line 1287 of file gc.c.

References BIG_BLOCK, block_pool, free_list, heap_size, i, init_pagetable(), INIT_SIZE, init_sizes(), n_sizes, new_list(), and old_pool.

Referenced by xmain().

◆ get_chunk()

word get_chunk ( unsigned  size)

Definition at line 313 of file gc.c.

References map_segment(), p, scratch_alloc(), and size.

Referenced by find_block(), and virtual_alloc().

◆ init_pagetable()

static void init_pagetable ( void  )
static

Definition at line 490 of file gc.c.

References empty_index, i, page_table, TOP_SIZE, and virtual_alloc().

Referenced by gc_init().

◆ init_sizes()

static void init_sizes ( void  )
static

Definition at line 718 of file gc.c.

References ASSERT, BYTES_PER_WORD, i, k, MAX_SMALL_BYTES, MAX_SMALL_WORDS, n_sizes, new_size(), PAGESIZE, size_bytes, and size_map.

Referenced by gc_init().

◆ make_free()

static void make_free ( hdrptr  h)
static

Definition at line 517 of file gc.c.

References BIG_BLOCK, DEBUG_PRINT, free_list, h, h_size(), hdr, insert, and PAGESIZE.

Referenced by find_block(), and free_block().

◆ map_next()

static word map_next ( word  p)
static

Definition at line 919 of file gc.c.

References GC_BASE, GC_BLOCK, GC_END, GC_FLEX, GC_MAP, GC_POINTER, GC_REPEAT, get_word, p, and panic().

Referenced by redir_map().

◆ map_segment()

word map_segment ( void p,
unsigned  len 
)

Definition at line 300 of file gc.c.

References base, len, nsegs, p, q, segmap, and SEGMENT.

Referenced by get_chunk(), and load_image().

◆ migrate()

static void migrate ( void  )
static

Definition at line 1108 of file gc.c.

References block_pool, BYTES_PER_WORD, changed, desc, DESC_MAP, FALSE, free_ptr, hdr, i, N_SIZES, n_sizes, NULL, p, pool_block, pool_size, redir_map(), and TRUE.

Referenced by gc_collect().

◆ new_list()

static hdrptr new_list ( void  )
static

◆ new_size()

◆ page_setup()

static void page_setup ( word  base,
unsigned  size,
hdrptr  h 
)
static

Definition at line 477 of file gc.c.

References ASSERT, base, empty_index, get_header, h, p, page_table, PAGESIZE, size, top_part, and virtual_alloc().

Referenced by find_block(), and free_block().

◆ redir_map()

static void redir_map ( unsigned  map,
word  origin,
int  bmshift 
)
static

◆ redirect()

◆ scavenge()

void scavenge ( value sp,
unsigned  size 
)

Definition at line 796 of file gc.c.

References alloc_since_gc, gc_collect(), gcflag, heap_size, PAGESIZE, round_up, size, sp, and THRESHOLD.

Referenced by gc_alloc().

◆ scratch_alloc()

void* scratch_alloc ( unsigned  size)

Definition at line 289 of file gc.c.

References malloc, memset(), NULL, p, panic(), and size.

Referenced by get_chunk(), load_image(), and vm_alloc().

◆ traverse_stack()

static void traverse_stack ( value xsp)
static

Definition at line 1069 of file gc.c.

References a, BP, c, CP, CP_MAP, CP_STKMAP, DEBUG_PRINT, dsegaddr, f, find_proc, FRAME_SHIFT, HEAD, i, interpreted, NULL, pc, PC, pointer, r, redir_map(), sp, stkaddr, and valptr.

Referenced by gc_collect().

◆ virtual_alloc()

word virtual_alloc ( unsigned  size)

Definition at line 321 of file gc.c.

References alloc_limit, alloc_ptr, ASSERT, get_chunk(), p, SEGMENT, and size.

Referenced by init_pagetable(), and page_setup().

◆ vm_alloc()

void* vm_alloc ( int  size)

Definition at line 1318 of file gc.c.

References scratch_alloc(), and size.

Variable Documentation

◆ alloc_limit

word alloc_limit
static

Definition at line 318 of file gc.c.

Referenced by virtual_alloc().

◆ alloc_ptr

word alloc_ptr = 0
static

Definition at line 318 of file gc.c.

Referenced by virtual_alloc().

◆ alloc_since_gc

unsigned alloc_since_gc = 0
static

Definition at line 791 of file gc.c.

Referenced by gc_alloc(), gc_collect(), and scavenge().

◆ block_pool

hdrptr block_pool[(2 *12)+1]
static

Definition at line 769 of file gc.c.

Referenced by add_block(), gc_alloc(), gc_collect(), gc_dump(), gc_init(), migrate(), and redirect().

◆ debug

mybool debug[256]
static

Definition at line 38 of file gc.c.

Referenced by free_block(), gc_alloc(), and gc_debug().

◆ empty_index

word empty_index
static

Definition at line 466 of file gc.c.

Referenced by init_pagetable(), and page_setup().

◆ free_count

int free_count[(2 *12)+1]
static

Definition at line 774 of file gc.c.

Referenced by add_block(), gc_alloc(), gc_collect(), and redirect().

◆ free_list

hdrptr free_list[8+1]
static

Definition at line 513 of file gc.c.

Referenced by find_block(), gc_dump(), gc_init(), jbg_buf_free(), jbg_buf_init(), jbg_buf_write(), and make_free().

◆ free_ptr

word free_ptr[(2 *12)+1]
static

Definition at line 773 of file gc.c.

Referenced by __gmp_doprnt_mpf(), add_block(), gc_alloc(), gc_collect(), migrate(), and redirect().

◆ gcflag

mybool gcflag = 1

Definition at line 790 of file gc.c.

Referenced by gc_collect(), and scavenge().

◆ gencount

unsigned gencount = 1
static

Definition at line 514 of file gc.c.

Referenced by find_block(), gc_collect(), and redirect().

◆ hdr_free

hdrptr hdr_free = 0
static

Definition at line 376 of file gc.c.

Referenced by alloc_header().

◆ heap_size

unsigned heap_size = 0
static

Definition at line 793 of file gc.c.

Referenced by gc_alloc(), gc_heap_size(), gc_init(), and scavenge().

◆ n_sizes

unsigned n_sizes
static

Definition at line 682 of file gc.c.

Referenced by gc_alloc(), gc_collect(), gc_dump(), gc_init(), init_sizes(), migrate(), new_size(), and redirect().

◆ nsegs

int nsegs = 1
static

Definition at line 297 of file gc.c.

Referenced by map_segment(), and release_unused_segments().

◆ old_pool

hdrptr old_pool[(2 *12)+1]
static

Definition at line 769 of file gc.c.

Referenced by gc_collect(), and gc_init().

◆ page_table

word page_table[(1<<(8 *4 -(12 - 2) - 12))]
static

Definition at line 465 of file gc.c.

Referenced by init_pagetable(), and page_setup().

◆ pool_total

unsigned pool_total = 0
static

Definition at line 792 of file gc.c.

Referenced by add_block(), gc_alloc(), gc_collect(), and gc_dump().

◆ segmap

void* segmap[4096]

Definition at line 296 of file gc.c.

Referenced by map_segment().

◆ size_bytes

unsigned size_bytes[(2 *12)]
static

Definition at line 684 of file gc.c.

Referenced by FcConfigSaveAttr(), init_sizes(), and new_size().

◆ size_map

unsigned char size_map[((4096/ 4)/2)+1]
static

Definition at line 696 of file gc.c.

Referenced by init_sizes().