/* Initialize the allocator */ int ialloc_init(gs_dual_memory_t *dmem, gs_memory_t * rmem, uint chunk_size, bool level2) { gs_ref_memory_t *ilmem = ialloc_alloc_state(rmem, chunk_size); gs_ref_memory_t *ilmem_stable = ialloc_alloc_state(rmem, chunk_size); gs_ref_memory_t *igmem = 0; gs_ref_memory_t *igmem_stable = 0; gs_ref_memory_t *ismem = ialloc_alloc_state(rmem, chunk_size); int i; if (ilmem == 0 || ilmem_stable == 0 || ismem == 0) goto fail; ilmem->stable_memory = (gs_memory_t *)ilmem_stable; if (level2) { igmem = ialloc_alloc_state(rmem, chunk_size); igmem_stable = ialloc_alloc_state(rmem, chunk_size); if (igmem == 0 || igmem_stable == 0) goto fail; igmem->stable_memory = (gs_memory_t *)igmem_stable; } else igmem = ilmem, igmem_stable = ilmem_stable; for (i = 0; i < countof(dmem->spaces_indexed); i++) dmem->spaces_indexed[i] = 0; dmem->space_local = ilmem; dmem->space_global = igmem; dmem->space_system = ismem; dmem->spaces.vm_reclaim = gs_gc_reclaim; /* real GC */ dmem->reclaim = 0; /* no interpreter GC yet */ /* Level 1 systems have only local VM. */ igmem->space = avm_global; igmem_stable->space = avm_global; ilmem->space = avm_local; /* overrides if ilmem == igmem */ ilmem_stable->space = avm_local; /* ditto */ ismem->space = avm_system; # if IGC_PTR_STABILITY_CHECK igmem->space_id = (i_vm_global << 1) + 1; igmem_stable->space_id = i_vm_global << 1; ilmem->space_id = (i_vm_local << 1) + 1; /* overrides if ilmem == igmem */ ilmem_stable->space_id = i_vm_local << 1; /* ditto */ ismem->space_id = (i_vm_system << 1); # endif ialloc_set_space(dmem, avm_global); return 0; fail: gs_free_object(rmem, igmem_stable, "ialloc_init failure"); gs_free_object(rmem, igmem, "ialloc_init failure"); gs_free_object(rmem, ismem, "ialloc_init failure"); gs_free_object(rmem, ilmem_stable, "ialloc_init failure"); gs_free_object(rmem, ilmem, "ialloc_init failure"); return_error(e_VMerror); }
/* Create an allocator with a fixed memory limit. */ static int alloc_render_memory(gs_memory_t **final_allocator, gs_memory_t *base_allocator, long space) { gs_ref_memory_t *rmem = ialloc_alloc_state((gs_memory_t *)base_allocator, space); vm_spaces spaces; int i, code; if (rmem == 0) return_error(gs_error_VMerror); code = ialloc_add_chunk(rmem, space, "alloc_render_memory"); if (code < 0) { gs_memory_free_all((gs_memory_t *)rmem, FREE_ALL_EVERYTHING, "alloc_render_memory"); return code; } *final_allocator = (gs_memory_t *)rmem; /* Call the reclaim procedure to delete the string marking tables */ /* Only need this once since no other chunks will ever exist */ for ( i = 0; i < countof(spaces_indexed); ++i ) spaces_indexed[i] = 0; space_local = space_global = (gs_ref_memory_t *)rmem; spaces.vm_reclaim = gs_nogc_reclaim; /* no real GC on this chunk */ GS_RECLAIM(&spaces, false); return 0; }
/* Initialize the allocator */ void ialloc_init(gs_memory_t *mem, uint chunk_size, bool level2) { gs_ref_memory_t *ilmem = ialloc_alloc_state(mem, chunk_size); gs_ref_memory_t *igmem = (level2 ? ialloc_alloc_state(mem, chunk_size) : ilmem); gs_ref_memory_t *ismem = ialloc_alloc_state(mem, chunk_size); int i; for ( i = 0; i < countof(gs_imemory.spaces.indexed); i++ ) gs_imemory.spaces.indexed[i] = 0; gs_imemory.space_local = ilmem; gs_imemory.space_global = igmem; gs_imemory.space_system = ismem; gs_imemory.reclaim = 0; /* Level 1 systems have only local VM. */ igmem->space = avm_global; ilmem->space = avm_local; /* overrides if ilmem == igmem */ igmem->global = ilmem->global = igmem; ismem->space = avm_system; ialloc_set_space(&gs_imemory, avm_global); }