Merge pull request #5198 from BrzVlad/fix-binprot-stats
[mono-project.git] / mono / metadata / sgen-client-mono.h
bloba5ec02d480e21cb4477a3cf7e5f1eb4416465d0a
1 /**
2 * \file
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.
8 */
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)
23 return obj->vtable;
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 {
34 MonoThreadInfo info;
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
48 been scanned.
50 gboolean gc_disabled;
52 #ifdef SGEN_POSIX_STW
53 /* This is -1 until the first suspend. */
54 int signal;
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. */
57 #endif
59 gpointer runtime_data;
61 void *stack_end;
62 void *stack_start;
63 void *stack_start_limit;
65 MonoContext ctx; /* ditto */
68 #else
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);
83 enum {
84 INTERNAL_MEM_EPHEMERON_LINK = INTERNAL_MEM_FIRST_CLIENT,
85 INTERNAL_MEM_MOVED_OBJECT,
86 INTERNAL_MEM_MAX
89 static inline mword
90 sgen_mono_array_size (GCVTable vtable, MonoArray *array, mword *bounds_size, mword descr)
92 mword size, size_without_bounds;
93 int element_size;
95 if ((descr & DESC_TYPE_MASK) == DESC_TYPE_VECTOR)
96 element_size = ((descr) >> VECTOR_ELSIZE_SHIFT) & MAX_ELEMENT_SIZE;
97 else
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;
108 if (bounds_size)
109 *bounds_size = size - size_without_bounds;
110 return size;
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);
129 } else {
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
138 * collector.
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");
149 return size;
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 (MONO_PROFILER_ENABLED (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; \
213 LOCK_GC; \
214 SGEN_ASSERT (0, start, "Write barrier outside an object?"); \
215 if (start) { \
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"); \
220 UNLOCK_GC; \
222 } while (0)
223 #else
224 #define sgen_client_wbarrier_generic_nostore_check(ptr)
225 #endif
227 static gboolean G_GNUC_UNUSED
228 sgen_client_object_has_critical_finalizer (GCObject *obj)
230 MonoClass *klass;
232 if (!mono_defaults.critical_finalizer_object)
233 return FALSE;
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_RAISE (gc_event, (MONO_GC_EVENT_START, generation));
298 #ifndef DISABLE_PERFCOUNTERS
299 if (generation == GENERATION_NURSERY)
300 mono_perfcounters->gc_collections0++;
301 else
302 mono_perfcounters->gc_collections1++;
303 #endif
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_RAISE (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)
388 static void G_GNUC_UNUSED
389 sgen_client_binary_protocol_mark_end (int generation)
393 static void G_GNUC_UNUSED
394 sgen_client_binary_protocol_reclaim_start (int generation)
398 static void G_GNUC_UNUSED
399 sgen_client_binary_protocol_reclaim_end (int generation)
403 static void
404 mono_binary_protocol_alloc_generic (gpointer obj, gpointer vtable, size_t size, gboolean pinned)
406 #ifdef ENABLE_DTRACE
407 const char *namespace = sgen_client_vtable_get_namespace (vtable);
408 const char *name = sgen_client_vtable_get_name (vtable);
410 if (sgen_ptr_in_nursery (obj)) {
411 if (G_UNLIKELY (MONO_GC_NURSERY_OBJ_ALLOC_ENABLED ()))
412 MONO_GC_NURSERY_OBJ_ALLOC ((mword)obj, size, namespace, name);
413 } else {
414 if (size > SGEN_MAX_SMALL_OBJ_SIZE) {
415 if (G_UNLIKELY (MONO_GC_MAJOR_OBJ_ALLOC_LARGE_ENABLED ()))
416 MONO_GC_MAJOR_OBJ_ALLOC_LARGE ((mword)obj, size, namespace, name);
417 } else if (pinned) {
418 MONO_GC_MAJOR_OBJ_ALLOC_PINNED ((mword)obj, size, namespace, name);
421 #endif
424 static void G_GNUC_UNUSED
425 sgen_client_binary_protocol_alloc (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
427 mono_binary_protocol_alloc_generic (obj, vtable, size, FALSE);
430 static void G_GNUC_UNUSED
431 sgen_client_binary_protocol_alloc_pinned (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
433 mono_binary_protocol_alloc_generic (obj, vtable, size, TRUE);
436 static void G_GNUC_UNUSED
437 sgen_client_binary_protocol_alloc_degraded (gpointer obj, gpointer vtable, size_t size, gpointer provenance)
439 MONO_GC_MAJOR_OBJ_ALLOC_DEGRADED ((mword)obj, size, sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
442 static void G_GNUC_UNUSED
443 sgen_client_binary_protocol_card_scan (gpointer start, size_t size)
447 static void G_GNUC_UNUSED
448 sgen_client_binary_protocol_pin_stage (gpointer addr_ptr, gpointer addr)
452 static void G_GNUC_UNUSED
453 sgen_client_binary_protocol_cement_stage (gpointer addr)
457 static void G_GNUC_UNUSED
458 sgen_client_binary_protocol_pin (gpointer obj, gpointer vtable, size_t size)
460 #ifdef ENABLE_DTRACE
461 if (G_UNLIKELY (MONO_GC_OBJ_PINNED_ENABLED ())) {
462 int gen = sgen_ptr_in_nursery (obj) ? GENERATION_NURSERY : GENERATION_OLD;
463 MONO_GC_OBJ_PINNED ((mword)obj,
464 sgen_safe_object_get_size (obj),
465 sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable), gen);
467 #endif
470 static void G_GNUC_UNUSED
471 sgen_client_binary_protocol_mark (gpointer obj, gpointer vtable, size_t size)
475 static void G_GNUC_UNUSED
476 sgen_client_binary_protocol_scan_begin (gpointer obj, gpointer vtable, size_t size)
480 static void G_GNUC_UNUSED
481 sgen_client_binary_protocol_scan_vtype_begin (gpointer obj, size_t size)
485 static void G_GNUC_UNUSED
486 sgen_client_binary_protocol_scan_process_reference (gpointer obj, gpointer ptr, gpointer value)
490 static void G_GNUC_UNUSED
491 sgen_client_binary_protocol_scan_stack (gpointer thread, gpointer stack_start, gpointer stack_end, int skip_reason)
495 static void G_GNUC_UNUSED
496 sgen_client_binary_protocol_wbarrier (gpointer ptr, gpointer value, gpointer value_vtable)
500 static void G_GNUC_UNUSED
501 sgen_client_binary_protocol_cement (gpointer ptr, gpointer vtable, size_t size)
503 #ifdef ENABLE_DTRACE
504 if (G_UNLIKELY (MONO_GC_OBJ_CEMENTED_ENABLED())) {
505 MONO_GC_OBJ_CEMENTED ((mword)ptr, sgen_safe_object_get_size ((GCObject*)ptr),
506 sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
508 #endif
511 static void G_GNUC_UNUSED
512 sgen_client_binary_protocol_copy (gpointer from, gpointer to, gpointer vtable, size_t size)
514 #ifdef ENABLE_DTRACE
515 if (G_UNLIKELY (MONO_GC_OBJ_MOVED_ENABLED ())) {
516 int dest_gen = sgen_ptr_in_nursery (to) ? GENERATION_NURSERY : GENERATION_OLD;
517 int src_gen = sgen_ptr_in_nursery (from) ? GENERATION_NURSERY : GENERATION_OLD;
518 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));
520 #endif
523 static void G_GNUC_UNUSED
524 sgen_client_binary_protocol_global_remset (gpointer ptr, gpointer value, gpointer value_vtable)
526 #ifdef ENABLE_DTRACE
527 if (G_UNLIKELY (MONO_GC_GLOBAL_REMSET_ADD_ENABLED ())) {
528 MONO_GC_GLOBAL_REMSET_ADD ((mword)ptr, (mword)value, sgen_safe_object_get_size (value),
529 sgen_client_vtable_get_namespace (value_vtable), sgen_client_vtable_get_name (value_vtable));
531 #endif
534 static void G_GNUC_UNUSED
535 sgen_client_binary_protocol_mod_union_remset (gpointer obj, gpointer ptr, gpointer value, gpointer value_vtable)
539 static void G_GNUC_UNUSED
540 sgen_client_binary_protocol_ptr_update (gpointer ptr, gpointer old_value, gpointer new_value, gpointer vtable, size_t size)
544 static void G_GNUC_UNUSED
545 sgen_client_binary_protocol_cleanup (gpointer ptr, gpointer vtable, size_t size)
549 static void G_GNUC_UNUSED
550 sgen_client_binary_protocol_dislink_add (gpointer link, gpointer obj, gboolean track)
554 static void G_GNUC_UNUSED
555 sgen_client_binary_protocol_dislink_update (gpointer link, gpointer obj, gboolean track)
557 #ifdef ENABLE_DTRACE
558 if (MONO_GC_WEAK_UPDATE_ENABLED ()) {
559 GCVTable vt = obj ? SGEN_LOAD_VTABLE (obj) : NULL;
560 MONO_GC_WEAK_UPDATE ((mword)link,
561 (mword)obj,
562 obj ? (mword)sgen_safe_object_get_size (obj) : (mword)0,
563 obj ? sgen_client_vtable_get_namespace (vt) : NULL,
564 obj ? sgen_client_vtable_get_name (vt) : NULL,
565 track ? 1 : 0);
567 #endif
570 static void G_GNUC_UNUSED
571 sgen_client_binary_protocol_dislink_remove (gpointer link, gboolean track)
575 static void G_GNUC_UNUSED
576 sgen_client_binary_protocol_empty (gpointer start, size_t size)
578 if (sgen_ptr_in_nursery (start))
579 MONO_GC_NURSERY_SWEPT ((mword)start, size);
580 else
581 MONO_GC_MAJOR_SWEPT ((mword)start, size);
584 static void G_GNUC_UNUSED
585 sgen_client_binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip)
589 static void G_GNUC_UNUSED
590 sgen_client_binary_protocol_thread_restart (gpointer thread)
594 static void G_GNUC_UNUSED
595 sgen_client_binary_protocol_thread_register (gpointer thread)
599 static void G_GNUC_UNUSED
600 sgen_client_binary_protocol_thread_unregister (gpointer thread)
604 static void G_GNUC_UNUSED
605 sgen_client_binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset, gpointer value, gpointer value_vtable, gboolean value_pinned)
609 static void G_GNUC_UNUSED
610 sgen_client_binary_protocol_cement_reset (void)
614 static void G_GNUC_UNUSED
615 sgen_client_binary_protocol_domain_unload_begin (gpointer domain)
619 static void G_GNUC_UNUSED
620 sgen_client_binary_protocol_domain_unload_end (gpointer domain)
624 static void G_GNUC_UNUSED
625 sgen_client_binary_protocol_gray_enqueue (gpointer queue, gpointer cursor, gpointer value)
629 static void G_GNUC_UNUSED
630 sgen_client_binary_protocol_gray_dequeue (gpointer queue, gpointer cursor, gpointer value)
634 static void G_GNUC_UNUSED
635 sgen_client_binary_protocol_major_card_table_scan_start (long long timestamp, gboolean mod_union)
639 static void G_GNUC_UNUSED
640 sgen_client_binary_protocol_major_card_table_scan_end (long long timestamp, gboolean mod_union)
644 static void G_GNUC_UNUSED
645 sgen_client_binary_protocol_los_card_table_scan_start (long long timestamp, gboolean mod_union)
649 static void G_GNUC_UNUSED
650 sgen_client_binary_protocol_los_card_table_scan_end (long long timestamp, gboolean mod_union)
654 static void G_GNUC_UNUSED
655 sgen_client_binary_protocol_finish_gray_stack_start (long long timestamp, int generation)
659 static void G_GNUC_UNUSED
660 sgen_client_binary_protocol_finish_gray_stack_end (long long timestamp, int generation)
664 static void G_GNUC_UNUSED
665 sgen_client_binary_protocol_worker_finish (long long timestamp, gboolean forced)
669 static void G_GNUC_UNUSED
670 sgen_client_binary_protocol_evacuating_blocks (size_t block_size)
674 static void G_GNUC_UNUSED
675 sgen_client_binary_protocol_concurrent_sweep_end (long long timestamp)
679 static void G_GNUC_UNUSED
680 sgen_client_binary_protocol_header (long long check, int version, int ptr_size, gboolean little_endian)
684 static void G_GNUC_UNUSED
685 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)
689 static void G_GNUC_UNUSED
690 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)
694 static void G_GNUC_UNUSED
695 sgen_client_binary_protocol_collection_end_stats (long long major_scan, long long los_scan, long long finish_stack)
699 #define TLAB_ACCESS_INIT SgenThreadInfo *__thread_info__ = (SgenThreadInfo*)mono_tls_get_sgen_thread_info ()
700 #define IN_CRITICAL_REGION (__thread_info__->client_info.in_critical_region)
702 /* Enter must be visible before anything is done in the critical region. */
703 #define ENTER_CRITICAL_REGION do { mono_atomic_store_acquire (&IN_CRITICAL_REGION, 1); } while (0)
705 /* Exit must make sure all critical regions stores are visible before it signal the end of the region.
706 * We don't need to emit a full barrier since we
708 #define EXIT_CRITICAL_REGION do { mono_atomic_store_release (&IN_CRITICAL_REGION, 0); } while (0)
710 #ifndef DISABLE_CRITICAL_REGION
712 * We can only use a critical region in the managed allocator if the JIT supports OP_ATOMIC_STORE_I4.
714 * TODO: Query the JIT instead of this ifdef hack.
716 #if defined (TARGET_X86) || defined (TARGET_AMD64) || (defined (TARGET_ARM) && defined (HAVE_ARMV7)) || defined (TARGET_ARM64)
717 #define MANAGED_ALLOCATOR_CAN_USE_CRITICAL_REGION
718 #endif
719 #endif
721 #define SGEN_TV_DECLARE(name) gint64 name
722 #define SGEN_TV_GETTIME(tv) tv = mono_100ns_ticks ()
723 #define SGEN_TV_ELAPSED(start,end) ((gint64)(end-start))
725 guint64 mono_time_since_last_stw (void);
727 typedef MonoSemType SgenSemaphore;
729 #define SGEN_SEMAPHORE_INIT(sem,initial) mono_os_sem_init ((sem), (initial))
730 #define SGEN_SEMAPHORE_POST(sem) mono_os_sem_post ((sem))
731 #define SGEN_SEMAPHORE_WAIT(sem) mono_os_sem_wait ((sem), MONO_SEM_FLAGS_NONE)
733 gboolean sgen_has_critical_method (void);
734 gboolean sgen_is_critical_method (MonoMethod *method);
736 void sgen_set_use_managed_allocator (gboolean flag);
737 gboolean sgen_is_managed_allocator (MonoMethod *method);
738 gboolean sgen_has_managed_allocator (void);
740 void sgen_scan_for_registered_roots_in_domain (MonoDomain *domain, int root_type);
741 void sgen_null_links_for_domain (MonoDomain *domain);
743 #endif