void *res;
#ifndef DISABLE_CRITICAL_REGION
TLAB_ACCESS_INIT;
+
+ if (G_UNLIKELY (has_per_allocation_action)) {
+ static int alloc_count;
+ int current_alloc = InterlockedIncrement (&alloc_count);
+
+ if (verify_before_allocs) {
+ if ((current_alloc % verify_before_allocs) == 0)
+ sgen_check_whole_heap_stw ();
+ }
+ if (collect_before_allocs) {
+ if (((current_alloc % collect_before_allocs) == 0) && nursery_section) {
+ LOCK_GC;
+ sgen_perform_collection (0, GENERATION_NURSERY, "collect-before-alloc-triggered", TRUE);
+ UNLOCK_GC;
+ }
+ }
+ }
+
ENTER_CRITICAL_REGION;
res = mono_gc_try_alloc_obj_nolock (vtable, size);
if (res) {
if (tlab_next_offset == -1 || tlab_temp_end_offset == -1)
return NULL;
#endif
-
+ if (collect_before_allocs)
+ return NULL;
if (!mono_runtime_has_tls_get ())
return NULL;
if (klass->instance_size > tlab_size)
return NULL;
if (klass->byval_arg.type == MONO_TYPE_STRING)
return mono_gc_get_managed_allocator_by_type (ATYPE_STRING);
- if (collect_before_allocs)
- return NULL;
/* Generic classes have dynamic field and can go above MAX_SMALL_OBJ_SIZE. */
if (ALIGN_TO (klass->instance_size, ALLOC_ALIGN) < MAX_SMALL_OBJ_SIZE && !mono_class_is_open_constructed_type (&klass->byval_arg))
return mono_gc_get_managed_allocator_by_type (ATYPE_SMALL);
sgen_perform_collection (size, generation_to_collect, reason, FALSE);
}
+/*
+ * LOCKING: Assumes the GC lock is held.
+ */
void
sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean wait_to_finish)
{