static gboolean ms_alloc_block (int size_index, gboolean pinned, gboolean has_references) { int size = block_obj_sizes [size_index]; int count = MS_BLOCK_FREE / size; MSBlockInfo *info; #ifndef FIXED_HEAP MSBlockHeader *header; #endif MSBlockInfo **free_blocks = FREE_BLOCKS (pinned, has_references); char *obj_start; int i; if (!mono_sgen_try_alloc_space (MS_BLOCK_SIZE, SPACE_MAJOR)) return FALSE; #ifdef FIXED_HEAP info = ms_get_empty_block (); #else info = mono_sgen_alloc_internal (INTERNAL_MEM_MS_BLOCK_INFO); #endif DEBUG (9, g_assert (count >= 2)); info->obj_size = size; info->obj_size_index = size_index; info->pinned = pinned; info->has_references = has_references; info->has_pinned = pinned; info->is_to_space = (mono_sgen_get_current_collection_generation () == GENERATION_OLD); #ifndef FIXED_HEAP info->block = ms_get_empty_block (); header = (MSBlockHeader*) info->block; header->info = info; #endif update_heap_boundaries_for_block (info); /* build free list */ obj_start = info->block + MS_BLOCK_SKIP; info->free_list = (void**)obj_start; /* we're skipping the last one - it must be nulled */ for (i = 0; i < count - 1; ++i) { char *next_obj_start = obj_start + size; *(void**)obj_start = next_obj_start; obj_start = next_obj_start; } /* the last one */ *(void**)obj_start = NULL; info->next_free = free_blocks [size_index]; free_blocks [size_index] = info; info->next = all_blocks; all_blocks = info; ++num_major_sections; return TRUE; }
static void ms_alloc_block (int size_index, gboolean pinned, gboolean has_references) { int size = block_obj_sizes [size_index]; int count = MS_BLOCK_FREE / size; #ifdef FIXED_HEAP MSBlockInfo *info = ms_get_empty_block (); #else MSBlockInfo *info = mono_sgen_alloc_internal (INTERNAL_MEM_MS_BLOCK_INFO); MSBlockHeader *header; #endif MSBlockInfo **free_blocks = FREE_BLOCKS (pinned, has_references); char *obj_start; int i; DEBUG (9, g_assert (count >= 2)); info->obj_size = size; info->pinned = pinned; info->has_references = has_references; #ifndef FIXED_HEAP info->block = ms_get_empty_block (); header = (MSBlockHeader*) info->block; header->info = info; #endif /* build free list */ obj_start = info->block + MS_BLOCK_SKIP; info->free_list = (void**)obj_start; /* we're skipping the last one - it must be nulled */ for (i = 0; i < count - 1; ++i) { char *next_obj_start = obj_start + size; *(void**)obj_start = next_obj_start; obj_start = next_obj_start; } /* the last one */ *(void**)obj_start = NULL; info->next_free = free_blocks [size_index]; free_blocks [size_index] = info; #ifndef FIXED_HEAP info->next = all_blocks; all_blocks = info; #endif ++num_major_sections; }