3 * Mono's client definitions for SGen.
5 * Copyright (C) 2014 Xamarin Inc
7 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 #ifdef SGEN_DEFINE_OBJECT_VTABLE
12 #include "sgen/sgen-archdep.h"
13 #include "utils/mono-threads.h"
14 #include "utils/mono-mmap.h"
15 #include "metadata/object-internals.h"
17 typedef MonoObject GCObject;
18 typedef MonoVTable* GCVTable;
20 static inline GCVTable
21 SGEN_LOAD_VTABLE_UNCHECKED (GCObject *obj)
26 static inline SgenDescriptor
27 sgen_vtable_get_descriptor (GCVTable vtable)
29 return (SgenDescriptor)vtable->gc_descr;
32 typedef struct _SgenClientThreadInfo SgenClientThreadInfo;
33 struct _SgenClientThreadInfo {
37 * `skip` is set to TRUE when STW fails to suspend a thread, most probably because
38 * the underlying thread is dead.
40 gboolean skip, suspend_done;
41 volatile int in_critical_region;
44 This is set the argument of mono_gc_set_skip_thread.
46 A thread that knowingly holds no managed state can call this
47 function around blocking loops to reduce the GC burden by not
53 /* This is -1 until the first suspend. */
55 /* FIXME: kill this, we only use signals on systems that have rt-posix, which doesn't have issues with duplicates. */
56 unsigned int stop_count; /* to catch duplicate signals. */
59 gpointer runtime_data;
63 void *stack_start_limit;
65 MonoContext ctx; /* ditto */
70 #include "metadata/profiler-private.h"
71 #include "utils/dtrace.h"
72 #include "utils/mono-counters.h"
73 #include "utils/mono-logger-internals.h"
74 #include "utils/mono-time.h"
75 #include "utils/mono-os-semaphore.h"
76 #include "metadata/sgen-bridge-internals.h"
78 extern void mono_sgen_register_moved_object (void *obj, void *destination);
79 extern void mono_sgen_gc_event_moves (void);
81 extern void mono_sgen_init_stw (void);
84 INTERNAL_MEM_EPHEMERON_LINK = INTERNAL_MEM_FIRST_CLIENT,
85 INTERNAL_MEM_MOVED_OBJECT,
90 sgen_mono_array_size (GCVTable vtable, MonoArray *array, mword *bounds_size, mword descr)
92 mword size, size_without_bounds;
95 if ((descr & DESC_TYPE_MASK) == DESC_TYPE_VECTOR)
96 element_size = ((descr) >> VECTOR_ELSIZE_SHIFT) & MAX_ELEMENT_SIZE;
98 element_size = vtable->klass->sizes.element_size;
100 size_without_bounds = size = MONO_SIZEOF_MONO_ARRAY + element_size * mono_array_length_fast (array);
102 if (G_UNLIKELY (array->bounds)) {
103 size += sizeof (mono_array_size_t) - 1;
104 size &= ~(sizeof (mono_array_size_t) - 1);
105 size += sizeof (MonoArrayBounds) * vtable->klass->rank;
109 *bounds_size = size - size_without_bounds;
113 #define SGEN_CLIENT_OBJECT_HEADER_SIZE (sizeof (GCObject))
114 #define SGEN_CLIENT_MINIMUM_OBJECT_SIZE SGEN_CLIENT_OBJECT_HEADER_SIZE
116 static mword /*__attribute__ ((__noinline__)) not sure if this hint is a good idea*/
117 sgen_client_slow_object_get_size (GCVTable vtable, GCObject* o)
119 MonoClass *klass = ((MonoVTable*)vtable)->klass;
122 * We depend on mono_string_length_fast and
123 * mono_array_length_fast not using the object's vtable.
125 if (klass == mono_defaults.string_class) {
126 return G_STRUCT_OFFSET (MonoString, chars) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
127 } else if (klass->rank) {
128 return sgen_mono_array_size (vtable, (MonoArray*)o, NULL, 0);
130 /* from a created object: the class must be inited already */
131 return klass->instance_size;
136 * This function can be called on an object whose first word, the
137 * vtable field, is not intact. This is necessary for the parallel
140 static MONO_NEVER_INLINE mword
141 sgen_client_par_object_get_size (GCVTable vtable, GCObject* o)
143 SgenDescriptor descr = sgen_vtable_get_descriptor (vtable);
144 mword type = descr & DESC_TYPE_MASK;
146 if (type == DESC_TYPE_RUN_LENGTH || type == DESC_TYPE_SMALL_PTRFREE) {
147 mword size = descr & 0xfff8;
148 SGEN_ASSERT (9, size >= sizeof (MonoObject), "Run length object size to small");
150 } else if (descr == SGEN_DESC_STRING) {
151 return G_STRUCT_OFFSET (MonoString, chars) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
152 } else if (type == DESC_TYPE_VECTOR) {
153 return sgen_mono_array_size (vtable, (MonoArray*)o, NULL, descr);
156 return sgen_client_slow_object_get_size (vtable, o);
159 static MONO_ALWAYS_INLINE size_t G_GNUC_UNUSED
160 sgen_client_array_element_size (GCVTable gc_vtable)
162 MonoVTable *vt = (MonoVTable*)gc_vtable;
163 return mono_array_element_size (vt->klass);
166 static MONO_ALWAYS_INLINE G_GNUC_UNUSED char*
167 sgen_client_array_data_start (GCObject *obj)
169 return (char*)(obj) + G_STRUCT_OFFSET (MonoArray, vector);
172 static MONO_ALWAYS_INLINE size_t G_GNUC_UNUSED
173 sgen_client_array_length (GCObject *obj)
175 return mono_array_length_fast ((MonoArray*)obj);
178 static MONO_ALWAYS_INLINE gboolean G_GNUC_UNUSED
179 sgen_client_object_is_array_fill (GCObject *o)
181 return ((MonoObject*)o)->synchronisation == GINT_TO_POINTER (-1);
184 static MONO_ALWAYS_INLINE void G_GNUC_UNUSED
185 sgen_client_pre_copy_checks (char *destination, GCVTable gc_vtable, void *obj, mword objsize)
187 MonoVTable *vt = (MonoVTable*)gc_vtable;
188 SGEN_ASSERT (9, vt->klass->inited, "vtable %p for class %s:%s was not initialized", vt, vt->klass->name_space, vt->klass->name);
191 static MONO_ALWAYS_INLINE void G_GNUC_UNUSED
192 sgen_client_update_copied_object (char *destination, GCVTable gc_vtable, void *obj, mword objsize)
194 MonoVTable *vt = (MonoVTable*)gc_vtable;
195 if (G_UNLIKELY (vt->rank && ((MonoArray*)obj)->bounds)) {
196 MonoArray *array = (MonoArray*)destination;
197 array->bounds = (MonoArrayBounds*)((char*)destination + ((char*)((MonoArray*)obj)->bounds - (char*)obj));
198 SGEN_LOG (9, "Array instance %p: size: %lu, rank: %d, length: %lu", array, (unsigned long)objsize, vt->rank, (unsigned long)mono_array_length (array));
201 if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_GC_MOVES))
202 mono_sgen_register_moved_object (obj, destination);
205 #ifdef XDOMAIN_CHECKS_IN_WBARRIER
206 extern gboolean sgen_mono_xdomain_checks;
208 #define sgen_client_wbarrier_generic_nostore_check(ptr) do { \
209 /* FIXME: ptr_in_heap must be called with the GC lock held */ \
210 if (sgen_mono_xdomain_checks && *(MonoObject**)ptr && ptr_in_heap (ptr)) { \
211 char *start = find_object_for_ptr (ptr); \
212 MonoObject *value = *(MonoObject**)ptr; \
214 SGEN_ASSERT (0, start, "Write barrier outside an object?"); \
216 MonoObject *obj = (MonoObject*)start; \
217 if (obj->vtable->domain != value->vtable->domain) \
218 SGEN_ASSERT (0, is_xdomain_ref_allowed (ptr, start, obj->vtable->domain), "Cross-domain ref not allowed"); \
224 #define sgen_client_wbarrier_generic_nostore_check(ptr)
227 static gboolean G_GNUC_UNUSED
228 sgen_client_object_has_critical_finalizer (GCObject *obj)
232 if (!mono_defaults.critical_finalizer_object)
235 klass = SGEN_LOAD_VTABLE (obj)->klass;
237 return mono_class_has_parent_fast (klass, mono_defaults.critical_finalizer_object);
240 const char* sgen_client_vtable_get_namespace (GCVTable vtable);
241 const char* sgen_client_vtable_get_name (GCVTable vtable);
243 static gboolean G_GNUC_UNUSED
244 sgen_client_bridge_need_processing (void)
246 return sgen_need_bridge_processing ();
249 static void G_GNUC_UNUSED
250 sgen_client_bridge_reset_data (void)
252 sgen_bridge_reset_data ();
255 static void G_GNUC_UNUSED
256 sgen_client_bridge_processing_stw_step (void)
258 sgen_bridge_processing_stw_step ();
261 static void G_GNUC_UNUSED
262 sgen_client_bridge_wait_for_processing (void)
264 mono_gc_wait_for_bridge_processing ();
267 static void G_GNUC_UNUSED
268 sgen_client_bridge_processing_finish (int generation)
270 sgen_bridge_processing_finish (generation);
273 static gboolean G_GNUC_UNUSED
274 sgen_client_bridge_is_bridge_object (GCObject *obj)
276 return sgen_is_bridge_object (obj);
279 static void G_GNUC_UNUSED
280 sgen_client_bridge_register_finalized_object (GCObject *object)
282 sgen_bridge_register_finalized_object (object);
285 static void G_GNUC_UNUSED
286 sgen_client_binary_protocol_collection_requested (int generation, size_t requested_size, gboolean force)
288 MONO_GC_REQUESTED (generation, requested_size, force);
291 static void G_GNUC_UNUSED
292 sgen_client_binary_protocol_collection_begin (int minor_gc_count, int generation)
294 MONO_GC_BEGIN (generation);
296 mono_profiler_gc_event (MONO_GC_EVENT_START, generation);
298 #ifndef DISABLE_PERFCOUNTERS
299 if (generation == GENERATION_NURSERY)
300 mono_perfcounters->gc_collections0++;
302 mono_perfcounters->gc_collections1++;
306 static void G_GNUC_UNUSED
307 sgen_client_binary_protocol_collection_end (int minor_gc_count, int generation, long long num_objects_scanned, long long num_unique_objects_scanned)
309 MONO_GC_END (generation);
311 mono_profiler_gc_event (MONO_GC_EVENT_END, generation);
314 static void G_GNUC_UNUSED
315 sgen_client_binary_protocol_concurrent_start (void)
317 MONO_GC_CONCURRENT_START_BEGIN (GENERATION_OLD);
320 static void G_GNUC_UNUSED
321 sgen_client_binary_protocol_concurrent_update (void)
323 MONO_GC_CONCURRENT_UPDATE_FINISH_BEGIN (GENERATION_OLD, sgen_get_major_collector ()->get_and_reset_num_major_objects_marked ());
326 static void G_GNUC_UNUSED
327 sgen_client_binary_protocol_concurrent_finish (void)
329 MONO_GC_CONCURRENT_UPDATE_FINISH_BEGIN (GENERATION_OLD, sgen_get_major_collector ()->get_and_reset_num_major_objects_marked ());
332 static void G_GNUC_UNUSED
333 sgen_client_binary_protocol_sweep_begin (int generation, int full_sweep)
335 MONO_GC_SWEEP_BEGIN (generation, full_sweep);
338 static void G_GNUC_UNUSED
339 sgen_client_binary_protocol_sweep_end (int generation, int full_sweep)
341 MONO_GC_SWEEP_END (generation, full_sweep);
344 static void G_GNUC_UNUSED
345 sgen_client_binary_protocol_world_stopping (int generation, long long timestamp, gpointer thread)
347 MONO_GC_WORLD_STOP_BEGIN ();
350 static void G_GNUC_UNUSED
351 sgen_client_binary_protocol_world_stopped (int generation, long long timestamp, long long total_major_cards, long long marked_major_cards, long long total_los_cards, long long marked_los_cards)
353 MONO_GC_WORLD_STOP_END ();
356 static void G_GNUC_UNUSED
357 sgen_client_binary_protocol_world_restarting (int generation, long long timestamp, long long total_major_cards, long long marked_major_cards, long long total_los_cards, long long marked_los_cards)
359 MONO_GC_WORLD_RESTART_BEGIN (generation);
362 static void G_GNUC_UNUSED
363 sgen_client_binary_protocol_world_restarted (int generation, long long timestamp)
365 MONO_GC_WORLD_RESTART_END (generation);
368 static void G_GNUC_UNUSED
369 sgen_client_binary_protocol_block_alloc (gpointer addr, size_t size)
373 static void G_GNUC_UNUSED
374 sgen_client_binary_protocol_block_free (gpointer addr, size_t size)
378 static void G_GNUC_UNUSED
379 sgen_client_binary_protocol_block_set_state (gpointer addr, size_t size, int old, int new_)
383 static void G_GNUC_UNUSED
384 sgen_client_binary_protocol_mark_start (int generation)
386 mono_profiler_gc_event (MONO_GC_EVENT_MARK_START, generation);
389 static void G_GNUC_UNUSED
390 sgen_client_binary_protocol_mark_end (int generation)
392 mono_profiler_gc_event (MONO_GC_EVENT_MARK_END, generation);
395 static void G_GNUC_UNUSED
396 sgen_client_binary_protocol_reclaim_start (int generation)
398 mono_profiler_gc_event (MONO_GC_EVENT_RECLAIM_START, generation);
401 static void G_GNUC_UNUSED
402 sgen_client_binary_protocol_reclaim_end (int generation)
404 mono_profiler_gc_event (MONO_GC_EVENT_RECLAIM_END, generation);
408 mono_binary_protocol_alloc_generic (gpointer obj, gpointer vtable, size_t size, gboolean pinned)
411 const char *namespace = sgen_client_vtable_get_namespace (vtable);
412 const char *name = sgen_client_vtable_get_name (vtable);
414 if (sgen_ptr_in_nursery (obj)) {
415 if (G_UNLIKELY (MONO_GC_NURSERY_OBJ_ALLOC_ENABLED ()))
416 MONO_GC_NURSERY_OBJ_ALLOC ((mword)obj, size, namespace, name);
418 if (size > SGEN_MAX_SMALL_OBJ_SIZE) {
419 if (G_UNLIKELY (MONO_GC_MAJOR_OBJ_ALLOC_LARGE_ENABLED ()))
420 MONO_GC_MAJOR_OBJ_ALLOC_LARGE ((mword)obj, size, namespace, name);
422 MONO_GC_MAJOR_OBJ_ALLOC_PINNED ((mword)obj, size, namespace, name);
428 static void G_GNUC_UNUSED
429 sgen_client_binary_protocol_alloc (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
431 mono_binary_protocol_alloc_generic (obj, vtable, size, FALSE);
434 static void G_GNUC_UNUSED
435 sgen_client_binary_protocol_alloc_pinned (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
437 mono_binary_protocol_alloc_generic (obj, vtable, size, TRUE);
440 static void G_GNUC_UNUSED
441 sgen_client_binary_protocol_alloc_degraded (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
443 MONO_GC_MAJOR_OBJ_ALLOC_DEGRADED ((mword)obj, size, sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
446 static void G_GNUC_UNUSED
447 sgen_client_binary_protocol_card_scan (gpointer start, size_t size)
451 static void G_GNUC_UNUSED
452 sgen_client_binary_protocol_pin_stage (gpointer addr_ptr, gpointer addr)
456 static void G_GNUC_UNUSED
457 sgen_client_binary_protocol_cement_stage (gpointer addr)
461 static void G_GNUC_UNUSED
462 sgen_client_binary_protocol_pin (gpointer obj, gpointer vtable, size_t size)
465 if (G_UNLIKELY (MONO_GC_OBJ_PINNED_ENABLED ())) {
466 int gen = sgen_ptr_in_nursery (obj) ? GENERATION_NURSERY : GENERATION_OLD;
467 MONO_GC_OBJ_PINNED ((mword)obj,
468 sgen_safe_object_get_size (obj),
469 sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable), gen);
474 static void G_GNUC_UNUSED
475 sgen_client_binary_protocol_mark (gpointer obj, gpointer vtable, size_t size)
479 static void G_GNUC_UNUSED
480 sgen_client_binary_protocol_scan_begin (gpointer obj, gpointer vtable, size_t size)
484 static void G_GNUC_UNUSED
485 sgen_client_binary_protocol_scan_vtype_begin (gpointer obj, size_t size)
489 static void G_GNUC_UNUSED
490 sgen_client_binary_protocol_scan_process_reference (gpointer obj, gpointer ptr, gpointer value)
494 static void G_GNUC_UNUSED
495 sgen_client_binary_protocol_scan_stack (gpointer thread, gpointer stack_start, gpointer stack_end, int skip_reason)
499 static void G_GNUC_UNUSED
500 sgen_client_binary_protocol_wbarrier (gpointer ptr, gpointer value, gpointer value_vtable)
504 static void G_GNUC_UNUSED
505 sgen_client_binary_protocol_cement (gpointer ptr, gpointer vtable, size_t size)
508 if (G_UNLIKELY (MONO_GC_OBJ_CEMENTED_ENABLED())) {
509 MONO_GC_OBJ_CEMENTED ((mword)ptr, sgen_safe_object_get_size ((GCObject*)ptr),
510 sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
515 static void G_GNUC_UNUSED
516 sgen_client_binary_protocol_copy (gpointer from, gpointer to, gpointer vtable, size_t size)
519 if (G_UNLIKELY (MONO_GC_OBJ_MOVED_ENABLED ())) {
520 int dest_gen = sgen_ptr_in_nursery (to) ? GENERATION_NURSERY : GENERATION_OLD;
521 int src_gen = sgen_ptr_in_nursery (from) ? GENERATION_NURSERY : GENERATION_OLD;
522 MONO_GC_OBJ_MOVED ((mword)to, (mword)from, dest_gen, src_gen, size, sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
527 static void G_GNUC_UNUSED
528 sgen_client_binary_protocol_global_remset (gpointer ptr, gpointer value, gpointer value_vtable)
531 if (G_UNLIKELY (MONO_GC_GLOBAL_REMSET_ADD_ENABLED ())) {
532 MONO_GC_GLOBAL_REMSET_ADD ((mword)ptr, (mword)value, sgen_safe_object_get_size (value),
533 sgen_client_vtable_get_namespace (value_vtable), sgen_client_vtable_get_name (value_vtable));
538 static void G_GNUC_UNUSED
539 sgen_client_binary_protocol_mod_union_remset (gpointer obj, gpointer ptr, gpointer value, gpointer value_vtable)
543 static void G_GNUC_UNUSED
544 sgen_client_binary_protocol_ptr_update (gpointer ptr, gpointer old_value, gpointer new_value, gpointer vtable, size_t size)
548 static void G_GNUC_UNUSED
549 sgen_client_binary_protocol_cleanup (gpointer ptr, gpointer vtable, size_t size)
553 static void G_GNUC_UNUSED
554 sgen_client_binary_protocol_dislink_add (gpointer link, gpointer obj, gboolean track)
558 static void G_GNUC_UNUSED
559 sgen_client_binary_protocol_dislink_update (gpointer link, gpointer obj, gboolean track)
562 if (MONO_GC_WEAK_UPDATE_ENABLED ()) {
563 GCVTable vt = obj ? SGEN_LOAD_VTABLE (obj) : NULL;
564 MONO_GC_WEAK_UPDATE ((mword)link,
566 obj ? (mword)sgen_safe_object_get_size (obj) : (mword)0,
567 obj ? sgen_client_vtable_get_namespace (vt) : NULL,
568 obj ? sgen_client_vtable_get_name (vt) : NULL,
574 static void G_GNUC_UNUSED
575 sgen_client_binary_protocol_dislink_remove (gpointer link, gboolean track)
579 static void G_GNUC_UNUSED
580 sgen_client_binary_protocol_empty (gpointer start, size_t size)
582 if (sgen_ptr_in_nursery (start))
583 MONO_GC_NURSERY_SWEPT ((mword)start, size);
585 MONO_GC_MAJOR_SWEPT ((mword)start, size);
588 static void G_GNUC_UNUSED
589 sgen_client_binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip)
593 static void G_GNUC_UNUSED
594 sgen_client_binary_protocol_thread_restart (gpointer thread)
598 static void G_GNUC_UNUSED
599 sgen_client_binary_protocol_thread_register (gpointer thread)
603 static void G_GNUC_UNUSED
604 sgen_client_binary_protocol_thread_unregister (gpointer thread)
608 static void G_GNUC_UNUSED
609 sgen_client_binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset, gpointer value, gpointer value_vtable, gboolean value_pinned)
613 static void G_GNUC_UNUSED
614 sgen_client_binary_protocol_cement_reset (void)
618 static void G_GNUC_UNUSED
619 sgen_client_binary_protocol_domain_unload_begin (gpointer domain)
623 static void G_GNUC_UNUSED
624 sgen_client_binary_protocol_domain_unload_end (gpointer domain)
628 static void G_GNUC_UNUSED
629 sgen_client_binary_protocol_gray_enqueue (gpointer queue, gpointer cursor, gpointer value)
633 static void G_GNUC_UNUSED
634 sgen_client_binary_protocol_gray_dequeue (gpointer queue, gpointer cursor, gpointer value)
638 static void G_GNUC_UNUSED
639 sgen_client_binary_protocol_major_card_table_scan_start (long long timestamp, gboolean mod_union)
643 static void G_GNUC_UNUSED
644 sgen_client_binary_protocol_major_card_table_scan_end (long long timestamp, gboolean mod_union)
648 static void G_GNUC_UNUSED
649 sgen_client_binary_protocol_los_card_table_scan_start (long long timestamp, gboolean mod_union)
653 static void G_GNUC_UNUSED
654 sgen_client_binary_protocol_los_card_table_scan_end (long long timestamp, gboolean mod_union)
658 static void G_GNUC_UNUSED
659 sgen_client_binary_protocol_finish_gray_stack_start (long long timestamp, int generation)
663 static void G_GNUC_UNUSED
664 sgen_client_binary_protocol_finish_gray_stack_end (long long timestamp, int generation)
668 static void G_GNUC_UNUSED
669 sgen_client_binary_protocol_worker_finish (long long timestamp, gboolean forced)
673 static void G_GNUC_UNUSED
674 sgen_client_binary_protocol_evacuating_blocks (size_t block_size)
678 static void G_GNUC_UNUSED
679 sgen_client_binary_protocol_concurrent_sweep_end (long long timestamp)
683 static void G_GNUC_UNUSED
684 sgen_client_binary_protocol_header (long long check, int version, int ptr_size, gboolean little_endian)
688 static void G_GNUC_UNUSED
689 sgen_client_binary_protocol_pin_stats (int objects_pinned_in_nursery, size_t bytes_pinned_in_nursery, int objects_pinned_in_major, size_t bytes_pinned_in_major)
693 static void G_GNUC_UNUSED
694 sgen_client_binary_protocol_worker_finish_stats (int worker_index, int generation, gboolean forced, long long major_scan, long long los_scan, long long work_time)
698 static void G_GNUC_UNUSED
699 sgen_client_binary_protocol_collection_end_stats (long long major_scan, long long los_scan, long long finish_stack)
703 #define TLAB_ACCESS_INIT SgenThreadInfo *__thread_info__ = (SgenThreadInfo*)mono_tls_get_sgen_thread_info ()
704 #define IN_CRITICAL_REGION (__thread_info__->client_info.in_critical_region)
706 /* Enter must be visible before anything is done in the critical region. */
707 #define ENTER_CRITICAL_REGION do { mono_atomic_store_acquire (&IN_CRITICAL_REGION, 1); } while (0)
709 /* Exit must make sure all critical regions stores are visible before it signal the end of the region.
710 * We don't need to emit a full barrier since we
712 #define EXIT_CRITICAL_REGION do { mono_atomic_store_release (&IN_CRITICAL_REGION, 0); } while (0)
714 #ifndef DISABLE_CRITICAL_REGION
716 * We can only use a critical region in the managed allocator if the JIT supports OP_ATOMIC_STORE_I4.
718 * TODO: Query the JIT instead of this ifdef hack.
720 #if defined (TARGET_X86) || defined (TARGET_AMD64) || (defined (TARGET_ARM) && defined (HAVE_ARMV7)) || defined (TARGET_ARM64)
721 #define MANAGED_ALLOCATOR_CAN_USE_CRITICAL_REGION
725 #define SGEN_TV_DECLARE(name) gint64 name
726 #define SGEN_TV_GETTIME(tv) tv = mono_100ns_ticks ()
727 #define SGEN_TV_ELAPSED(start,end) ((gint64)(end-start))
729 guint64 mono_time_since_last_stw (void);
731 typedef MonoSemType SgenSemaphore;
733 #define SGEN_SEMAPHORE_INIT(sem,initial) mono_os_sem_init ((sem), (initial))
734 #define SGEN_SEMAPHORE_POST(sem) mono_os_sem_post ((sem))
735 #define SGEN_SEMAPHORE_WAIT(sem) mono_os_sem_wait ((sem), MONO_SEM_FLAGS_NONE)
737 gboolean sgen_has_critical_method (void);
738 gboolean sgen_is_critical_method (MonoMethod *method);
740 void sgen_set_use_managed_allocator (gboolean flag);
741 gboolean sgen_is_managed_allocator (MonoMethod *method);
742 gboolean sgen_has_managed_allocator (void);
744 void sgen_scan_for_registered_roots_in_domain (MonoDomain *domain, int root_type);
745 void sgen_null_links_for_domain (MonoDomain *domain);