3 * GC implementation using malloc: will leak everything, just for testing.
5 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
6 * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
7 * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13 #include <mono/metadata/mono-gc.h>
14 #include <mono/metadata/gc-internals.h>
15 #include <mono/metadata/runtime.h>
16 #include <mono/metadata/w32handle.h>
17 #include <mono/metadata/abi-details.h>
18 #include <mono/utils/atomic.h>
19 #include <mono/utils/mono-threads.h>
20 #include <mono/utils/mono-counters.h>
21 #include <mono/metadata/null-gc-handles.h>
25 static gboolean gc_inited
= FALSE
;
28 mono_gc_base_init (void)
33 mono_counters_init ();
36 mono_w32handle_init ();
39 mono_thread_callbacks_init ();
40 mono_thread_info_init (sizeof (MonoThreadInfo
));
42 mono_thread_info_attach ();
44 null_gc_handles_init ();
50 mono_gc_base_cleanup (void)
55 mono_gc_init_icalls (void)
60 mono_gc_collect (int generation
)
65 mono_gc_max_generation (void)
71 mono_gc_get_allocated_bytes_for_current_thread (void)
77 mono_gc_get_generation (MonoObject
*object
)
83 mono_gc_collection_count (int generation
)
89 mono_gc_add_memory_pressure (gint64 value
)
93 /* maybe track the size, not important, though */
95 mono_gc_get_used_size (void)
101 mono_gc_get_heap_size (void)
107 mono_gc_is_gc_thread (void)
113 mono_gc_walk_heap (int flags
, MonoGCReferences callback
, void *data
)
119 mono_object_is_alive (MonoObject
* o
)
125 mono_gc_register_root (char *start
, size_t size
, void *descr
, MonoGCRootSource source
, void *key
, const char *msg
)
131 mono_gc_register_root_wbarrier (char *start
, size_t size
, MonoGCDescriptor descr
, MonoGCRootSource source
, void *key
, const char *msg
)
138 mono_gc_deregister_root (char* addr
)
143 mono_gc_make_descr_for_string (gsize
*bitmap
, int numbits
)
149 mono_gc_make_descr_for_object (gsize
*bitmap
, int numbits
, size_t obj_size
)
155 mono_gc_make_descr_for_array (int vector
, gsize
*elem_bitmap
, int numbits
, size_t elem_size
)
161 mono_gc_make_descr_from_bitmap (gsize
*bitmap
, int numbits
)
167 mono_gc_make_vector_descr (void)
173 mono_gc_make_root_descr_all_refs (int numbits
)
179 mono_gc_alloc_fixed (size_t size
, void *descr
, MonoGCRootSource source
, void *key
, const char *msg
)
181 return (MonoObject
*)g_malloc0 (size
);
185 mono_gc_alloc_fixed_no_descriptor (size_t size
, MonoGCRootSource source
, void *key
, const char *msg
)
187 return mono_gc_alloc_fixed (size
, NULL
, source
, key
, msg
);
191 mono_gc_free_fixed (void* addr
)
197 mono_gc_alloc_obj (MonoVTable
*vtable
, size_t size
)
199 MonoObject
*obj
= g_calloc (1, size
);
201 obj
->vtable
= vtable
;
207 mono_gc_alloc_vector (MonoVTable
*vtable
, size_t size
, uintptr_t max_length
)
209 MonoArray
*obj
= g_calloc (1, size
);
211 obj
->obj
.vtable
= vtable
;
212 obj
->max_length
= max_length
;
218 mono_gc_alloc_array (MonoVTable
*vtable
, size_t size
, uintptr_t max_length
, uintptr_t bounds_size
)
220 MonoArray
*obj
= g_calloc (1, size
);
222 obj
->obj
.vtable
= vtable
;
223 obj
->max_length
= max_length
;
226 obj
->bounds
= (MonoArrayBounds
*) ((char *) obj
+ size
- bounds_size
);
232 mono_gc_alloc_string (MonoVTable
*vtable
, size_t size
, gint32 len
)
234 MonoString
*obj
= g_calloc (1, size
);
236 obj
->object
.vtable
= vtable
;
238 obj
->chars
[len
] = 0;
244 mono_gc_alloc_mature (MonoVTable
*vtable
, size_t size
)
246 return mono_gc_alloc_obj (vtable
, size
);
250 mono_gc_alloc_pinned_obj (MonoVTable
*vtable
, size_t size
)
252 return mono_gc_alloc_obj (vtable
, size
);
256 mono_gc_wbarrier_set_field_internal (MonoObject
*obj
, gpointer field_ptr
, MonoObject
* value
)
258 *(void**)field_ptr
= value
;
262 mono_gc_wbarrier_set_arrayref_internal (MonoArray
*arr
, gpointer slot_ptr
, MonoObject
* value
)
264 *(void**)slot_ptr
= value
;
268 mono_gc_wbarrier_arrayref_copy_internal (gpointer dest_ptr
, gconstpointer src_ptr
, int count
)
270 mono_gc_memmove_aligned (dest_ptr
, src_ptr
, count
* sizeof (gpointer
));
274 mono_gc_wbarrier_generic_store_internal (void volatile* ptr
, MonoObject
* value
)
276 *(void**)ptr
= value
;
280 mono_gc_wbarrier_generic_store_atomic_internal (gpointer ptr
, MonoObject
*value
)
282 mono_atomic_store_ptr (ptr
, value
);
286 mono_gc_wbarrier_generic_nostore_internal (gpointer ptr
)
291 mono_gc_wbarrier_value_copy_internal (gpointer dest
, gconstpointer src
, int count
, MonoClass
*klass
)
293 mono_gc_memmove_atomic (dest
, src
, count
* mono_class_value_size (klass
, NULL
));
297 mono_gc_wbarrier_object_copy_internal (MonoObject
* obj
, MonoObject
*src
)
299 /* do not copy the sync state */
300 mono_gc_memmove_aligned (mono_object_get_data (obj
), (char*)src
+ MONO_ABI_SIZEOF (MonoObject
),
301 mono_object_class (obj
)->instance_size
- MONO_ABI_SIZEOF (MonoObject
));
305 mono_gc_is_critical_method (MonoMethod
*method
)
311 mono_gc_thread_attach (MonoThreadInfo
* info
)
313 info
->handle_stack
= mono_handle_stack_alloc ();
318 mono_gc_thread_detach (MonoThreadInfo
*p
)
323 mono_gc_thread_detach_with_lock (MonoThreadInfo
*p
)
325 mono_handle_stack_free (p
->handle_stack
);
329 mono_gc_thread_in_critical_region (MonoThreadInfo
*info
)
335 mono_gc_get_aligned_size_for_allocator (int size
)
341 mono_gc_get_managed_allocator (MonoClass
*klass
, gboolean for_box
, gboolean known_instance_size
)
347 mono_gc_get_managed_array_allocator (MonoClass
*klass
)
353 mono_gc_get_managed_allocator_by_type (int atype
, ManagedAllocatorVariant variant
)
359 mono_gc_get_managed_allocator_types (void)
365 mono_gc_get_gc_name (void)
371 mono_gc_clear_domain (MonoDomain
*domain
)
376 mono_gc_suspend_finalizers (void)
381 mono_gc_get_suspend_signal (void)
387 mono_gc_get_restart_signal (void)
393 mono_gc_get_specific_write_barrier (gboolean is_concurrent
)
395 g_assert_not_reached ();
400 mono_gc_get_write_barrier (void)
402 g_assert_not_reached ();
407 mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func
, void *data
)
413 mono_gc_get_description (void)
415 return g_strdup (DEFAULT_GC_NAME
);
419 mono_gc_set_desktop_mode (void)
424 mono_gc_is_moving (void)
430 mono_gc_is_disabled (void)
436 mono_gc_wbarrier_range_copy (gpointer _dest
, gconstpointer _src
, int size
)
438 g_assert_not_reached ();
441 MonoRangeCopyFunction
442 mono_gc_get_range_copy_func (void)
444 return &mono_gc_wbarrier_range_copy
;
448 mono_gc_get_card_table (int *shift_bits
, gpointer
*card_mask
)
450 g_assert_not_reached ();
455 mono_gc_get_target_card_table (int *shift_bits
, target_mgreg_t
*card_mask
)
463 mono_gc_card_table_nursery_check (void)
465 g_assert_not_reached ();
470 mono_gc_get_nursery (int *shift_bits
, size_t *size
)
476 mono_gc_precise_stack_mark_enabled (void)
482 mono_gc_get_logfile (void)
488 mono_gc_params_set (const char* options
)
493 mono_gc_debug_set (const char* options
)
498 mono_gc_conservatively_scan_area (void *start
, void *end
)
500 g_assert_not_reached ();
504 mono_gc_scan_object (void *obj
, void *gc_data
)
506 g_assert_not_reached ();
511 mono_gc_get_bitmap_for_descr (void *descr
, int *numbits
)
513 g_assert_not_reached ();
518 mono_gc_set_gc_callbacks (MonoGCCallbacks
*callbacks
)
523 mono_gc_set_stack_end (void *stack_end
)
528 mono_gc_get_los_limit (void)
534 mono_gc_user_markers_supported (void)
540 mono_gc_make_root_descr_user (MonoGCRootMarkFunc marker
)
542 g_assert_not_reached ();
548 mono_gc_pthread_create (pthread_t
*new_thread
, const pthread_attr_t
*attr
, void *(*start_routine
)(void *), void *arg
)
550 return pthread_create (new_thread
, attr
, start_routine
, arg
);
555 mono_gc_skip_thread_changing (gboolean skip
)
557 // No STW, nothing needs to be done.
561 mono_gc_skip_thread_changed (gboolean skip
)
566 BOOL APIENTRY
mono_gc_dllmain (HMODULE module_handle
, DWORD reason
, LPVOID reserved
)
573 mono_gc_get_vtable (MonoObject
*obj
)
575 // No pointer tagging.
580 mono_gc_get_vtable_bits (MonoClass
*klass
)
586 mono_gc_register_altstack (gpointer stack
, gint32 stack_size
, gpointer altstack
, gint32 altstack_size
)
591 mono_gc_is_null (void)
597 mono_gc_invoke_finalizers (void)
603 mono_gc_pending_finalizers (void)
609 mono_gc_ephemeron_array_add (MonoObject
*obj
)
614 guint64
mono_gc_get_total_allocated_bytes (MonoBoolean precise
)
620 mono_gc_get_gcmemoryinfo (gint64
* high_memory_load_threshold_bytes
,
621 gint64
* memory_load_bytes
,
622 gint64
* total_available_memory_bytes
,
623 gint64
* heap_size_bytes
,
624 gint64
* fragmented_bytes
)
626 *high_memory_load_threshold_bytes
= 0;
627 *memory_load_bytes
= 0;
628 *total_available_memory_bytes
= 0;
629 *heap_size_bytes
= 0;
630 *fragmented_bytes
= 0;
635 MONO_EMPTY_SOURCE_FILE (null_gc
);
636 #endif /* HAVE_NULL_GC */