void factor_vm::init_factor(vm_parameters *p) { /* Kilobytes */ p->datastack_size = align_page(p->datastack_size << 10); p->retainstack_size = align_page(p->retainstack_size << 10); p->callstack_size = align_page(p->callstack_size << 10); p->callback_size = align_page(p->callback_size << 10); /* Megabytes */ p->young_size <<= 20; p->aging_size <<= 20; p->tenured_size <<= 20; p->code_size <<= 20; /* Disable GC during init as a sanity check */ gc_off = true; /* OS-specific initialization */ early_init(); const vm_char *executable_path = vm_executable_path(); if(executable_path) p->executable_path = executable_path; if(p->image_path == NULL) p->image_path = default_image_path(); srand((unsigned int)nano_count()); init_ffi(); init_contexts(p->datastack_size,p->retainstack_size,p->callstack_size); init_callbacks(p->callback_size); load_image(p); init_c_io(); init_inline_caching((int)p->max_pic_size); if(p->signals) init_signals(); if(p->console) open_console(); init_profiler(); special_objects[OBJ_CPU] = allot_alien(false_object,(cell)FACTOR_CPU_STRING); special_objects[OBJ_OS] = allot_alien(false_object,(cell)FACTOR_OS_STRING); special_objects[OBJ_CELL_SIZE] = tag_fixnum(sizeof(cell)); special_objects[OBJ_EXECUTABLE] = allot_alien(false_object,(cell)p->executable_path); special_objects[OBJ_ARGS] = false_object; special_objects[OBJ_EMBEDDED] = false_object; special_objects[OBJ_VM_COMPILER] = allot_alien(false_object,(cell)FACTOR_COMPILER_VERSION); /* We can GC now */ gc_off = false; if(!to_boolean(special_objects[OBJ_STAGE2])) prepare_boot_image(); }
void factorvm::init_factor(vm_parameters *p) { /* Kilobytes */ p->ds_size = align_page(p->ds_size << 10); p->rs_size = align_page(p->rs_size << 10); /* Megabytes */ p->young_size <<= 20; p->aging_size <<= 20; p->tenured_size <<= 20; p->code_size <<= 20; /* Disable GC during init as a sanity check */ gc_off = true; /* OS-specific initialization */ early_init(); const vm_char *executable_path = vm_executable_path(); if(executable_path) p->executable_path = executable_path; if(p->image_path == NULL) p->image_path = default_image_path(); srand(current_micros()); init_ffi(); init_stacks(p->ds_size,p->rs_size); load_image(p); init_c_io(); init_inline_caching(p->max_pic_size); init_signals(); if(p->console) open_console(); init_profiler(); userenv[CPU_ENV] = allot_alien(F,(cell)FACTOR_CPU_STRING); userenv[OS_ENV] = allot_alien(F,(cell)FACTOR_OS_STRING); userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(cell)); userenv[EXECUTABLE_ENV] = allot_alien(F,(cell)p->executable_path); userenv[ARGS_ENV] = F; userenv[EMBEDDED_ENV] = F; /* We can GC now */ gc_off = false; if(userenv[STAGE2_ENV] == F) { userenv[STACK_TRACES_ENV] = tag_boolean(p->stack_traces); do_stage1_init(); } }
/* Get things started */ void init_factor(F_PARAMETERS *p) { /* Kilobytes */ p->ds_size = align_page(p->ds_size << 10); p->rs_size = align_page(p->rs_size << 10); /* Megabytes */ p->young_size <<= 20; p->aging_size <<= 20; p->tenured_size <<= 20; p->code_size <<= 20; /* Disable GC during init as a sanity check */ gc_off = true; /* OS-specific initialization */ early_init(); if(p->image == NULL) p->image = default_image_path(); srand(current_micros()); init_ffi(); init_stacks(p->ds_size,p->rs_size); load_image(p); init_c_io(); init_signals(); if(p->console) open_console(); stack_chain = NULL; profiling_p = false; performing_gc = false; last_code_heap_scan = NURSERY; collecting_aging_again = false; userenv[CPU_ENV] = tag_object(from_char_string(FACTOR_CPU_STRING)); userenv[OS_ENV] = tag_object(from_char_string(FACTOR_OS_STRING)); userenv[CELL_SIZE_ENV] = tag_fixnum(sizeof(CELL)); userenv[STACK_TRACES_ENV] = tag_boolean(p->stack_traces); /* We can GC now */ gc_off = false; if(!stage2) do_stage1_init(); }
code_heap::code_heap(cell size) { if(size > ((u64)1 << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size); seg = new segment(align_page(size),true); if(!seg) fatal_error("Out of memory in heap allocator",size); allocator = new free_list_allocator<code_block>(size,seg->start); }
/* This malloc-style heap code is reasonably generic. Maybe in the future, it will be used for the data heap too, if we ever get incremental mark/sweep/compact GC. */ void new_heap(F_HEAP *heap, CELL size) { heap->segment = alloc_segment(align_page(size)); if(!heap->segment) fatal_error("Out of memory in new_heap",size); heap->free_list = NULL; }
heap::heap(bool secure_gc_, cell size) : secure_gc(secure_gc_) { if(size > (1L << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size); seg = new segment(align_page(size)); if(!seg) fatal_error("Out of memory in heap allocator",size); clear_free_list(); }
heap::heap(factor_vm *myvm_, cell size) { myvm = myvm_; seg = new segment(myvm,align_page(size)); if(!seg) fatal_error("Out of memory in new_heap",size); clear_free_list(); }
code_heap::code_heap(cell size) { if(size > ((u64)1 << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size); seg = new segment(align_page(size),true); if(!seg) fatal_error("Out of memory in code_heap constructor",size); cell start = seg->start + seh_area_size; allocator = new free_list_allocator<code_block>(seg->end - start,start); /* See os-windows-x86.64.cpp for seh_area usage */ seh_area = (char *)seg->start; }
void factor_vm::init_factor(vm_parameters* p) { // Kilobytes p->datastack_size = align_page(p->datastack_size << 10); p->retainstack_size = align_page(p->retainstack_size << 10); p->callstack_size = align_page(p->callstack_size << 10); p->callback_size = align_page(p->callback_size << 10); // Megabytes p->young_size <<= 20; p->aging_size <<= 20; p->tenured_size <<= 20; p->code_size <<= 20; // Disable GC during init as a sanity check gc_off = true; // OS-specific initialization early_init(); p->executable_path = vm_executable_path(); if (p->image_path == NULL) { if (embedded_image_p()) { p->embedded_image = true; p->image_path = safe_strdup(p->executable_path); } else p->image_path = default_image_path(); } srand((unsigned int)nano_count()); init_ffi(); datastack_size = p->datastack_size; retainstack_size = p->retainstack_size; callstack_size = p->callstack_size; ctx = NULL; spare_ctx = new_context(); callbacks = new callback_heap(p->callback_size, this); load_image(p); max_pic_size = (int)p->max_pic_size; special_objects[OBJ_CELL_SIZE] = tag_fixnum(sizeof(cell)); special_objects[OBJ_ARGS] = false_object; special_objects[OBJ_EMBEDDED] = false_object; cell aliens[][2] = { {OBJ_STDIN, (cell)stdin}, {OBJ_STDOUT, (cell)stdout}, {OBJ_STDERR, (cell)stderr}, {OBJ_CPU, (cell)FACTOR_CPU_STRING}, {OBJ_EXECUTABLE, (cell)safe_strdup(p->executable_path)}, {OBJ_IMAGE, (cell)safe_strdup(p->image_path)}, {OBJ_OS, (cell)FACTOR_OS_STRING}, {OBJ_VM_COMPILE_TIME, (cell)FACTOR_COMPILE_TIME}, {OBJ_VM_COMPILER, (cell)FACTOR_COMPILER_VERSION}, {OBJ_VM_GIT_LABEL, (cell)FACTOR_STRINGIZE(FACTOR_GIT_LABEL)}, {OBJ_VM_VERSION, (cell)FACTOR_STRINGIZE(FACTOR_VERSION)}, #if defined(WINDOWS) {WIN_EXCEPTION_HANDLER, (cell)&factor::exception_handler} #endif }; int n_items = sizeof(aliens) / sizeof(cell[2]); for (int n = 0; n < n_items; n++) { cell idx = aliens[n][0]; special_objects[idx] = allot_alien(false_object, aliens[n][1]); } // We can GC now gc_off = false; if (!to_boolean(special_objects[OBJ_STAGE2])) prepare_boot_image(); if (p->signals) init_signals(); if (p->console) open_console(); }