[sdb] Add support for DebuggerNonUserCodeAttribute.
[mono.git] / mono / metadata / sgen-alloc.c
index 333bfe1acf0e26c9f69339824093e3802f37ed3f..02a1d45bd34dd834bb7c03717fe094fd9ca53bab 100644 (file)
@@ -145,6 +145,34 @@ alloc_degraded (MonoVTable *vtable, size_t size, gboolean for_mature)
        return p;
 }
 
+static void
+zero_tlab_if_necessary (void *p, size_t size)
+{
+       if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION) {
+               memset (p, 0, size);
+       } else {
+               /*
+                * This function is called for all allocations in
+                * TLABs.  TLABs originate from fragments, which are
+                * initialized to be faux arrays.  The remainder of
+                * the fragments are zeroed out at initialization for
+                * CLEAR_AT_GC, so here we just need to make sure that
+                * the array header is zeroed.  Since we don't know
+                * whether we're called for the start of a fragment or
+                * for somewhere in between, we zero in any case, just
+                * to make sure.
+                */
+
+               if (size >= sizeof (MonoArray))
+                       memset (p, 0, sizeof (MonoArray));
+               else {
+                       static guint8 zeros [sizeof (MonoArray)];
+
+                       SGEN_ASSERT (0, !memcmp (p, zeros, size), "TLAB segment must be zeroed out.");
+               }
+       }
+}
+
 /*
  * Provide a variant that takes just the vtable for small fixed-size objects.
  * The aligned size is already computed and stored in vt->gc_descr.
@@ -273,9 +301,7 @@ mono_gc_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                                        g_assert (0);
                                }
 
-                               if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION) {
-                                       memset (p, 0, size);
-                               }
+                               zero_tlab_if_necessary (p, size);
                        } else {
                                size_t alloc_size = 0;
                                if (TLAB_START)
@@ -304,9 +330,7 @@ mono_gc_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                                TLAB_REAL_END = TLAB_START + alloc_size;
                                TLAB_TEMP_END = TLAB_START + MIN (SGEN_SCAN_START_SIZE, alloc_size);
 
-                               if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION) {
-                                       memset (TLAB_START, 0, alloc_size);
-                               }
+                               zero_tlab_if_necessary (TLAB_START, alloc_size);
 
                                /* Allocate from the TLAB */
                                p = (void*)TLAB_NEXT;
@@ -361,8 +385,7 @@ mono_gc_try_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                sgen_set_nursery_scan_start ((char*)p);
 
                /*FIXME we should use weak memory ops here. Should help specially on x86. */
-               if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION)
-                       memset (p, 0, size);
+               zero_tlab_if_necessary (p, size);
        } else {
                int available_in_tlab;
                char *real_end;
@@ -391,8 +414,7 @@ mono_gc_try_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                        if (!p)
                                return NULL;
 
-                       if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION)
-                               memset (p, 0, size);                    
+                       zero_tlab_if_necessary (p, size);
                } else {
                        size_t alloc_size = 0;
 
@@ -408,8 +430,7 @@ mono_gc_try_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                        TLAB_TEMP_END = new_next + MIN (SGEN_SCAN_START_SIZE, alloc_size);
                        sgen_set_nursery_scan_start ((char*)p);
 
-                       if (nursery_clear_policy == CLEAR_AT_TLAB_CREATION)
-                               memset (new_next, 0, alloc_size);
+                       zero_tlab_if_necessary (new_next, alloc_size);
 
                        MONO_GC_NURSERY_TLAB_ALLOC ((mword)new_next, alloc_size);
                }