void caml_init_domains(uintnat minor_size) { int i; uintnat size; void* heaps_base; /* sanity check configuration */ if (caml_mem_round_up_pages(1 << Minor_heap_align_bits) != (1 << Minor_heap_align_bits)) caml_fatal_error("Minor_heap_align_bits misconfigured for this platform"); /* reserve memory space for minor heaps */ size = (uintnat)1 << (Minor_heap_sel_bits + Minor_heap_align_bits); /* To ensure Is_foreign gives no false positives, we reserve twice the address space needed and only use the first half */ heaps_base = caml_mem_map(size*2, size*2, 1 /* reserve_only */); if (!heaps_base) caml_raise_out_of_memory(); minor_heaps_base = (uintnat) heaps_base; caml_plat_mutex_init(&all_domains_lock); for (i = 0; i < Max_domains; i++) { struct dom_internal* dom = &all_domains[i]; caml_plat_mutex_init(&dom->roots_lock); dom->running = 0; dom->state.id = i; dom->tls_area = minor_heaps_base + (uintnat)(1 << Minor_heap_align_bits) * (uintnat)i; dom->tls_area_end = caml_mem_round_up_pages(dom->tls_area + sizeof(struct caml_domain_state)); dom->minor_heap_area = /* skip guard page */ caml_mem_round_up_pages(dom->tls_area_end + 1); dom->minor_heap_area_end = dom->minor_heap_area + (1 << Minor_heap_align_bits); } create_domain(minor_size, 1); if (!domain_self) caml_fatal_error("Failed to create main domain"); caml_init_global_roots(); caml_init_signal_handling(); }
struct caml_heap_state* caml_init_shared_heap() { int i; struct caml_heap_state* heap; if (caml_domain_self()->is_main) { caml_plat_mutex_init(&pool_freelist.lock); } Assert(NOT_MARKABLE == Promotedhd_hd(0)); heap = caml_stat_alloc(sizeof(struct caml_heap_state)); heap->free_pools = 0; heap->num_free_pools = 0; for (i = 0; i<NUM_SIZECLASSES; i++) { heap->avail_pools[i] = heap->full_pools[i] = heap->unswept_avail_pools[i] = heap->unswept_full_pools[i] = 0; } heap->next_to_sweep = 0; heap->swept_large = 0; heap->unswept_large = 0; heap->owner = caml_domain_self(); heap->pools_allocated = 0; heap->large_bytes_allocated = 0; return heap; }
void caml_init_major_gc() { caml_domain_state->mark_stack = caml_stat_alloc(MARK_STACK_SIZE * sizeof(value)); caml_domain_state->mark_stack_count = 0; caml_plat_mutex_init(&pools_to_rescan_lock); }
void caml_init_global_roots() { caml_plat_mutex_init(&roots_mutex); }