2009-02-03 Geoff Norton <gnorton@novell.com>
[mono-project.git] / mono / metadata / gc-internal.h
blobc000afa223d1dfe8a359be62c00e145de0fc0053
1 /*
2 * metadata/gc-internal.h: Internal GC interface
4 * Author: Paolo Molaro <lupus@ximian.com>
6 * (C) 2002 Ximian, Inc.
7 */
9 #ifndef __MONO_METADATA_GC_INTERNAL_H__
10 #define __MONO_METADATA_GC_INTERNAL_H__
12 #include <glib.h>
13 #include <mono/metadata/object-internals.h>
14 #include <mono/os/gc_wrapper.h>
16 #define MONO_GC_REGISTER_ROOT(x) mono_gc_register_root ((char*)&(x), sizeof(x), NULL)
18 #define MONO_GC_UNREGISTER_ROOT(x) mono_gc_deregister_root ((char*)&(x))
20 void mono_object_register_finalizer (MonoObject *obj) MONO_INTERNAL;
21 void ves_icall_System_GC_InternalCollect (int generation) MONO_INTERNAL;
22 gint64 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection) MONO_INTERNAL;
23 void ves_icall_System_GC_KeepAlive (MonoObject *obj) MONO_INTERNAL;
24 void ves_icall_System_GC_ReRegisterForFinalize (MonoObject *obj) MONO_INTERNAL;
25 void ves_icall_System_GC_SuppressFinalize (MonoObject *obj) MONO_INTERNAL;
26 void ves_icall_System_GC_WaitForPendingFinalizers (void) MONO_INTERNAL;
28 MonoObject *ves_icall_System_GCHandle_GetTarget (guint32 handle) MONO_INTERNAL;
29 guint32 ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type) MONO_INTERNAL;
30 void ves_icall_System_GCHandle_FreeHandle (guint32 handle) MONO_INTERNAL;
31 gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle) MONO_INTERNAL;
33 extern void mono_gc_init (void) MONO_INTERNAL;
34 extern void mono_gc_base_init (void) MONO_INTERNAL;
35 extern void mono_gc_cleanup (void) MONO_INTERNAL;
36 extern void mono_gc_enable (void) MONO_INTERNAL;
37 extern void mono_gc_disable (void) MONO_INTERNAL;
40 * Return whenever the current thread is registered with the GC (i.e. started
41 * by the GC pthread wrappers on unix.
43 extern gboolean mono_gc_is_gc_thread (void) MONO_INTERNAL;
46 * Try to register a foreign thread with the GC, if we fail or the backend
47 * can't cope with this concept - we return FALSE.
49 extern gboolean mono_gc_register_thread (void *baseptr) MONO_INTERNAL;
51 /* only valid after the RECLAIM_START GC event and before RECLAIM_END
52 * Not exported in public headers, but can be linked to (unsupported).
54 extern gboolean mono_object_is_alive (MonoObject* obj);
55 extern gboolean mono_gc_is_finalizer_thread (MonoThread *thread);
56 extern gpointer mono_gc_out_of_memory (size_t size);
57 extern void mono_gc_enable_events (void);
59 /* disappearing link functionality */
60 void mono_gc_weak_link_add (void **link_addr, MonoObject *obj) MONO_INTERNAL;
61 void mono_gc_weak_link_remove (void **link_addr) MONO_INTERNAL;
62 MonoObject *mono_gc_weak_link_get (void **link_addr) MONO_INTERNAL;
64 /* simple interface for data structures needed in the runtime */
65 void* mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits) MONO_INTERNAL;
67 /* User defined marking function */
68 /* It should work like this:
69 * foreach (ref in GC references in the are structure pointed to by ADDR)
70 * *ref = mark_func (*ref)
72 typedef void *(*MonoGCCopyFunc) (void *addr);
73 typedef void (*MonoGCMarkFunc) (void *addr, MonoGCCopyFunc mark_func);
75 /* Create a descriptor with a user defined marking function */
76 void *mono_gc_make_root_descr_user (MonoGCMarkFunc marker);
78 /* desc is the result from mono_gc_make_descr*. A NULL value means
79 * all the words contain GC pointers.
80 * The memory is non-moving and it will be explicitly deallocated.
81 * size bytes will be available from the returned address (ie, descr
82 * must not be stored in the returned memory)
84 void* mono_gc_alloc_fixed (size_t size, void *descr) MONO_INTERNAL;
85 void mono_gc_free_fixed (void* addr) MONO_INTERNAL;
87 /* make sure the gchandle was allocated for an object in domain */
88 gboolean mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain) MONO_INTERNAL;
89 void mono_gchandle_free_domain (MonoDomain *domain) MONO_INTERNAL;
91 typedef void (*FinalizerThreadCallback) (gpointer user_data);
93 /* if there are finalizers to run, run them. Returns the number of finalizers run */
94 int mono_gc_invoke_finalizers (void) MONO_INTERNAL;
95 gboolean mono_gc_pending_finalizers (void) MONO_INTERNAL;
96 void mono_gc_finalize_notify (void) MONO_INTERNAL;
98 void* mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size) MONO_INTERNAL;
99 void* mono_gc_alloc_obj (MonoVTable *vtable, size_t size) MONO_INTERNAL;
100 void* mono_gc_make_descr_for_string (gsize *bitmap, int numbits) MONO_INTERNAL;
101 void* mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size) MONO_INTERNAL;
102 void* mono_gc_make_descr_for_array (int vector, gsize *elem_bitmap, int numbits, size_t elem_size) MONO_INTERNAL;
104 void mono_gc_register_for_finalization (MonoObject *obj, void *user_data) MONO_INTERNAL;
105 void mono_gc_add_memory_pressure (gint64 value) MONO_INTERNAL;
106 int mono_gc_register_root (char *start, size_t size, void *descr) MONO_INTERNAL;
107 void mono_gc_deregister_root (char* addr) MONO_INTERNAL;
108 int mono_gc_finalizers_for_domain (MonoDomain *domain, MonoObject **out_array, int out_size) MONO_INTERNAL;
111 * Register a root which can only be written using a write barrier.
112 * Writes to the root must be done using a write barrier (MONO_ROOT_SETREF).
113 * If the root uses an user defined mark routine, the writes are not required to be
114 * to the area between START and START+SIZE.
115 * The write barrier allows the GC to avoid scanning this root at each collection, so it
116 * is more efficient.
117 * FIXME: Add an API for clearing remset entries if a root with a user defined
118 * mark routine is deleted.
120 int mono_gc_register_root_wbarrier (char *start, size_t size, void *descr) MONO_INTERNAL;
122 void mono_gc_wbarrier_set_root (gpointer ptr, MonoObject *value) MONO_INTERNAL;
124 /* Set a field of a root registered using mono_gc_register_root_wbarrier () */
125 #define MONO_ROOT_SETREF(s,fieldname,value) do { \
126 mono_gc_wbarrier_set_root (&((s)->fieldname), (MonoObject*)value); \
127 } while (0)
129 void mono_gc_finalize_threadpool_threads (void) MONO_INTERNAL;
131 /* fast allocation support */
132 MonoMethod* mono_gc_get_managed_allocator (MonoVTable *vtable, gboolean for_box) MONO_INTERNAL;
133 int mono_gc_get_managed_allocator_type (MonoMethod *managed_alloc) MONO_INTERNAL;
134 MonoMethod *mono_gc_get_managed_allocator_by_type (int atype) MONO_INTERNAL;
136 guint32 mono_gc_get_managed_allocator_types (void) MONO_INTERNAL;
138 /* Fast write barriers */
139 MonoMethod* mono_gc_get_write_barrier (void) MONO_INTERNAL;
141 /* helper for the managed alloc support */
142 MonoString *mono_string_alloc (int length) MONO_INTERNAL;
144 #endif /* __MONO_METADATA_GC_INTERNAL_H__ */