Back to index

plt-scheme  4.2.1
Defines | Typedefs | Functions | Variables
sgc.h File Reference
#include <stddef.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define GC_PTR   void*
#define SGC_ATOMIC_SET   1
#define SGC_UNCOLLECTABLE_SET   2

Typedefs

typedef void(* GC_collect_start_callback_Proc )(void)
typedef void(* GC_collect_end_callback_Proc )(void)
typedef void(* GC_count_tracer )(void *v, int)
typedef void(* GC_path_tracer )(void *v, unsigned long src, void *pdata)
typedef void(* GC_trace_init )(void)
typedef void(* GC_trace_done )(void)
typedef void(* GC_set_elem_finalizer )(void *p)

Functions

void GC_add_roots (void *start, void *end)
void GC_set_stack_base (void *base)
voidGC_get_stack_base (void)
voidGC_base (void *)
void GC_dump (void)
long GC_get_memory_use ()
void GC_end_stubborn_change (void *)
void GC_gcollect (void)
voidGC_malloc (size_t size_in_bytes)
voidGC_malloc_atomic (size_t size_in_bytes)
voidGC_malloc_stubborn (size_t size_in_bytes)
voidGC_malloc_uncollectable (size_t size_in_bytes)
voidGC_malloc_atomic_uncollectable (size_t size_in_bytes)
GC_collect_start_callback_Proc GC_set_collect_start_callback (GC_collect_start_callback_Proc)
GC_collect_end_callback_Proc GC_set_collect_end_callback (GC_collect_end_callback_Proc)
void GC_free (void *)
voidGC_malloc_specific (size_t size, struct GC_Set *set)
void GC_general_register_disappearing_link (void **p, void *a)
void GC_register_late_disappearing_link (void **p, void *a)
void GC_unregister_disappearing_link (void **p)
void GC_register_finalizer (void *p, void(*f)(void *p, void *data), void *data, void(**oldf)(void *p, void *data), void **olddata)
void GC_register_finalizer_ignore_self (void *p, void(*f)(void *p, void *data), void *data, void(**oldf)(void *p, void *data), void **olddata)
void GC_register_eager_finalizer (void *p, int level, void(*f)(void *p, void *data), void *data, void(**oldf)(void *p, void *data), void **olddata)
struct GC_SetGC_new_set (char *name, GC_trace_init init, GC_trace_init done, GC_count_tracer count_tracer, GC_path_tracer path_tracer, GC_set_elem_finalizer final, int flags)
struct GC_SetGC_set (void *d)
void GC_for_each_element (struct GC_Set *set, void(*f)(void *p, int size, void *data), void *data)
int GC_trace_count (int *stack, int *roots, int *uncollectable, int *final)
void GC_trace_path (void)
void GC_store_path (void *v, unsigned long src, void *path_data)
void ** GC_get_next_path (void **prev, int *len)
void GC_clear_paths ()

Variables

void(* GC_start_collect_callback )(void)
void(* GC_end_collect_callback )(void)
void(* GC_custom_finalize )(void)
void(* GC_out_of_memory )(void)
voidGC_initial_trace_root
int(* GC_inital_root_skip )(void *, size_t)

Define Documentation

#define GC_PTR   void*

Definition at line 8 of file sgc.h.

#define SGC_ATOMIC_SET   1

Definition at line 69 of file sgc.h.

#define SGC_UNCOLLECTABLE_SET   2

Definition at line 70 of file sgc.h.


Typedef Documentation

Definition at line 40 of file sgc.h.

Definition at line 39 of file sgc.h.

typedef void(* GC_count_tracer)(void *v, int)

Definition at line 63 of file sgc.h.

typedef void(* GC_path_tracer)(void *v, unsigned long src, void *pdata)

Definition at line 64 of file sgc.h.

Definition at line 67 of file sgc.h.

typedef void(* GC_trace_done)(void)

Definition at line 66 of file sgc.h.

typedef void(* GC_trace_init)(void)

Definition at line 65 of file sgc.h.


Function Documentation

void GC_add_roots ( void start,
void end 
)

Definition at line 211 of file copy.c.

{
  if (roots_count >= roots_size) {
    unsigned long *naya;

    roots_size = roots_size ? 2 * roots_size : 500;
    naya = (unsigned long *)malloc(sizeof(unsigned long) * (roots_size + 1));

    memcpy((void *)naya, (void *)roots, 
          sizeof(unsigned long) * roots_count);

    if (roots)
      free(roots);

    roots = naya;
  }

  roots[roots_count++] = PTR_TO_INT(start);
  roots[roots_count++] = PTR_TO_INT(end) - PTR_ALIGNMENT;
}

