1 /* 2 * Copyright (c) 2000 by Hewlett-Packard Company. All rights reserved. 3 * 4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED 5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 6 * 7 * Permission is hereby granted to use or copy this program 8 * for any purpose, provided the above notices are retained on all copies. 9 * Permission to modify the code and to distribute modified code is granted, 10 * provided the above notices are retained, and a notice that the code was 11 * modified is included with the above copyright notice. 12 */ 13 14 /* 15 * Interface for thread local allocation. Memory obtained 16 * this way can be used by all threads, as though it were obtained 17 * from an allocator like GC_malloc. The difference is that GC_local_malloc 18 * counts the number of allocations of a given size from the current thread, 19 * and uses GC_malloc_many to perform the allocations once a threashold 20 * is exceeded. Thus far less synchronization may be needed. 21 * Allocation of known large objects should not use this interface. 22 * This interface is designed primarily for fast allocation of small 23 * objects on multiprocessors, e.g. for a JVM running on an MP server. 24 * 25 * If this file is included with GC_GCJ_SUPPORT defined, GCJ-style 26 * bitmap allocation primitives will also be included. 27 * 28 * If this file is included with GC_REDIRECT_TO_LOCAL defined, then 29 * GC_MALLOC, GC_MALLOC_ATOMIC, and possibly GC_GCJ_MALLOC will 30 * be redefined to use the thread local allocatoor. 31 * 32 * The interface is available only if the collector is built with 33 * -DTHREAD_LOCAL_ALLOC, which is currently supported only on Linux. 34 * 35 * The debugging allocators use standard, not thread-local allocation. 36 * 37 * These routines normally require an explicit call to GC_init(), though 38 * that may be done from a constructor function. 39 */ 40 41 #ifndef _GC_H 42 # include "gc.h" 43 #endif 44 45 #if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H) 46 # include "gc_gcj.h" 47 #endif 48 49 #ifndef GC_LOCAL_ALLOC_H 50 #define GC_LOCAL_ALLOC_H 51 52 /* We assume ANSI C for this interface. */ 53 54 GC_PTR GC_local_malloc(size_t bytes); 55 56 GC_PTR GC_local_malloc_atomic(size_t bytes); 57 58 #if defined(GC_GCJ_SUPPORT) 59 GC_PTR GC_local_gcj_malloc(size_t bytes, 60 void * ptr_to_struct_containing_descr); 61 GC_PTR GC_local_gcj_fast_malloc(size_t lw, 62 void * ptr_to_struct_containing_descr); 63 #endif 64 65 # ifdef GC_DEBUG 66 /* We don't really use local allocation in this case. */ 67 # define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS) 68 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS) 69 # ifdef GC_GCJ_SUPPORT 70 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS) 71 # define GC_LOCAL_GCJ_FAST_MALLOC(s,d) GC_debug_gcj_fast_malloc(s,d,GC_EXTRAS) 72 # endif 73 # else 74 # define GC_LOCAL_MALLOC(s) GC_local_malloc(s) 75 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s) 76 # ifdef GC_GCJ_SUPPORT 77 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d) 78 # define GC_LOCAL_GCJ_FAST_MALLOC(s,d) GC_local_gcj_fast_malloc(s,d) 79 # endif 80 # endif 81 82 # ifdef GC_REDIRECT_TO_LOCAL 83 # undef GC_MALLOC 84 # define GC_MALLOC(s) GC_LOCAL_MALLOC(s) 85 # undef GC_MALLOC_ATOMIC 86 # define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s) 87 # ifdef GC_GCJ_SUPPORT 88 # undef GC_GCJ_MALLOC 89 # undef GC_GCJ_FAST_MALLOC 90 # define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d) 91 # define GC_GCJ_FAST_MALLOC(s,d) GC_LOCAL_GCJ_FAST_MALLOC(s,d) 92 # endif 93 # endif 94 95 #endif /* GC_LOCAL_ALLOC_H */ 96