make heap gc concurrent between threads.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1476 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
147c2cee15
commit
fb399932e4
@ -12,7 +12,7 @@
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: allocating space *
|
||||
* version:$Id: alloc.c,v 1.77 2005-11-23 12:09:50 vsc Exp $ *
|
||||
* version:$Id: alloc.c,v 1.78 2005-12-07 17:53:29 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
@ -264,9 +264,9 @@ Yap_InitMemory(int Trail, int Heap, int Stack)
|
||||
int
|
||||
Yap_ExtendWorkSpace(Int s)
|
||||
{
|
||||
void *bp = (void *)Yap_GlobalBase, *nbp;
|
||||
void *basebp = (void *)Yap_GlobalBase, *nbp;
|
||||
UInt s0 = (char *)Yap_TrailTop-(char *)Yap_GlobalBase;
|
||||
nbp = realloc(bp, s+s0);
|
||||
nbp = realloc(basebp, s+s0);
|
||||
if (nbp == NULL)
|
||||
return FALSE;
|
||||
Yap_GlobalBase = (char *)nbp;
|
||||
|
195
C/heapgc.c
195
C/heapgc.c
@ -23,7 +23,6 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "alloc.h"
|
||||
#include "attvar.h"
|
||||
|
||||
|
||||
#define EARLY_RESET 1
|
||||
#if !defined(TABLING)
|
||||
#define EASY_SHUNTING 1
|
||||
@ -33,29 +32,6 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/* global variables for garbage collection */
|
||||
|
||||
#if !defined(YAPOR) && !defined(THREADS)
|
||||
/* in a single gc */
|
||||
static unsigned long int total_marked, total_oldies; /* number of heap objects marked */
|
||||
|
||||
#if DEBUG
|
||||
#ifdef COROUTINING
|
||||
static unsigned long int total_smarked;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* !defined(YAPOR) && !defined(THREADS) */
|
||||
|
||||
#ifdef EASY_SHUNTING
|
||||
static choiceptr current_B;
|
||||
|
||||
static tr_fr_ptr sTR, sTR0;
|
||||
|
||||
static CELL *prev_HB;
|
||||
#endif
|
||||
|
||||
static tr_fr_ptr new_TR;
|
||||
|
||||
static CELL *HGEN;
|
||||
|
||||
STATIC_PROTO(Int p_inform_gc, (void));
|
||||
STATIC_PROTO(Int p_gc, (void));
|
||||
STATIC_PROTO(void push_registers, (Int, yamop *));
|
||||
@ -79,31 +55,105 @@ STATIC_PROTO(int is_gc_very_verbose, (void));
|
||||
|
||||
#include "heapgc.h"
|
||||
|
||||
#if GC_NO_TAGS
|
||||
char *bp;
|
||||
#endif
|
||||
|
||||
static int discard_trail_entries = 0;
|
||||
|
||||
/* support for hybrid garbage collection scheme */
|
||||
|
||||
typedef struct {
|
||||
typedef struct gc_mark_continuation {
|
||||
CELL *v;
|
||||
int nof;
|
||||
} cont;
|
||||
|
||||
/* straightforward binary tree scheme that, given a key, finds a
|
||||
matching dbref */
|
||||
|
||||
typedef enum {
|
||||
db_entry,
|
||||
cl_entry,
|
||||
lcl_entry,
|
||||
li_entry,
|
||||
dcl_entry
|
||||
} db_entry_type;
|
||||
|
||||
typedef struct db_entry {
|
||||
CODEADDR val;
|
||||
db_entry_type db_type;
|
||||
int in_use;
|
||||
struct db_entry *left;
|
||||
CODEADDR lim;
|
||||
struct db_entry *right;
|
||||
} *dbentry;
|
||||
|
||||
typedef struct RB_red_blk_node {
|
||||
CODEADDR key;
|
||||
CODEADDR lim;
|
||||
db_entry_type db_type;
|
||||
int in_use;
|
||||
int red; /* if red=0 then the node is black */
|
||||
struct RB_red_blk_node* left;
|
||||
struct RB_red_blk_node* right;
|
||||
struct RB_red_blk_node* parent;
|
||||
} rb_red_blk_node;
|
||||
|
||||
#ifdef EASY_SHUNTING
|
||||
#undef cont_top0
|
||||
#define cont_top0 (cont *)sTR
|
||||
#else
|
||||
#endif
|
||||
|
||||
#if !defined(YAPOR) && !defined(THREADS)
|
||||
/* in a single gc */
|
||||
static unsigned long int total_marked, total_oldies; /* number of heap objects marked */
|
||||
|
||||
#if DEBUG
|
||||
#ifdef COROUTINING
|
||||
static unsigned long int total_smarked;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef EASY_SHUNTING
|
||||
static choiceptr current_B;
|
||||
|
||||
static tr_fr_ptr sTR, sTR0;
|
||||
|
||||
static CELL *prev_HB;
|
||||
#endif
|
||||
|
||||
static tr_fr_ptr new_TR;
|
||||
|
||||
static CELL *HGEN;
|
||||
|
||||
#if GC_NO_TAGS
|
||||
char *Yap_bp;
|
||||
#endif
|
||||
|
||||
static int discard_trail_entries = 0;
|
||||
|
||||
#ifdef HYBRID_SCHEME
|
||||
static CELL_PTR *iptop;
|
||||
#endif
|
||||
|
||||
#ifndef EASY_SHUNTING
|
||||
static cont *cont_top0;
|
||||
#endif
|
||||
static cont *cont_top;
|
||||
|
||||
static gc_ma_hash_entry gc_ma_hash_table[GC_MAVARS_HASH_SIZE];
|
||||
|
||||
static gc_ma_hash_entry *gc_ma_h_top;
|
||||
|
||||
static UInt gc_timestamp; /* an unsigned int */
|
||||
|
||||
static ADDR db_vec, db_vec0;
|
||||
|
||||
static rb_red_blk_node *db_root, *db_nil;
|
||||
|
||||
#endif /* !defined(YAPOR) && !defined(THREADS) */
|
||||
|
||||
/* support for hybrid garbage collection scheme */
|
||||
|
||||
static void
|
||||
gc_growtrail(int committed)
|
||||
{
|
||||
#if THREADS
|
||||
#if !GC_TAGS
|
||||
YAPLeaveCriticalSection();
|
||||
#endif
|
||||
#if THREADS
|
||||
longjmp(Yap_gc_restore, 2);
|
||||
#endif
|
||||
#if USE_SYSTEM_MALLOC
|
||||
@ -157,8 +207,6 @@ PUSH_CONTINUATION(CELL *v, int nof) {
|
||||
|
||||
#ifdef HYBRID_SCHEME
|
||||
|
||||
static CELL_PTR *iptop;
|
||||
|
||||
inline static void
|
||||
PUSH_POINTER(CELL *v) {
|
||||
if (iptop >= (CELL_PTR *)ASP) return;
|
||||
@ -282,18 +330,6 @@ quicksort(CELL *a[], Int p, Int r)
|
||||
one will remain.
|
||||
*/
|
||||
|
||||
#define GC_MAVARS_HASH_SIZE 512
|
||||
|
||||
typedef struct gc_ma_hash_entry_struct {
|
||||
UInt timestmp;
|
||||
CELL* addr;
|
||||
struct gc_ma_hash_entry_struct *next;
|
||||
} gc_ma_hash_entry;
|
||||
|
||||
static gc_ma_hash_entry gc_ma_hash_table[GC_MAVARS_HASH_SIZE];
|
||||
|
||||
static UInt gc_timestamp; /* an unsigned int */
|
||||
|
||||
static inline unsigned int
|
||||
GC_MAVAR_HASH(CELL *addr) {
|
||||
#if SIZEOF_INT_P==8
|
||||
@ -303,8 +339,6 @@ GC_MAVAR_HASH(CELL *addr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
gc_ma_hash_entry *gc_ma_h_top;
|
||||
|
||||
static inline gc_ma_hash_entry *
|
||||
GC_ALLOC_NEW_MASPACE(void)
|
||||
{
|
||||
@ -511,41 +545,6 @@ count_cells_marked(void)
|
||||
#endif
|
||||
|
||||
|
||||
/* straightforward binary tree scheme that, given a key, finds a
|
||||
matching dbref */
|
||||
|
||||
typedef enum {
|
||||
db_entry,
|
||||
cl_entry,
|
||||
lcl_entry,
|
||||
li_entry,
|
||||
dcl_entry
|
||||
} db_entry_type;
|
||||
|
||||
typedef struct db_entry {
|
||||
CODEADDR val;
|
||||
db_entry_type db_type;
|
||||
int in_use;
|
||||
struct db_entry *left;
|
||||
CODEADDR lim;
|
||||
struct db_entry *right;
|
||||
} *dbentry;
|
||||
|
||||
static ADDR db_vec, db_vec0;
|
||||
|
||||
typedef struct RB_red_blk_node {
|
||||
CODEADDR key;
|
||||
CODEADDR lim;
|
||||
db_entry_type db_type;
|
||||
int in_use;
|
||||
int red; /* if red=0 then the node is black */
|
||||
struct RB_red_blk_node* left;
|
||||
struct RB_red_blk_node* right;
|
||||
struct RB_red_blk_node* parent;
|
||||
} rb_red_blk_node;
|
||||
|
||||
static rb_red_blk_node *db_root, *db_nil;
|
||||
|
||||
static rb_red_blk_node *
|
||||
RBMalloc(UInt size)
|
||||
{
|
||||
@ -3336,12 +3335,12 @@ icompact_heap(void)
|
||||
|
||||
#ifdef EASY_SHUNTING
|
||||
static void
|
||||
set_conditionals(tr_fr_ptr sTR) {
|
||||
while (sTR != sTR0) {
|
||||
set_conditionals(tr_fr_ptr str) {
|
||||
while (str != sTR0) {
|
||||
CELL *cptr;
|
||||
sTR -= 2;
|
||||
cptr = (CELL *)TrailTerm(sTR+1);
|
||||
*cptr = TrailTerm(sTR);
|
||||
str -= 2;
|
||||
cptr = (CELL *)TrailTerm(str+1);
|
||||
*cptr = TrailTerm(str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -3589,12 +3588,12 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
#if GC_NO_TAGS
|
||||
{
|
||||
UInt alloc_sz = (CELL *)Yap_TrailTop-(CELL*)Yap_GlobalBase;
|
||||
bp = Yap_PreAllocCodeSpace();
|
||||
while (bp+alloc_sz > (char *)AuxSp) {
|
||||
Yap_bp = Yap_PreAllocCodeSpace();
|
||||
while (Yap_bp+alloc_sz > (char *)AuxSp) {
|
||||
/* not enough space */
|
||||
*--ASP = (CELL)current_env;
|
||||
bp = (char *)Yap_ExpandPreAllocCodeSpace(alloc_sz, NULL);
|
||||
if (!bp)
|
||||
Yap_bp = (char *)Yap_ExpandPreAllocCodeSpace(alloc_sz, NULL);
|
||||
if (!Yap_bp)
|
||||
return 0;
|
||||
current_env = (CELL *)*ASP;
|
||||
ASP++;
|
||||
@ -3602,7 +3601,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
max = (CELL *)DelayTop();
|
||||
#endif
|
||||
}
|
||||
memset((void *)bp, 0, alloc_sz);
|
||||
memset((void *)Yap_bp, 0, alloc_sz);
|
||||
}
|
||||
#endif /* GC_NO_TAGS */
|
||||
if (setjmp(Yap_gc_restore) == 2) {
|
||||
@ -3651,7 +3650,9 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
if (!b_ptr) HGEN = H0;
|
||||
}
|
||||
/* fprintf(stderr,"HGEN is %ld, %p, %p/%p\n", IntegerOfTerm(Yap_ReadTimedVar(GcGeneration)), HGEN, H,H0);*/
|
||||
#if !GC_TAGS
|
||||
YAPEnterCriticalSection();
|
||||
#endif
|
||||
OldTR = (tr_fr_ptr)(old_TR = TR);
|
||||
push_registers(predarity, nextop);
|
||||
marking_phase(old_TR, current_env, nextop, max);
|
||||
@ -3695,7 +3696,9 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
TR = old_TR;
|
||||
pop_registers(predarity, nextop);
|
||||
TR = new_TR;
|
||||
#if !GC_TAGS
|
||||
YAPLeaveCriticalSection();
|
||||
#endif
|
||||
/* fprintf(Yap_stderr,"NEW HGEN %ld (%ld)\n", H-H0, HGEN-H0);*/
|
||||
Yap_UpdateTimedVar(GcGeneration, MkIntegerTerm(H-H0));
|
||||
c_time = Yap_cputime();
|
||||
|
51
H/Heap.h
51
H/Heap.h
@ -10,7 +10,7 @@
|
||||
* File: Heap.h *
|
||||
* mods: *
|
||||
* comments: Heap Init Structure *
|
||||
* version: $Id: Heap.h,v 1.87 2005-12-05 17:16:11 vsc Exp $ *
|
||||
* version: $Id: Heap.h,v 1.88 2005-12-07 17:53:30 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
/* information that can be stored in Code Space */
|
||||
@ -24,6 +24,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define GC_MAVARS_HASH_SIZE 512
|
||||
|
||||
typedef struct gc_ma_hash_entry_struct {
|
||||
UInt timestmp;
|
||||
CELL* addr;
|
||||
struct gc_ma_hash_entry_struct *next;
|
||||
} gc_ma_hash_entry;
|
||||
|
||||
typedef struct atom_hash_entry {
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
rwlock_t AERWLock;
|
||||
@ -99,12 +107,29 @@ typedef struct worker_local_struct {
|
||||
unsigned long int tot_smarked;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef EASY_SHUNTING
|
||||
struct choicept *wl_current_B;
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
struct trail_frame *wl_sTR, *wl_sTR0;
|
||||
struct trail_frame *new_tr;
|
||||
#else
|
||||
Term *wl_sTR, *wl_sTR0;
|
||||
Term *new_tr;
|
||||
#endif
|
||||
CELL *wl_prev_HB;
|
||||
CELL *hgen;
|
||||
CELL **ip_top;
|
||||
#if GC_NO_TAGS
|
||||
char *b_p;
|
||||
#endif
|
||||
#endif
|
||||
struct gc_mark_continuation *conttop0;
|
||||
struct gc_mark_continuation *conttop;
|
||||
int disc_trail_entries;
|
||||
gc_ma_hash_entry Gc_ma_hash_table[GC_MAVARS_HASH_SIZE];
|
||||
gc_ma_hash_entry *Gc_ma_h_top;
|
||||
UInt Gc_timestamp; /* an unsigned int */
|
||||
ADDR DB_vec, DB_vec0;
|
||||
struct RB_red_blk_node *DB_root, *DB_nil;
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
jmp_buf gc_restore; /* where to jump if garbage collection crashes */
|
||||
struct array_entry *dynamic_arrays;
|
||||
struct static_array_entry *static_arrays;
|
||||
@ -763,13 +788,27 @@ struct various_codes *Yap_heap_regs;
|
||||
#ifdef COROUTINING
|
||||
#define total_smarked Yap_heap_regs->wl[worker_id].tot_smarked
|
||||
#endif
|
||||
#endif
|
||||
#ifdef EASY_SHUNTING
|
||||
#endif /* DEBUG */
|
||||
#define current_B Yap_heap_regs->wl[worker_id].wl_current_B
|
||||
#define sTR Yap_heap_regs->wl[worker_id].wl_sTR
|
||||
#define sTR0 Yap_heap_regs->wl[worker_id].wl_sTR0
|
||||
#define prev_HB Yap_heap_regs->wl[worker_id].wl_prev_HB
|
||||
#endif
|
||||
#define new_TR Yap_heap_regs->wl[worker_id].new_tr
|
||||
#define HGEN Yap_heap_regs->wl[worker_id].hgen
|
||||
#define iptop Yap_heap_regs->wl[worker_id].ip_top
|
||||
#define discard_trail_entries Yap_heap_regs->wl[worker_id].disc_trail_entries
|
||||
#if GC_NO_TAGS
|
||||
#define Yap_bp Yap_heap_regs->wl[worker_id].b_p
|
||||
#endif /* GC_NO_TAGS */
|
||||
#define gc_ma_hash_table Yap_heap_regs->wl[worker_id].Gc_ma_hash_table
|
||||
#define gc_ma_h_top Yap_heap_regs->wl[worker_id].Gc_ma_h_top
|
||||
#define gc_timestamp Yap_heap_regs->wl[worker_id].Gc_timestamp
|
||||
#define cont_top0 Yap_heap_regs->wl[worker_id].conttop0
|
||||
#define db_vec Yap_heap_regs->wl[worker_id].DB_vec
|
||||
#define db_vec0 Yap_heap_regs->wl[worker_id].DB_vec0
|
||||
#define db_root Yap_heap_regs->wl[worker_id].DB_root
|
||||
#define db_nil Yap_heap_regs->wl[worker_id].DB_nil
|
||||
#define cont_top Yap_heap_regs->wl[worker_id].conttop
|
||||
#define Yap_gc_restore Yap_heap_regs->wl[worker_id].gc_restore
|
||||
#define TrustLUCode Yap_heap_regs->wl[worker_id].trust_lu_code
|
||||
#define DynamicArrays Yap_heap_regs->wl[worker_id].dynamic_arrays
|
||||
|
@ -89,12 +89,14 @@
|
||||
|
||||
#if GC_NO_TAGS
|
||||
|
||||
extern char *bp;
|
||||
#if !defined(YAPOR) && !defined(THREADS)
|
||||
extern char *Yap_bp;
|
||||
#endif
|
||||
|
||||
#define MARK_BIT 1
|
||||
#define RMARK_BIT 2
|
||||
|
||||
#define mcell(X) bp[X-(CELL *)Yap_GlobalBase]
|
||||
#define mcell(X) Yap_bp[X-(CELL *)Yap_GlobalBase]
|
||||
|
||||
static inline Int
|
||||
MARKED_PTR(CELL* ptr)
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
<h2>Yap-5.1.0:</h2>
|
||||
<ul>
|
||||
<li> NEW: heapgc should now be concurrent when using threads. </li>
|
||||
<li> FIXED: heapgc wo tags can handle trail overflows right. </li>
|
||||
<li> NEW: heapgc wo tags does not write on the collected areas during marking. </li>
|
||||
<li> FIXED: dif/2 might get into trouble restoring assignments to
|
||||
|
Reference in New Issue
Block a user