[Coop] Convert mono_attach_load_agent. (#15954)
[mono-project.git] / libgc / include / gc_local_alloc.h
blobfcbb942c9a2d5445d23a005c063a3bfb587b852e
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_H
42 # include "gc.h"
43 #endif
45 #if defined(GC_GCJ_SUPPORT) && !defined(GC_GCJ_H)
46 # include "gc_gcj.h"
47 #endif
49 #ifndef GC_LOCAL_ALLOC_H
50 #define GC_LOCAL_ALLOC_H
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
56 /* We assume ANSI C for this interface. */
58 GC_PTR GC_local_malloc(size_t bytes);
60 GC_PTR GC_local_malloc_atomic(size_t bytes);
62 #if defined(GC_GCJ_SUPPORT)
63 GC_PTR GC_local_gcj_malloc(size_t bytes,
64 void * ptr_to_struct_containing_descr);
65 GC_PTR GC_local_gcj_fast_malloc(size_t lw,
66 void * ptr_to_struct_containing_descr);
67 #endif
69 #ifdef __cplusplus
70 } // extern "C"
71 #endif
73 # ifdef GC_DEBUG
74 /* We don't really use local allocation in this case. */
75 # define GC_LOCAL_MALLOC(s) GC_debug_malloc(s,GC_EXTRAS)
76 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_debug_malloc_atomic(s,GC_EXTRAS)
77 # ifdef GC_GCJ_SUPPORT
78 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
79 # define GC_LOCAL_GCJ_FAST_MALLOC(s,d) GC_debug_gcj_fast_malloc(s,d,GC_EXTRAS)
80 # endif
81 # else
82 # define GC_LOCAL_MALLOC(s) GC_local_malloc(s)
83 # define GC_LOCAL_MALLOC_ATOMIC(s) GC_local_malloc_atomic(s)
84 # ifdef GC_GCJ_SUPPORT
85 # define GC_LOCAL_GCJ_MALLOC(s,d) GC_local_gcj_malloc(s,d)
86 # define GC_LOCAL_GCJ_FAST_MALLOC(s,d) GC_local_gcj_fast_malloc(s,d)
87 # endif
88 # endif
90 # ifdef GC_REDIRECT_TO_LOCAL
91 # undef GC_MALLOC
92 # define GC_MALLOC(s) GC_LOCAL_MALLOC(s)
93 # undef GC_MALLOC_ATOMIC
94 # define GC_MALLOC_ATOMIC(s) GC_LOCAL_MALLOC_ATOMIC(s)
95 # ifdef GC_GCJ_SUPPORT
96 # undef GC_GCJ_MALLOC
97 # undef GC_GCJ_FAST_MALLOC
98 # define GC_GCJ_MALLOC(s,d) GC_LOCAL_GCJ_MALLOC(s,d)
99 # define GC_GCJ_FAST_MALLOC(s,d) GC_LOCAL_GCJ_FAST_MALLOC(s,d)
100 # endif
101 # endif
103 #endif /* GC_LOCAL_ALLOC_H */