Back to index

plt-scheme  4.2.1
Functions | Variables
mallocx.c File Reference
#include <stdio.h>
#include "private/gc_priv.h"

Go to the source code of this file.

Functions

ptr_t GC_clear_stack ()
void GC_extend_size_map ()
GC_bool GC_alloc_reclaim_list ()
GC_PTR GC_generic_or_special_malloc (word lb, int knd)
GC_PTR GC_realloc (GC_PTR p, size_t lb)
ptr_t GC_generic_malloc_ignore_off_page (size_t lb, int k)
char * GC_malloc_ignore_off_page (size_t lb)
char * GC_malloc_atomic_ignore_off_page (size_t lb)
ptr_t GC_generic_malloc_words_small_inner (word lw, int k)
ptr_t GC_generic_malloc_words_small (word lw, int k)
GC_PTR GC_malloc_uncollectable (size_t lb)

Variables

ptr_t *GC_CONST GC_objfreelist_ptr = GC_objfreelist
ptr_t *GC_CONST GC_aobjfreelist_ptr = GC_aobjfreelist
ptr_t *GC_CONST GC_uobjfreelist_ptr = GC_uobjfreelist

Function Documentation

Definition at line 178 of file mallocx.c.

{
    register ptr_t result;
    word lw;
    word n_blocks;
    GC_bool init;
    DCL_LOCK_STATE;
    
    if (SMALL_OBJ(lb))
        return(GC_generic_malloc((word)lb, k));
    lw = ROUNDED_UP_WORDS(lb);
    n_blocks = OBJ_SZ_TO_BLOCKS(lw);
    init = GC_obj_kinds[k].ok_init;
    if (GC_have_errors) GC_print_all_errors();
    GC_INVOKE_FINALIZERS();
    DISABLE_SIGNALS();
    LOCK();
    result = (ptr_t)GC_alloc_large(lw, k, IGNORE_OFF_PAGE);
    if (0 != result) {
        if (GC_debugging_started) {
           BZERO(result, n_blocks * HBLKSIZE);
        } else {
#           ifdef THREADS
             /* Clear any memory that might be used for GC descriptors */
             /* before we release the lock.                          */
               ((word *)result)[0] = 0;
               ((word *)result)[1] = 0;
               ((word *)result)[lw-1] = 0;
               ((word *)result)[lw-2] = 0;
#          endif
        }
    }
    GC_words_allocd += lw;
    UNLOCK();
    ENABLE_SIGNALS();
    if (0 == result) {
        return((*GC_oom_fn)(lb));
    } else {
       if (init && !GC_debugging_started) {
           BZERO(result, n_blocks * HBLKSIZE);
        }
        return(result);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 295 of file mallocx.c.

Here is the call graph for this function:

Definition at line 262 of file mallocx.c.

{
register ptr_t op;
register ptr_t *opp;
register struct obj_kind * kind = GC_obj_kinds + k;

    opp = &(kind -> ok_freelist[lw]);
    if( (op = *opp) == 0 ) {
        if (!GC_is_initialized) {
            GC_init_inner();
        }
       if (kind -> ok_reclaim_list != 0 || GC_alloc_reclaim_list(kind)) {
           op = GC_clear_stack(GC_allocobj((word)lw, k));
       }
       if (op == 0) {
           UNLOCK();
           ENABLE_SIGNALS();
           return ((*GC_oom_fn)(WORDS_TO_BYTES(lw)));
       }
    }
    *opp = obj_link(op);
    obj_link(op) = 0;
    GC_words_allocd += lw;
    return((ptr_t)op);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 42 of file mallocx.c.

{
    switch(knd) {
#     ifdef STUBBORN_ALLOC
       case STUBBORN:
           return(GC_malloc_stubborn((size_t)lb));
#     endif
       case PTRFREE:
           return(GC_malloc_atomic((size_t)lb));
       case NORMAL:
           return(GC_malloc((size_t)lb));
       case UNCOLLECTABLE:
           return(GC_malloc_uncollectable((size_t)lb));
#       ifdef ATOMIC_UNCOLLECTABLE
         case AUNCOLLECTABLE:
           return(GC_malloc_atomic_uncollectable((size_t)lb));
#      endif /* ATOMIC_UNCOLLECTABLE */
       default:
           return(GC_generic_malloc(lb,knd));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* GC_malloc_atomic_ignore_off_page ( size_t  lb)

Definition at line 238 of file mallocx.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* GC_malloc_ignore_off_page ( size_t  lb)

Definition at line 228 of file mallocx.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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);
    }
}
GC_PTR GC_realloc ( GC_PTR  p,
size_t  lb 
)

Definition at line 74 of file mallocx.c.

{
register struct hblk * h;
register hdr * hhdr;
register word sz;     /* Current size in bytes   */
register word orig_sz;       /* Original sz in bytes    */
int obj_kind;

    if (p == 0) return(GC_malloc(lb));    /* Required by ANSI */
    h = HBLKPTR(p);
    hhdr = HDR(h);
    sz = hhdr -> hb_sz;
    obj_kind = hhdr -> hb_obj_kind;
    sz = WORDS_TO_BYTES(sz);
    orig_sz = sz;

    if (sz > MAXOBJBYTES) {
       /* Round it up to the next whole heap block */
         register word descr;
         
         sz = (sz+HBLKSIZE-1) & (~HBLKMASK);
         hhdr -> hb_sz = BYTES_TO_WORDS(sz);
         descr = GC_obj_kinds[obj_kind].ok_descriptor;
          if (GC_obj_kinds[obj_kind].ok_relocate_descr) descr += sz;
          hhdr -> hb_descr = descr;
         if (IS_UNCOLLECTABLE(obj_kind)) GC_non_gc_bytes += (sz - orig_sz);
         /* Extra area is already cleared by GC_alloc_large_and_clear. */
    }
    if (ADD_SLOP(lb) <= sz) {
       if (lb >= (sz >> 1)) {
#          ifdef STUBBORN_ALLOC
               if (obj_kind == STUBBORN) GC_change_stubborn(p);
#          endif
           if (orig_sz > lb) {
             /* Clear unneeded part of object to avoid bogus pointer */
             /* tracing.                                      */
             /* Safe for stubborn objects.                           */
               BZERO(((ptr_t)p) + lb, orig_sz - lb);
           }
           return(p);
       } else {
           /* shrink */
             GC_PTR result =
                     GC_generic_or_special_malloc((word)lb, obj_kind);

             if (result == 0) return(0);
                 /* Could also return original object.  But this      */
                 /* gives the client warning of imminent disaster.    */
             BCOPY(p, result, lb);
#            ifndef IGNORE_FREE
               GC_free(p);
#            endif
             return(result);
       }
    } else {
       /* grow */
         GC_PTR result =
              GC_generic_or_special_malloc((word)lb, obj_kind);

         if (result == 0) return(0);
         BCOPY(p, result, sz);
#        ifndef IGNORE_FREE
           GC_free(p);
#        endif
         return(result);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 35 of file mallocx.c.

Definition at line 34 of file mallocx.c.

Definition at line 36 of file mallocx.c.