X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fgc-internal.h;h=c3b5f63c265c7aa275b2b4cc4dc0dc8e0cdc8372;hb=04bed5c57c82fdb43d700671c957024504b89306;hp=10b94338ffabf3ad7c6473fb54fcf763072ee20a;hpb=9e1f34dd2d7be45b2a3a6b1c133a4a1de8c3d864;p=mono.git diff --git a/mono/metadata/gc-internal.h b/mono/metadata/gc-internal.h index 10b94338ffa..c3b5f63c265 100644 --- a/mono/metadata/gc-internal.h +++ b/mono/metadata/gc-internal.h @@ -17,10 +17,64 @@ #define mono_domain_finalizers_lock(domain) EnterCriticalSection (&(domain)->finalizable_objects_hash_lock); #define mono_domain_finalizers_unlock(domain) LeaveCriticalSection (&(domain)->finalizable_objects_hash_lock); +/* Register a memory area as a conservatively scanned GC root */ #define MONO_GC_REGISTER_ROOT(x) mono_gc_register_root ((char*)&(x), sizeof(x), NULL) #define MONO_GC_UNREGISTER_ROOT(x) mono_gc_deregister_root ((char*)&(x)) +/* + * Register a memory location as a root pointing to memory allocated using + * mono_gc_alloc_fixed (). This includes MonoGHashTable. + */ +#ifdef HAVE_SGEN_GC +/* The result of alloc_fixed () is not GC tracked memory */ +#define MONO_GC_REGISTER_ROOT_FIXED(x) +#else +#define MONO_GC_REGISTER_ROOT_FIXED(x) MONO_GC_REGISTER_ROOT ((x)) +#endif + +/* + * Return a GC descriptor for an array containing N pointers to memory allocated + * by mono_gc_alloc_fixed (). + */ +#ifdef HAVE_SGEN_GC +/* The result of alloc_fixed () is not GC tracked memory */ +#define MONO_GC_ROOT_DESCR_FOR_FIXED(n) mono_gc_make_root_descr_all_refs (0) +#else +/* The result of alloc_fixed () is GC tracked memory */ +#define MONO_GC_ROOT_DESCR_FOR_FIXED(n) NULL +#endif + +/* Register a memory location holding a single object reference as a GC root */ +#define MONO_GC_REGISTER_ROOT_SINGLE(x) do { \ + g_assert (sizeof (x) == sizeof (MonoObject*)); \ + mono_gc_register_root ((char*)&(x), sizeof(MonoObject*), mono_gc_make_root_descr_all_refs (1)); \ + } while (0) + +/* + * This is used for fields which point to objects which are kept alive by other references + * when using Boehm. + */ +#ifdef HAVE_SGEN_GC +#define MONO_GC_REGISTER_ROOT_IF_MOVING(x) do { \ + MONO_GC_REGISTER_ROOT_SINGLE(x); \ +} while (0) + +#define MONO_GC_UNREGISTER_ROOT_IF_MOVING(x) do { \ + MONO_GC_UNREGISTER_ROOT (x); \ +} while (0) +#else +#define MONO_GC_REGISTER_ROOT_IF_MOVING(x) +#define MONO_GC_UNREGISTER_ROOT_IF_MOVING(x) +#endif + +/* useful until we keep track of gc-references in corlib etc. */ +#ifdef HAVE_SGEN_GC +#define IS_GC_REFERENCE(t) FALSE +#else +#define IS_GC_REFERENCE(t) ((t)->type == MONO_TYPE_U && class->image == mono_defaults.corlib) +#endif + void mono_object_register_finalizer (MonoObject *obj) MONO_INTERNAL; void ves_icall_System_GC_InternalCollect (int generation) MONO_INTERNAL; gint64 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection) MONO_INTERNAL; @@ -33,6 +87,8 @@ MonoObject *ves_icall_System_GCHandle_GetTarget (guint32 handle) MONO_INTERNAL; guint32 ves_icall_System_GCHandle_GetTargetHandle (MonoObject *obj, guint32 handle, gint32 type) MONO_INTERNAL; void ves_icall_System_GCHandle_FreeHandle (guint32 handle) MONO_INTERNAL; gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle) MONO_INTERNAL; +void ves_icall_System_GC_register_ephemeron_array (MonoObject *array) MONO_INTERNAL; +MonoObject *ves_icall_System_GC_get_ephemeron_tombstone (void) MONO_INTERNAL; extern void mono_gc_init (void) MONO_INTERNAL; extern void mono_gc_base_init (void) MONO_INTERNAL; @@ -54,6 +110,8 @@ extern gboolean mono_gc_register_thread (void *baseptr) MONO_INTERNAL; extern gboolean mono_gc_is_finalizer_internal_thread (MonoInternalThread *thread) MONO_INTERNAL; +extern void mono_gc_set_stack_end (void *stack_end) MONO_INTERNAL; + /* only valid after the RECLAIM_START GC event and before RECLAIM_END * Not exported in public headers, but can be linked to (unsupported). */ @@ -74,28 +132,37 @@ void mono_gc_remove_weak_track_handle (guint32 gchandle) MONO_INTERNAL; GSList* mono_gc_remove_weak_track_object (MonoDomain *domain, MonoObject *obj) MONO_INTERNAL; #endif +/*Ephemeron functionality. Sgen only*/ +gboolean mono_gc_ephemeron_array_add (MonoObject *obj) MONO_INTERNAL; + + MonoBoolean GCHandle_CheckCurrentDomain (guint32 gchandle) MONO_INTERNAL; /* simple interface for data structures needed in the runtime */ void* mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits) MONO_INTERNAL; +/* Return a root descriptor for a root with all refs */ +void* mono_gc_make_root_descr_all_refs (int numbits) MONO_INTERNAL; + /* User defined marking function */ /* It should work like this: * foreach (ref in GC references in the are structure pointed to by ADDR) - * *ref = mark_func (*ref) + * mark_func (ref) */ -typedef void *(*MonoGCCopyFunc) (void *addr); -typedef void (*MonoGCMarkFunc) (void *addr, MonoGCCopyFunc mark_func); +typedef void (*MonoGCMarkFunc) (void **addr); +typedef void (*MonoGCRootMarkFunc) (void *addr, MonoGCMarkFunc mark_func); /* Create a descriptor with a user defined marking function */ -void *mono_gc_make_root_descr_user (MonoGCMarkFunc marker); +void *mono_gc_make_root_descr_user (MonoGCRootMarkFunc marker); /* desc is the result from mono_gc_make_descr*. A NULL value means * all the words might contain GC pointers. * The memory is non-moving and it will be explicitly deallocated. * size bytes will be available from the returned address (ie, descr * must not be stored in the returned memory) + * NOTE: Under Boehm, this returns memory allocated using GC_malloc, so the result should + * be stored into a location registered using MONO_GC_REGISTER_ROOT_FIXED (). */ void* mono_gc_alloc_fixed (size_t size, void *descr) MONO_INTERNAL; void mono_gc_free_fixed (void* addr) MONO_INTERNAL; @@ -112,8 +179,8 @@ void mono_gc_finalize_notify (void) MONO_INTERNAL; void* mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size) MONO_INTERNAL; void* mono_gc_alloc_obj (MonoVTable *vtable, size_t size) MONO_INTERNAL; -void* mono_gc_alloc_vector (MonoVTable *vtable, size_t size, mono_array_size_t max_length) MONO_INTERNAL; -void* mono_gc_alloc_array (MonoVTable *vtable, size_t size, mono_array_size_t max_length, mono_array_size_t bounds_size) MONO_INTERNAL; +void* mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length) MONO_INTERNAL; +void* mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size) MONO_INTERNAL; void* mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len) MONO_INTERNAL; void* mono_gc_make_descr_for_string (gsize *bitmap, int numbits) MONO_INTERNAL; void* mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size) MONO_INTERNAL; @@ -126,6 +193,7 @@ void mono_gc_deregister_root (char* addr) MONO_INTERNAL; int mono_gc_finalizers_for_domain (MonoDomain *domain, MonoObject **out_array, int out_size) MONO_INTERNAL; void mono_gc_run_finalize (void *obj, void *data) MONO_INTERNAL; void mono_gc_clear_domain (MonoDomain * domain) MONO_INTERNAL; +void* mono_gc_alloc_mature (MonoVTable *vtable) MONO_INTERNAL; /* * Register a root which can only be written using a write barrier. @@ -152,6 +220,7 @@ void mono_gc_finalize_threadpool_threads (void) MONO_INTERNAL; /* Accessible using mono_marshal_wrapper_info_from_wrapper () */ typedef struct { + const char *gc_name; int alloc_type; } AllocatorWrapperInfo; @@ -161,9 +230,15 @@ MonoMethod *mono_gc_get_managed_allocator_by_type (int atype) MONO_INTERNAL; guint32 mono_gc_get_managed_allocator_types (void) MONO_INTERNAL; +/* Return a short string identifying the GC, indented to be saved in AOT images */ +const char *mono_gc_get_gc_name (void) MONO_INTERNAL; + /* Fast write barriers */ MonoMethod* mono_gc_get_write_barrier (void) MONO_INTERNAL; +/* Fast valuetype copy */ +void mono_gc_wbarrier_value_copy_bitmap (gpointer dest, gpointer src, int size, unsigned bitmap) MONO_INTERNAL; + /* helper for the managed alloc support */ MonoString *mono_string_alloc (int length) MONO_INTERNAL; @@ -177,7 +252,11 @@ typedef struct { * needed by the other functions. */ gpointer (*thread_attach_func) (void); - /* FIXME: Add a cleanup function too */ + /* + * Function called during thread deatch to free the data allocated by + * thread_attach_func. + */ + void (*thread_detach_func) (gpointer user_data); /* * Function called from every thread when suspending for GC. It can save * data needed for marking from thread stacks. user_data is the data returned @@ -198,6 +277,7 @@ typedef struct { /* Set the callback functions callable by the GC */ void mono_gc_set_gc_callbacks (MonoGCCallbacks *callbacks) MONO_INTERNAL; +MonoGCCallbacks *mono_gc_get_gc_callbacks (void) MONO_INTERNAL; /* Functions callable from the thread mark func */ @@ -214,8 +294,75 @@ gsize* mono_gc_get_bitmap_for_descr (void *descr, int *numbits) MONO_INTERNAL; or -1 if not applicable. */ int mono_gc_get_suspend_signal (void) MONO_INTERNAL; -#ifdef HAVE_SGEN_GC +/* + * Return a human readable description of the GC in malloc-ed memory. + */ +char* mono_gc_get_description (void) MONO_INTERNAL; + +/* + * Configure the GC to desktop mode + */ +void mono_gc_set_desktop_mode (void) MONO_INTERNAL; + +/* + * Return whenever this GC can move objects + */ +gboolean mono_gc_is_moving (void) MONO_INTERNAL; + +typedef void* (*MonoGCLockedCallbackFunc) (void *data); + +void* mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data) MONO_INTERNAL; + int mono_gc_get_los_limit (void) MONO_INTERNAL; + +guint8* mono_gc_get_card_table (int *shift_bits, gpointer *card_mask) MONO_INTERNAL; + +void* mono_gc_get_nursery (int *shift_bits, size_t *size) MONO_INTERNAL; + +/* + * Return whenever GC is disabled + */ +gboolean mono_gc_is_disabled (void) MONO_INTERNAL; + +#if defined(__MACH__) +void mono_gc_register_mach_exception_thread (pthread_t thread) MONO_INTERNAL; +pthread_t mono_gc_get_mach_exception_thread (void) MONO_INTERNAL; +#endif + +gboolean mono_gc_parse_environment_string_extract_number (const char *str, glong *out) MONO_INTERNAL; + +gboolean mono_gc_precise_stack_mark_enabled (void) MONO_INTERNAL; + +FILE *mono_gc_get_logfile (void) MONO_INTERNAL; + +typedef void (*mono_reference_queue_callback) (void *user_data); + +typedef struct _MonoReferenceQueue MonoReferenceQueue; +typedef struct _RefQueueEntry RefQueueEntry; + +struct _RefQueueEntry { +#ifdef HAVE_SGEN_GC + void *dis_link; +#else + guint32 gchandle; +#endif + void *user_data; + RefQueueEntry *next; +}; + +struct _MonoReferenceQueue { + RefQueueEntry *queue; + mono_reference_queue_callback callback; + MonoReferenceQueue *next; + gboolean should_be_deleted; +}; + +MonoReferenceQueue* mono_gc_reference_queue_new (mono_reference_queue_callback callback) MONO_INTERNAL; +void mono_gc_reference_queue_free (MonoReferenceQueue *queue) MONO_INTERNAL; +gboolean mono_gc_reference_queue_add (MonoReferenceQueue *queue, MonoObject *obj, void *user_data) MONO_INTERNAL; + +#ifdef HOST_WIN32 +BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reserved) MONO_INTERNAL; #endif #endif /* __MONO_METADATA_GC_INTERNAL_H__ */