Back to index

plt-scheme  4.2.1
gc_local_alloc.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2000 by Hewlett-Packard Company.  All rights reserved.
00003  *
00004  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00005  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00006  *
00007  * Permission is hereby granted to use or copy this program
00008  * for any purpose,  provided the above notices are retained on all copies.
00009  * Permission to modify the code and to distribute modified code is granted,
00010  * provided the above notices are retained, and a notice that the code was
00011  * modified is included with the above copyright notice.
00012  */
00013 
00014 /*
00015  * Interface for thread local allocation.  Memory obtained
00016  * this way can be used by all threads, as though it were obtained
00017  * from an allocator like GC_malloc.  The difference is that GC_local_malloc
00018  * counts the number of allocations of a given size from the current thread,
00019  * and uses GC_malloc_many to perform the allocations once a threashold
00020  * is exceeded.  Thus far less synchronization may be needed.
00021  * Allocation of known large objects should not use this interface.
00022  * This interface is designed primarily for fast allocation of small
00023  * objects on multiprocessors, e.g. for a JVM running on an MP server.
00024  *
00025  * If this file is included with GC_GCJ_SUPPORT defined, GCJ-style
00026  * bitmap allocation primitives will also be included.
00027  *
00028  * If this file is included with GC_REDIRECT_TO_LOCAL defined, then
00029  * GC_MALLOC, GC_MALLOC_ATOMIC, and possibly GC_GCJ_MALLOC will
00030  * be redefined to use the thread local allocatoor.
00031  *
00032  * The interface is available only if the collector is built with
00033  * -DTHREAD_LOCAL_ALLOC, which is currently supported only on Linux.
00034  *
00035  * The debugging allocators use standard, not thread-local allocation.
00036  *
00037  * These routines normally require an explicit call to GC_init(), though
00038  * that may be done from a constructor function.
00039  */
00040 
00041 #ifndef GC_LOCAL_ALLOC_H
00042 #define GC_LOCAL_ALLOC_H
00043 
00044 #ifndef _GC_H
00045 #   include "gc.h"
00046 #endif
00047 
00048 #if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H)
00049 #   include "gc_gcj.h"
00050 #endif
00051 
00052 /* We assume ANSI C for this interface.   */
00053 
00054 GC_PTR GC_local_malloc(size_t bytes);
00055 
00056 GC_PTR GC_local_malloc_atomic(size_t bytes);
00057 
00058 #if defined(GC_GCJ_SUPPORT)
00059   GC_PTR GC_local_gcj_malloc(size_t bytes,
00060                           void * ptr_to_struct_containing_descr);
00061 #endif
00062 
00063 # ifdef GC_DEBUG
00064     /* We don't really use local allocation in this case.      */
00065 #   define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS)
00066 #   define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS)
00067 #   ifdef GC_GCJ_SUPPORT
00068 #      define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
00069 #   endif
00070 # else
00071 #   define GC_LOCAL_MALLOC(s) GC_local_malloc(s)
00072 #   define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s)
00073 #   ifdef GC_GCJ_SUPPORT
00074 #      define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d)
00075 #   endif
00076 # endif
00077 
00078 # ifdef GC_REDIRECT_TO_LOCAL
00079 #   undef GC_MALLOC
00080 #   define GC_MALLOC(s) GC_LOCAL_MALLOC(s)
00081 #   undef GC_MALLOC_ATOMIC
00082 #   define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s)
00083 #   ifdef GC_GCJ_SUPPORT
00084 #      undef GC_GCJ_MALLOC
00085 #      define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d)
00086 #   endif
00087 # endif
00088 
00089 #endif /* GC_LOCAL_ALLOC_H */