[merp] Remove dead code (#20043)
[mono-project.git] / mono / metadata / null-gc.c
blob52f7101e23007186f1fff3fc5b8257b1e40be764
1 /**
2 * \file
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.
9 */
11 #include "config.h"
12 #include <glib.h>
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>
23 #ifdef HAVE_NULL_GC
25 static gboolean gc_inited = FALSE;
27 void
28 mono_gc_base_init (void)
30 if (gc_inited)
31 return;
33 mono_counters_init ();
35 #ifndef HOST_WIN32
36 mono_w32handle_init ();
37 #endif
39 mono_thread_callbacks_init ();
40 mono_thread_info_init (sizeof (MonoThreadInfo));
42 mono_thread_info_attach ();
44 null_gc_handles_init ();
46 gc_inited = TRUE;
49 void
50 mono_gc_base_cleanup (void)
54 void
55 mono_gc_init_icalls (void)
59 void
60 mono_gc_collect (int generation)
64 int
65 mono_gc_max_generation (void)
67 return 0;
70 guint64
71 mono_gc_get_allocated_bytes_for_current_thread (void)
73 return 0;
76 int
77 mono_gc_get_generation (MonoObject *object)
79 return 0;
82 int
83 mono_gc_collection_count (int generation)
85 return 0;
88 void
89 mono_gc_add_memory_pressure (gint64 value)
93 /* maybe track the size, not important, though */
94 int64_t
95 mono_gc_get_used_size (void)
97 return 1024*1024;
100 int64_t
101 mono_gc_get_heap_size (void)
103 return 2*1024*1024;
106 gboolean
107 mono_gc_is_gc_thread (void)
109 return TRUE;
113 mono_gc_walk_heap (int flags, MonoGCReferences callback, void *data)
115 return 1;
118 gboolean
119 mono_object_is_alive (MonoObject* o)
121 return TRUE;
125 mono_gc_register_root (char *start, size_t size, void *descr, MonoGCRootSource source, void *key, const char *msg)
127 return TRUE;
131 mono_gc_register_root_wbarrier (char *start, size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg)
133 return TRUE;
137 void
138 mono_gc_deregister_root (char* addr)
142 void*
143 mono_gc_make_descr_for_string (gsize *bitmap, int numbits)
145 return NULL;
148 void*
149 mono_gc_make_descr_for_object (gsize *bitmap, int numbits, size_t obj_size)
151 return NULL;
154 void*
155 mono_gc_make_descr_for_array (int vector, gsize *elem_bitmap, int numbits, size_t elem_size)
157 return NULL;
160 void*
161 mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
163 return NULL;
166 void*
167 mono_gc_make_vector_descr (void)
169 return NULL;
172 void*
173 mono_gc_make_root_descr_all_refs (int numbits)
175 return NULL;
178 MonoObject*
179 mono_gc_alloc_fixed (size_t size, void *descr, MonoGCRootSource source, void *key, const char *msg)
181 return (MonoObject*)g_malloc0 (size);
184 MonoObject*
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);
190 void
191 mono_gc_free_fixed (void* addr)
193 g_free (addr);
196 MonoObject*
197 mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
199 MonoObject *obj = g_calloc (1, size);
201 obj->vtable = vtable;
203 return obj;
206 MonoArray*
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;
214 return obj;
217 MonoArray*
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;
225 if (bounds_size)
226 obj->bounds = (MonoArrayBounds *) ((char *) obj + size - bounds_size);
228 return obj;
231 MonoString*
232 mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
234 MonoString *obj = g_calloc (1, size);
236 obj->object.vtable = vtable;
237 obj->length = len;
238 obj->chars [len] = 0;
240 return obj;
243 MonoObject*
244 mono_gc_alloc_mature (MonoVTable *vtable, size_t size)
246 return mono_gc_alloc_obj (vtable, size);
249 MonoObject*
250 mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
252 return mono_gc_alloc_obj (vtable, size);
255 void
256 mono_gc_wbarrier_set_field_internal (MonoObject *obj, gpointer field_ptr, MonoObject* value)
258 *(void**)field_ptr = value;
261 void
262 mono_gc_wbarrier_set_arrayref_internal (MonoArray *arr, gpointer slot_ptr, MonoObject* value)
264 *(void**)slot_ptr = value;
267 void
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));
273 void
274 mono_gc_wbarrier_generic_store_internal (void volatile* ptr, MonoObject* value)
276 *(void**)ptr = value;
279 void
280 mono_gc_wbarrier_generic_store_atomic_internal (gpointer ptr, MonoObject *value)
282 mono_atomic_store_ptr (ptr, value);
285 void
286 mono_gc_wbarrier_generic_nostore_internal (gpointer ptr)
290 void
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));
296 void
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));
304 gboolean
305 mono_gc_is_critical_method (MonoMethod *method)
307 return FALSE;
310 gpointer
311 mono_gc_thread_attach (MonoThreadInfo* info)
313 info->handle_stack = mono_handle_stack_alloc ();
314 return info;
317 void
318 mono_gc_thread_detach (MonoThreadInfo *p)
322 void
323 mono_gc_thread_detach_with_lock (MonoThreadInfo *p)
325 mono_handle_stack_free (p->handle_stack);
328 gboolean
329 mono_gc_thread_in_critical_region (MonoThreadInfo *info)
331 return FALSE;
335 mono_gc_get_aligned_size_for_allocator (int size)
337 return size;
340 MonoMethod*
341 mono_gc_get_managed_allocator (MonoClass *klass, gboolean for_box, gboolean known_instance_size)
343 return NULL;
346 MonoMethod*
347 mono_gc_get_managed_array_allocator (MonoClass *klass)
349 return NULL;
352 MonoMethod*
353 mono_gc_get_managed_allocator_by_type (int atype, ManagedAllocatorVariant variant)
355 return NULL;
358 guint32
359 mono_gc_get_managed_allocator_types (void)
361 return 0;
364 const char *
365 mono_gc_get_gc_name (void)
367 return "null";
370 void
371 mono_gc_clear_domain (MonoDomain *domain)
375 void
376 mono_gc_suspend_finalizers (void)
381 mono_gc_get_suspend_signal (void)
383 return -1;
387 mono_gc_get_restart_signal (void)
389 return -1;
392 MonoMethod*
393 mono_gc_get_specific_write_barrier (gboolean is_concurrent)
395 g_assert_not_reached ();
396 return NULL;
399 MonoMethod*
400 mono_gc_get_write_barrier (void)
402 g_assert_not_reached ();
403 return NULL;
406 void*
407 mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data)
409 return func (data);
412 char*
413 mono_gc_get_description (void)
415 return g_strdup (DEFAULT_GC_NAME);
418 void
419 mono_gc_set_desktop_mode (void)
423 gboolean
424 mono_gc_is_moving (void)
426 return FALSE;
429 gboolean
430 mono_gc_is_disabled (void)
432 return FALSE;
435 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;
447 guint8*
448 mono_gc_get_card_table (int *shift_bits, gpointer *card_mask)
450 g_assert_not_reached ();
451 return NULL;
454 guint8*
455 mono_gc_get_target_card_table (int *shift_bits, target_mgreg_t *card_mask)
457 *shift_bits = 0;
458 *card_mask = 0;
459 return NULL;
462 gboolean
463 mono_gc_card_table_nursery_check (void)
465 g_assert_not_reached ();
466 return TRUE;
469 void*
470 mono_gc_get_nursery (int *shift_bits, size_t *size)
472 return NULL;
475 gboolean
476 mono_gc_precise_stack_mark_enabled (void)
478 return FALSE;
481 FILE *
482 mono_gc_get_logfile (void)
484 return NULL;
487 void
488 mono_gc_params_set (const char* options)
492 void
493 mono_gc_debug_set (const char* options)
497 void
498 mono_gc_conservatively_scan_area (void *start, void *end)
500 g_assert_not_reached ();
503 void *
504 mono_gc_scan_object (void *obj, void *gc_data)
506 g_assert_not_reached ();
507 return NULL;
510 gsize*
511 mono_gc_get_bitmap_for_descr (void *descr, int *numbits)
513 g_assert_not_reached ();
514 return NULL;
517 void
518 mono_gc_set_gc_callbacks (MonoGCCallbacks *callbacks)
522 void
523 mono_gc_set_stack_end (void *stack_end)
528 mono_gc_get_los_limit (void)
530 return G_MAXINT;
533 gboolean
534 mono_gc_user_markers_supported (void)
536 return FALSE;
539 void *
540 mono_gc_make_root_descr_user (MonoGCRootMarkFunc marker)
542 g_assert_not_reached ();
543 return NULL;
546 #ifndef HOST_WIN32
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);
552 #endif
554 void
555 mono_gc_skip_thread_changing (gboolean skip)
557 // No STW, nothing needs to be done.
560 void
561 mono_gc_skip_thread_changed (gboolean skip)
565 #ifdef HOST_WIN32
566 BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reserved)
568 return TRUE;
570 #endif
572 MonoVTable *
573 mono_gc_get_vtable (MonoObject *obj)
575 // No pointer tagging.
576 return obj->vtable;
579 guint
580 mono_gc_get_vtable_bits (MonoClass *klass)
582 return 0;
585 void
586 mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
590 gboolean
591 mono_gc_is_null (void)
593 return TRUE;
597 mono_gc_invoke_finalizers (void)
599 return 0;
602 MonoBoolean
603 mono_gc_pending_finalizers (void)
605 return FALSE;
608 gboolean
609 mono_gc_ephemeron_array_add (MonoObject *obj)
611 return TRUE;
614 guint64 mono_gc_get_total_allocated_bytes (MonoBoolean precise)
616 return 0;
619 void
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;
633 #else
635 MONO_EMPTY_SOURCE_FILE (null_gc);
636 #endif /* HAVE_NULL_GC */