Here is the call graph for this function:

void* GC_base ( void )

Definition at line 1741 of file sgc.c.

{
  void *p;

  p = find_ptr(d, NULL, NULL, NULL, NULL, 0);

#if PAD_BOUNDARY_BYTES
  if (p)
    p = PAD_FORWARD(p);
#endif
  
  return p;
}

Definition at line 4888 of file sgc.c.

{
#if ALLOW_TRACE_PATH
  int i;

  for (i = 0; i < TRACE_PATH_BUFFER_SIZE; i++)
    trace_path_buffer[i] = NULL;
#endif
}

Here is the caller graph for this function:

void GC_dump ( void  )

Definition at line 1171 of file misc.c.

{
    GC_printf0("***Static roots:\n");
    GC_print_static_roots();
    GC_printf0("\n***Heap sections:\n");
    GC_print_heap_sects();
    GC_printf0("\n***Free blocks:\n");
    GC_print_hblkfreelist();
    GC_printf0("\n***Blocks in use:\n");
    GC_print_block_list();
    GC_printf0("\n***Finalization statistics:\n");
    GC_print_finalization_stats();
}

Definition at line 2114 of file sgc.c.

{
  /* stubborness is not exploited */
}
void GC_for_each_element ( struct GC_Set set,
void(*)(void *p, int size, void *data f,
void data 
)

Definition at line 2868 of file sgc.c.

{
  int i;
  BlockOfMemory **blocks = set->blocks;
  MemoryChunk *c = *(set->othersptr);

#if ALLOW_SET_LOCKING
  if (!set->uncollectable)
    set->locked++;
#endif

  for (i = 0; i < NUM_COMMON_SIZE; i++) {
    BlockOfMemory **prev = &blocks[i];
    BlockOfMemory *block = *prev;

    while (block) {
      int j;

      j = (block->top - block->start) / block->size;
      
      while (j--) {
       int bit = POS_TO_FREE_BIT(j);
       int pos = POS_TO_FREE_INDEX(j);
       
       if (IS_MARKED(block->free[pos] & bit)) {
         unsigned long p;
         void *s;
         
         p = block->start + (block->size * j);
         s = INT_TO_PTR(p);
         
#if PAD_BOUNDARY_BYTES
         s = PAD_FORWARD(s);
#endif
         
         f(s, block->size, data);
       }
      }
      block = block->next;
    }
  }

  for (; c; c = c->next) {
    void *s;

    s = INT_TO_PTR(c->start);

#if PAD_BOUNDARY_BYTES
    s = PAD_FORWARD(s);
#endif

    f(s, c->end - c->start, data);
  }

#if ALLOW_SET_LOCKING
  if (!set->uncollectable)
    --set->locked;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GC_free ( void )

Definition at line 4034 of file compact.c.

{
  MPage *page;

  page = find_page(p);

  if ((page->flags & MFLAG_BIGBLOCK)
      && !(page->flags & MFLAG_CONTINUED)
      && (p == page->block_start)) {
    memory_in_use -= page->u.size;

    if (page->prev)
      page->prev->next = page->next;
    else
      first = page->next;
    if (page->next)
      page->next->prev = page->prev;
    else
      last = page->prev;

    free_bigpage(page);
  }
}

Here is the call graph for this function:

Definition at line 4063 of file compact.c.

{
  gcollect(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2744 of file sgc.c.

Here is the call graph for this function:

Definition at line 1198 of file misc.c.

{
  long c = 0;
  LOCK();
  GC_apply_to_all_blocks(get_size, (word)&c);
  UNLOCK();
  return c;
}
void** GC_get_next_path ( void **  prev,
int len 
)

Definition at line 4868 of file sgc.c.

{
#if ALLOW_TRACE_PATH
  void **p;

  if (!prev)
    p = trace_path_buffer;
  else
    p = prev + (2 * (((long *)prev)[-1]));
    
  *len = *(long *)p;
  if (!*len)
    return NULL;

  return p + 1;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

Definition at line 43 of file AmigaOS.c.

{
    struct Process *proc = (struct Process*)SysBase->ThisTask;
 
    /* Reference: Amiga Guru Book Pages: 42,567,574 */
    if (proc->pr_Task.tc_Node.ln_Type==NT_PROCESS
        && proc->pr_CLI != NULL) {
       /* first ULONG is StackSize */
       /*longPtr = proc->pr_ReturnAddr;
       size = longPtr[0];*/

       return (char *)proc->pr_ReturnAddr + sizeof(ULONG);
    } else {
       return (char *)proc->pr_Task.tc_SPUpper;
    }
}
void* GC_malloc ( size_t  size_in_bytes)

Definition at line 300 of file malloc.c.

{
register ptr_t op;
register ptr_t *opp;
register word lw;
DCL_LOCK_STATE;

    if( EXPECT(SMALL_OBJ(lb), 1) ) {
#       ifdef MERGE_SIZES
         lw = GC_size_map[lb];
#      else
         lw = ALIGNED_WORDS(lb);
#       endif
       opp = &(GC_objfreelist[lw]);
       FASTLOCK();
        if( EXPECT(!FASTLOCK_SUCCEEDED() || (op = *opp) == 0, 0) ) {
            FASTUNLOCK();
            return(GENERAL_MALLOC((word)lb, NORMAL));
        }
        /* See above comment on signals.  */
       GC_ASSERT(0 == obj_link(op)
                || (word)obj_link(op)
                     <= (word)GC_greatest_plausible_heap_addr
                   && (word)obj_link(op)
                     >= (word)GC_least_plausible_heap_addr);
        *opp = obj_link(op);
        obj_link(op) = 0;
        GC_words_allocd += lw;
        FASTUNLOCK();
        return((GC_PTR) op);
   } else {
       return(GENERAL_MALLOC((word)lb, NORMAL));
   }
}
void* GC_malloc_atomic ( size_t  size_in_bytes)

Definition at line 245 of file malloc.c.

{
register ptr_t op;
register ptr_t * opp;
register word lw;
DCL_LOCK_STATE;

    if( EXPECT(SMALL_OBJ(lb), 1) ) {
#       ifdef MERGE_SIZES
         lw = GC_size_map[lb];
#      else
         lw = ALIGNED_WORDS(lb);
#       endif
       opp = &(GC_aobjfreelist[lw]);
       FASTLOCK();
        if( EXPECT(!FASTLOCK_SUCCEEDED() || (op = *opp) == 0, 0) ) {
            FASTUNLOCK();
            return(GENERAL_MALLOC((word)lb, PTRFREE));
        }
        /* See above comment on signals.  */
        *opp = obj_link(op);
        GC_words_allocd += lw;
        FASTUNLOCK();
        return((GC_PTR) op);
   } else {
       return(GENERAL_MALLOC((word)lb, PTRFREE));
   }
}
void* GC_malloc_atomic_uncollectable ( size_t  size_in_bytes)

Definition at line 3997 of file compact.c.

{
  void *p;
  p = malloc(size_in_bytes);
  memset(p, 0, size_in_bytes);
  return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* GC_malloc_specific ( size_t  size,
struct GC_Set set 
)

Definition at line 2653 of file sgc.c.

Here is the call graph for this function:

void* GC_malloc_stubborn ( size_t  size_in_bytes)

Definition at line 303 of file stubborn.c.

{
    return(GC_malloc(lb));
}
void* GC_malloc_uncollectable ( size_t  size_in_bytes)

Definition at line 538 of file mallocx.c.

{
register ptr_t op;
register ptr_t *opp;
register word lw;
DCL_LOCK_STATE;

    if( SMALL_OBJ(lb) ) {
#       ifdef MERGE_SIZES
         if (EXTRA_BYTES != 0 && lb != 0) lb--;
                /* We don't need the extra byte, since this won't be  */
                /* collected anyway.                                  */
         lw = GC_size_map[lb];
#      else
         lw = ALIGNED_WORDS(lb);
#       endif
       opp = &(GC_uobjfreelist[lw]);
       FASTLOCK();
        if( FASTLOCK_SUCCEEDED() && (op = *opp) != 0 ) {
            /* See above comment on signals.     */
            *opp = obj_link(op);
            obj_link(op) = 0;
            GC_words_allocd += lw;
            /* Mark bit ws already set on free list.  It will be      */
           /* cleared only temporarily during a collection, as a      */
           /* result of the normal free list mark bit clearing.       */
            GC_non_gc_bytes += WORDS_TO_BYTES(lw);
            FASTUNLOCK();
            return((GC_PTR) op);
        }
        FASTUNLOCK();
        op = (ptr_t)GC_generic_malloc((word)lb, UNCOLLECTABLE);
    } else {
       op = (ptr_t)GC_generic_malloc((word)lb, UNCOLLECTABLE);
    }
    if (0 == op) return(0);
    /* We don't need the lock here, since we have an undisguised      */
    /* pointer.  We do need to hold the lock while we adjust          */
    /* mark bits.                                              */
    {
       register struct hblk * h;
       
       h = HBLKPTR(op);
       lw = HDR(h) -> hb_sz;
       
       DISABLE_SIGNALS();
       LOCK();
       GC_set_mark_bit(op);
       GC_non_gc_bytes += WORDS_TO_BYTES(lw);
       UNLOCK();
       ENABLE_SIGNALS();
       return((GC_PTR) op);
    }
}
struct GC_Set* GC_new_set ( char *  name,
GC_trace_init  init,
GC_trace_init  done,
GC_count_tracer  count_tracer,
GC_path_tracer  path_tracer,
GC_set_elem_finalizer  final,
int  flags 
) [read]

Definition at line 2564 of file sgc.c.

{
  GC_Set *c, **naya;
  int i;

  if (!initialized)
    GC_initialize();

  c = (GC_Set *)malloc_managed(sizeof(GC_SetWithOthers));

  naya = (GC_Set **)malloc_managed(sizeof(GC_Set *) * (num_common_sets + 1));
  for (i = 0; i < num_common_sets; i++)
    naya[i] = common_sets[i];
  
#if KEEP_SET_NO || KEEP_CHUNK_SET_NO
  c->no = num_common_sets;
#endif
#if ALLOW_TRACE_COUNT
  c->count_tracer = count_tracer;
#endif
#if ALLOW_TRACE_PATH
  c->path_tracer = path_tracer;
#endif
#if ALLOW_TRACE_COUNT || ALLOW_TRACE_PATH
  c->trace_init = trace_init;
  c->trace_done = trace_done;
#endif
#if ALLOW_SET_FINALIZER
  c->finalizer = final;
#endif    

  naya[num_common_sets++] = c;
  c->atomic = !!(flags & SGC_ATOMIC_SET);
  c->uncollectable = !!(flags & SGC_UNCOLLECTABLE_SET);
#if ALLOW_SET_LOCKING
  c->locked = 0;
#endif
  c->name = name;
  c->blocks = (BlockOfMemory **)malloc_managed(sizeof(BlockOfMemory*) * 2 * NUM_COMMON_SIZE);
  memset(c->blocks, 0, sizeof(BlockOfMemory*) * NUM_COMMON_SIZE);
  c->block_ends = c->blocks + NUM_COMMON_SIZE;
  memset(c->block_ends, 0, sizeof(BlockOfMemory*) * NUM_COMMON_SIZE);

  ((GC_SetWithOthers *)c)->others = NULL;
  c->othersptr = &((GC_SetWithOthers *)c)->others;

  free_managed(common_sets);
  common_sets = naya;

  return c;
}

Here is the call graph for this function:

void GC_register_eager_finalizer ( void p,
int  level,
void(*)(void *p, void *data f,
void data,
void(**)(void *p, void *data oldf,
void **  olddata 
)

Definition at line 2852 of file sgc.c.

{
  register_finalizer(PAD_BACKWARD(p), f, data, oldf, olddata, level, 0);
}

Here is the call graph for this function:

void GC_register_finalizer ( void p,
void(*)(void *p, void *data f,
void data,
void(**)(void *p, void *data oldf,
void **  olddata 
)

Definition at line 2845 of file sgc.c.

{
  register_finalizer(PAD_BACKWARD(p), f, data, oldf, olddata, 0, 0);
}

Here is the call graph for this function:

void GC_register_finalizer_ignore_self ( void p,
void(*)(void *p, void *data f,
void data,
void(**)(void *p, void *data oldf,
void **  olddata 
)

Definition at line 2859 of file sgc.c.

{
  register_finalizer(PAD_BACKWARD(p), f, data, oldf, olddata, 0, 1);
}

Here is the call graph for this function:

Definition at line 158 of file finalize.c.

struct GC_Set* GC_set ( void d) [read]

Definition at line 1800 of file sgc.c.

{
#if KEEP_SET_NO
  BlockOfMemory *block = NULL;
  MemoryChunk *chunk = NULL;
  
  if (!initialized)
    GC_initialize();

  if (find_ptr(d, NULL, &block, NULL, &chunk, 0)) {
    int set_no;
    if (block)
      set_no = block->set_no;
    else
      set_no = chunk->set_no;

    return common_sets[set_no];
  } else
    return NULL;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 331 of file alloc.c.

Here is the caller graph for this function:

Definition at line 325 of file alloc.c.

Here is the caller graph for this function:

Definition at line 448 of file compact.c.

{
  stack_base = (unsigned long)base;
}

Here is the caller graph for this function:

void GC_store_path ( void v,
unsigned long  src,
void path_data 
)

Definition at line 4812 of file sgc.c.

{
  /* Note: a trace path of the form X->X->Y->Z->... (with two Xs)
     indicates an off-by-one stack source. */
#if ALLOW_TRACE_PATH
  TraceStack *s = (TraceStack *)path_data;
  int len, i;

  if (trace_path_buffer_pos < 0)
    return;

  len = s->count / 3;
  if (len * 2 + 3 > (TRACE_PATH_BUFFER_SIZE - trace_path_buffer_pos - 7)) {
    trace_path_buffer[trace_path_buffer_pos++] = (void *)2;
    trace_path_buffer[trace_path_buffer_pos++] = "truncated";
    trace_path_buffer[trace_path_buffer_pos++] = 0;
    trace_path_buffer[trace_path_buffer_pos++] = v; /* already padded */
    trace_path_buffer[trace_path_buffer_pos++] = 0;
    trace_path_buffer[trace_path_buffer_pos] = 0;
    trace_path_buffer_pos = -1;
    return;
  }

  if (len) {
    unsigned long prev = 0;

    trace_path_buffer[trace_path_buffer_pos++] = (void *)(len + 2);
    trace_path_buffer[trace_path_buffer_pos++] = current_trace_source;
    trace_path_buffer[trace_path_buffer_pos++] = 0;
    for (i = 1; len--; i += 3) {
      trace_path_buffer[trace_path_buffer_pos++] = (void *)PAD_FORWARD(s->stack[i]);
      trace_path_buffer[trace_path_buffer_pos++] = 0; /* reset on next iteration */

      if (i > 1) {
       /* See if we have offset information in the original trace info.
          (It might be missing because KEEP_DETAIL might be turned off, or
            PUSH_COLLECT had 0 for its third argument.) */
       unsigned long diff;
       if (s->stack[i + 1])
         diff = ((unsigned long)s->stack[i + 1]) - prev;
       else
         diff = 0;
       trace_path_buffer[trace_path_buffer_pos - 3] = (void *)diff;
      }
      prev = (unsigned long)s->stack[i];
    }

    trace_path_buffer[trace_path_buffer_pos - 1] = (void *)(src - prev);

    trace_path_buffer[trace_path_buffer_pos++] = v; /* already padded */
    trace_path_buffer[trace_path_buffer_pos++] = 0;
    trace_path_buffer[trace_path_buffer_pos] = 0;
  }
#endif
}
int GC_trace_count ( int stack,
int roots,
int uncollectable,
int final 
)

Definition at line 4749 of file sgc.c.

{
#if ALLOW_TRACE_COUNT
  int j;

  if (!sector_mem_use)
    return 0;

  for (j = 0; j < num_common_sets; j++) {
    if (common_sets[j]->trace_init)
      common_sets[j]->trace_init();
  }

  collecting_with_trace_count = 1;
  GC_gcollect();
  collecting_with_trace_count = 0;

  if (stack)
    *stack = traced_from_stack;
  if (roots)
    *roots = traced_from_roots;
  if (uncollectable)
    *uncollectable = traced_from_uncollectable;
  if (final)
    *final = traced_from_finals;

  for (j = 0; j < num_common_sets; j++) {
    if (common_sets[j]->trace_done)
      common_sets[j]->trace_done();
  }

  return mem_traced;
#else
  return 0;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4786 of file sgc.c.

{
#if ALLOW_TRACE_PATH
  int j;

  if (!sector_mem_use)
    return;

  for (j = 0; j < num_common_sets; j++) {
    if (common_sets[j]->trace_init)
      common_sets[j]->trace_init();
  }

  trace_path_buffer_pos = 0;

  collecting_with_trace_path = 1;
  GC_gcollect();
  collecting_with_trace_path = 0;

  for (j = 0; j < num_common_sets; j++) {
    if (common_sets[j]->trace_done)
      common_sets[j]->trace_done();
  }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2754 of file sgc.c.

{
  /* We'll do it later */
}

Variable Documentation

Definition at line 37 of file finalize.c.

int(* GC_inital_root_skip)(void *, size_t)

Definition at line 464 of file sgc.c.

Definition at line 463 of file sgc.c.

Definition at line 2893 of file mred.cxx.