[gc] Move OOM handling into the runtime from the GC.
[mono.git] / mono / sgen / sgen-alloc.c
index 413388810f8b4ec8053fe82bd6acd65f235a9af1..349eff5401457757c9757591a398a275d7990aab 100644 (file)
@@ -196,7 +196,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
         */
 
        if (real_size > SGEN_MAX_SMALL_OBJ_SIZE) {
-               p = sgen_los_alloc_large_inner (vtable, ALIGN_UP (real_size));
+               p = (void **)sgen_los_alloc_large_inner (vtable, ALIGN_UP (real_size));
        } else {
                /* tlab_next and tlab_temp_end are TLS vars so accessing them might be expensive */
 
@@ -252,7 +252,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
                        available_in_tlab = (int)(TLAB_REAL_END - TLAB_NEXT);//We'll never have tlabs > 2Gb
                        if (size > tlab_size || available_in_tlab > SGEN_MAX_NURSERY_WASTE) {
                                /* Allocate directly from the nursery */
-                               p = sgen_nursery_alloc (size);
+                               p = (void **)sgen_nursery_alloc (size);
                                if (!p) {
                                        /*
                                         * We couldn't allocate from the nursery, so we try
@@ -273,7 +273,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
                                         */
                                        sgen_ensure_free_space (real_size);
                                        if (!degraded_mode)
-                                               p = sgen_nursery_alloc (size);
+                                               p = (void **)sgen_nursery_alloc (size);
                                }
                                if (!p)
                                        return alloc_degraded (vtable, size, FALSE);
@@ -285,12 +285,12 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
                                        SGEN_LOG (3, "Retire TLAB: %p-%p [%ld]", TLAB_START, TLAB_REAL_END, (long)(TLAB_REAL_END - TLAB_NEXT - size));
                                sgen_nursery_retire_region (p, available_in_tlab);
 
-                               p = sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
+                               p = (void **)sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
                                if (!p) {
                                        /* See comment above in similar case. */
                                        sgen_ensure_free_space (tlab_size);
                                        if (!degraded_mode)
-                                               p = sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
+                                               p = (void **)sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
                                }
                                if (!p)
                                        return alloc_degraded (vtable, size, FALSE);
@@ -304,7 +304,7 @@ sgen_alloc_obj_nolock (GCVTable vtable, size_t size)
                                zero_tlab_if_necessary (TLAB_START, alloc_size);
 
                                /* Allocate from the TLAB */
-                               p = (void*)TLAB_NEXT;
+                               p = (void **)TLAB_NEXT;
                                TLAB_NEXT += size;
                                sgen_set_nursery_scan_start ((char*)p);
                        }
@@ -349,7 +349,7 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
 
        if (G_UNLIKELY (size > tlab_size)) {
                /* Allocate directly from the nursery */
-               p = sgen_nursery_alloc (size);
+               p = (void **)sgen_nursery_alloc (size);
                if (!p)
                        return NULL;
                sgen_set_nursery_scan_start ((char*)p);
@@ -380,7 +380,7 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
                        }
                } else if (available_in_tlab > SGEN_MAX_NURSERY_WASTE) {
                        /* Allocate directly from the nursery */
-                       p = sgen_nursery_alloc (size);
+                       p = (void **)sgen_nursery_alloc (size);
                        if (!p)
                                return NULL;
 
@@ -389,7 +389,7 @@ sgen_try_alloc_obj_nolock (GCVTable vtable, size_t size)
                        size_t alloc_size = 0;
 
                        sgen_nursery_retire_region (p, available_in_tlab);
-                       new_next = sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
+                       new_next = (char *)sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
                        p = (void**)new_next;
                        if (!p)
                                return NULL;
@@ -426,8 +426,6 @@ sgen_alloc_obj (GCVTable vtable, size_t size)
        if (!SGEN_CAN_ALIGN_UP (size))
                return NULL;
 
-#ifndef DISABLE_CRITICAL_REGION
-
        if (G_UNLIKELY (has_per_allocation_action)) {
                static int alloc_count;
                int current_alloc = InterlockedIncrement (&alloc_count);
@@ -452,12 +450,10 @@ sgen_alloc_obj (GCVTable vtable, size_t size)
                return res;
        }
        EXIT_CRITICAL_REGION;
-#endif
+
        LOCK_GC;
        res = sgen_alloc_obj_nolock (vtable, size);
        UNLOCK_GC;
-       if (G_UNLIKELY (!res))
-               sgen_client_out_of_memory (size);
        return res;
 }
 
@@ -478,7 +474,7 @@ sgen_alloc_obj_pinned (GCVTable vtable, size_t size)
 
        if (size > SGEN_MAX_SMALL_OBJ_SIZE) {
                /* large objects are always pinned anyway */
-               p = sgen_los_alloc_large_inner (vtable, size);
+               p = (GCObject *)sgen_los_alloc_large_inner (vtable, size);
        } else {
                SGEN_ASSERT (9, sgen_client_vtable_is_inited (vtable), "class %s:%s is not initialized", sgen_client_vtable_get_namespace (vtable), sgen_client_vtable_get_name (vtable));
                p = major_collector.alloc_small_pinned_obj (vtable, size, SGEN_VTABLE_HAS_REFERENCES (vtable));
@@ -554,9 +550,6 @@ sgen_init_allocator (void)
 
        mono_tls_key_set_offset (TLS_KEY_SGEN_TLAB_NEXT_ADDR, tlab_next_addr_offset);
        mono_tls_key_set_offset (TLS_KEY_SGEN_TLAB_TEMP_END, tlab_temp_end_offset);
-
-       g_assert (tlab_next_addr_offset != -1);
-       g_assert (tlab_temp_end_offset != -1);
 #endif
 
 #ifdef HEAVY_STATISTICS