X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fsgen-alloc.c;h=02a1d45bd34dd834bb7c03717fe094fd9ca53bab;hb=2facf4db1f2cc64f9d934ec6ed880765d9ed9074;hp=ffdb0c485528c572ad5d160ceeb7ad31fac4aa4b;hpb=b57fcaa28b7108c701b378a27f772917c225d033;p=mono.git diff --git a/mono/metadata/sgen-alloc.c b/mono/metadata/sgen-alloc.c index ffdb0c48552..02a1d45bd34 100644 --- a/mono/metadata/sgen-alloc.c +++ b/mono/metadata/sgen-alloc.c @@ -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); } @@ -799,7 +820,8 @@ create_allocator (int atype) * case compare signed to distinguish between them. */ mono_mb_emit_ldarg (mb, 1); - mono_mb_emit_ptr (mb, (gpointer) MONO_ARRAY_MAX_INDEX); + mono_mb_emit_icon (mb, MONO_ARRAY_MAX_INDEX); + mono_mb_emit_byte (mb, CEE_CONV_U); pos = mono_mb_emit_short_branch (mb, CEE_BLE_UN_S); mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);