/* * Allocate a new section of memory to be used as old generation. */ static GCMemSection* alloc_major_section (void) { GCMemSection *section; int scan_starts; section = sgen_alloc_os_memory_aligned (MAJOR_SECTION_SIZE, MAJOR_SECTION_SIZE, TRUE); section->next_data = section->data = (char*)section + SGEN_SIZEOF_GC_MEM_SECTION; g_assert (!((mword)section->data & 7)); section->size = MAJOR_SECTION_SIZE - SGEN_SIZEOF_GC_MEM_SECTION; section->end_data = section->data + section->size; sgen_update_heap_boundaries ((mword)section->data, (mword)section->end_data); DEBUG (3, fprintf (gc_debug_file, "New major heap section: (%p-%p), total: %lld\n", section->data, section->end_data, (long long int)mono_gc_get_heap_size ())); scan_starts = (section->size + SGEN_SCAN_START_SIZE - 1) / SGEN_SCAN_START_SIZE; section->scan_starts = sgen_alloc_internal_dynamic (sizeof (char*) * scan_starts, INTERNAL_MEM_SCAN_STARTS); section->num_scan_start = scan_starts; section->block.role = MEMORY_ROLE_GEN1; section->is_to_space = TRUE; /* add to the section list */ section->block.next = section_list; section_list = section; ++num_major_sections; return section; }
static void* major_alloc_heap (mword nursery_size, mword nursery_align, int the_nursery_bits) { if (nursery_align) nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE); else nursery_start = sgen_alloc_os_memory (nursery_size, TRUE); nursery_end = nursery_start + nursery_size; nursery_bits = the_nursery_bits; return nursery_start; }
static void* major_alloc_heap (mword nursery_size, mword nursery_align, int the_nursery_bits) { if (nursery_align) nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE, "nursery"); else nursery_start = sgen_alloc_os_memory (nursery_size, SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE, "nursery"); nursery_end = nursery_start + nursery_size; nursery_bits = the_nursery_bits; return nursery_start; }
static SgenPinnedChunk* alloc_pinned_chunk (SgenPinnedAllocator *alc) { SgenPinnedChunk *chunk; int offset; int size = SGEN_PINNED_CHUNK_SIZE; chunk = sgen_alloc_os_memory_aligned (size, size, TRUE); chunk->block.role = MEMORY_ROLE_PINNED; sgen_update_heap_boundaries ((mword)chunk, ((mword)chunk + size)); pinned_chunk_bytes_alloced += size; /* setup the bookeeping fields */ chunk->num_pages = size / FREELIST_PAGESIZE; offset = G_STRUCT_OFFSET (SgenPinnedChunk, data); chunk->page_sizes = (void*)((char*)chunk + offset); offset += sizeof (int) * chunk->num_pages; offset = SGEN_ALIGN_UP (offset); chunk->free_list = (void*)((char*)chunk + offset); offset += sizeof (void*) * SGEN_PINNED_FREELIST_NUM_SLOTS; offset = SGEN_ALIGN_UP (offset); chunk->start_data = (void*)((char*)chunk + offset); /* allocate the first page to the freelist */ chunk->page_sizes [0] = PINNED_FIRST_SLOT_SIZE; build_freelist (alc, chunk, slot_for_size (PINNED_FIRST_SLOT_SIZE), PINNED_FIRST_SLOT_SIZE, chunk->start_data, ((char*)chunk + FREELIST_PAGESIZE)); sgen_debug_printf (4, "Allocated pinned chunk %p, size: %d\n", chunk, size); chunk->block.next = alc->chunk_list; alc->chunk_list = chunk; chunk->allocator = alc; return chunk; }