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.
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)
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;
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;
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;
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);
}
* 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);