Exemple #1
0
/*
 * 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;
}
Exemple #2
0
void
sgen_pinned_update_heap_boundaries (SgenPinnedAllocator *alc)
{
    SgenPinnedChunk *chunk;
    for (chunk = alc->chunk_list; chunk; chunk = chunk->block.next) {
        char *end_chunk = (char*)chunk + chunk->num_pages * FREELIST_PAGESIZE;
        sgen_update_heap_boundaries ((mword)chunk, (mword)end_chunk);
    }
}
Exemple #3
0
static void
major_sweep (void)
{
	GCMemSection *section, *prev_section;

	to_space_set_next_data ();
	unset_to_space ();

	/* unpin objects from the pinned chunks and free the unmarked ones */
	sweep_pinned_objects ();

	sgen_pinned_update_heap_boundaries (&pinned_allocator);

	/* free the unused sections */
	prev_section = NULL;
	for (section = section_list; section;) {
		GCMemSection *this_section = section;

		/* to_space doesn't need handling here */
		if (section->is_to_space) {
			section->is_to_space = FALSE;
			prev_section = section;
			section = section->block.next;
			goto update;
		}
		/* no pinning object, so the section is free */
		if (!section->pin_queue_num_entries) {
			GCMemSection *to_free;
			g_assert (!section->pin_queue_start);
			if (prev_section)
				prev_section->block.next = section->block.next;
			else
				section_list = section->block.next;
			to_free = section;
			section = section->block.next;
			free_major_section (to_free);
			continue;
		} else {
			DEBUG (6, fprintf (gc_debug_file, "Section %p has still pinned objects (%d)\n", section, section->pin_queue_num_entries));
			build_section_fragments (section);
		}
		prev_section = section;
		section = section->block.next;

	update:
		sgen_update_heap_boundaries ((mword)this_section->data, (mword)this_section->data + this_section->size);
	}

	have_swept = TRUE;
}
Exemple #4
0
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;
}