2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / boehm-gc / include / gc_local_alloc.h
blob88e29e9a11f24d32f5e0356b1ec6a8a7f785239f
1 /*
2 * Copyright (c) 2000 by Hewlett-Packard Company. All rights reserved.
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
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.
25 * If this file is included with GC_GCJ_SUPPORT defined, GCJ-style
26 * bitmap allocation primitives will also be included.
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.
32 * The interface is available only if the collector is built with
33 * -DTHREAD_LOCAL_ALLOC, which is currently supported only on Linux.
35 * The debugging allocators use standard, not thread-local allocation.
37 * These routines normally require an explicit call to GC_init(), though
38 * that may be done from a constructor function.
41 #ifndef GC_LOCAL_ALLOC_H
42 #define GC_LOCAL_ALLOC_H
44 #ifndef _GC_H
45 # include "gc.h"
46 #endif
48 #if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H)
49 # include "gc_gcj.h"
50 #endif
52 /* We assume ANSI C for this interface. */
54 GC_PTR GC_local_malloc(size_t bytes);
56 GC_PTR GC_local_malloc_atomic(size_t bytes);
58 #if defined(GC_GCJ_SUPPORT)
59 GC_PTR GC_local_gcj_malloc(size_t bytes,
60 void * ptr_to_struct_containing_descr);
61 #endif
63 # ifdef GC_DEBUG
64 # define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS)
65 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS)
66 # ifdef GC_GCJ_SUPPORT
67 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
68 # endif
69 # else
70 # define GC_LOCAL_MALLOC(s) GC_local_malloc(s)
71 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s)
72 # ifdef GC_GCJ_SUPPORT
73 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d)
74 # endif
75 # endif
77 # ifdef GC_REDIRECT_TO_LOCAL
78 # undef GC_MALLOC
79 # define GC_MALLOC(s) GC_LOCAL_MALLOC(s)
80 # undef GC_MALLOC_ATOMIC
81 # define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s)
82 # ifdef GC_GCJ_SUPPORT
83 # undef GC_GCJ_MALLOC
84 # define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d)
85 # endif
86 # endif
88 #endif /* GC_LOCAL_ALLOC_H */