void jl_gc_collect(void) { allocd_bytes = 0; if (is_gc_enabled) { JL_SIGATOMIC_BEGIN(); #ifdef GCTIME double t0 = clock_now(); #endif gc_mark(); #ifdef GCTIME ios_printf(ios_stderr, "mark time %.3f ms\n", (clock_now()-t0)*1000); #endif #if defined(MEMPROFILE) all_pool_stats(); big_obj_stats(); #endif #ifdef GCTIME t0 = clock_now(); #endif sweep_weak_refs(); gc_sweep(); #ifdef GCTIME ios_printf(ios_stderr, "sweep time %.3f ms\n", (clock_now()-t0)*1000); #endif run_finalizers(); JL_SIGATOMIC_END(); #ifdef OBJPROFILE print_obj_profile(); htable_reset(&obj_counts, 0); #endif } }
void jl_gc_collect(void) { size_t actual_allocd = allocd_bytes; total_allocd_bytes += allocd_bytes; allocd_bytes = 0; if (is_gc_enabled) { JL_SIGATOMIC_BEGIN(); jl_in_gc = 1; #if defined(GCTIME) || defined(GC_FINAL_STATS) double t0 = clock_now(); #endif gc_mark(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "mark time %.3f ms\n", (clock_now()-t0)*1000); #endif #if defined(MEMPROFILE) all_pool_stats(); big_obj_stats(); #endif #ifdef GCTIME t0 = clock_now(); #endif sweep_weak_refs(); gc_sweep(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "sweep time %.3f ms\n", (clock_now()-t0)*1000); #endif int nfinal = to_finalize.len; run_finalizers(); jl_in_gc = 0; JL_SIGATOMIC_END(); #if defined(GC_FINAL_STATS) total_gc_time += (clock_now()-t0); total_freed_bytes += freed_bytes; #endif #ifdef OBJPROFILE print_obj_profile(); htable_reset(&obj_counts, 0); #endif // tune collect interval based on current live ratio #if defined(MEMPROFILE) jl_printf(JL_STDERR, "allocd %ld, freed %ld, interval %ld, ratio %.2f\n", actual_allocd, freed_bytes, collect_interval, (double)freed_bytes/(double)actual_allocd); #endif if (freed_bytes < (7*(actual_allocd/10))) { if (collect_interval <= 2*(max_collect_interval/5)) collect_interval = 5*(collect_interval/2); } else { collect_interval = default_collect_interval; } freed_bytes = 0; // if a lot of objects were finalized, re-run GC to finish freeing // their storage if possible. if (nfinal > 100000) jl_gc_collect(); } }
// 'eq' means unordered comparison is sufficient static value_t compare_(value_t a, value_t b, int eq) { value_t guess = bounded_compare(a, b, BOUNDED_COMPARE_BOUND, eq); if (guess == NIL) { guess = cyc_compare(a, b, &equal_eq_hashtable, eq); htable_reset(&equal_eq_hashtable, 512); } return guess; }
DLLEXPORT void jl_save_system_image(char *fname, char *startscriptname) { jl_gc_collect(); jl_gc_collect(); int en = jl_gc_is_enabled(); jl_gc_disable(); htable_reset(&backref_table, 50000); ios_t f; ios_file(&f, fname, 1, 1, 1, 1); // orphan old Base module if present jl_base_module = (jl_module_t*)jl_get_global(jl_main_module, jl_symbol("Base")); // delete cached slow ASCIIString constructor if present jl_methtable_t *mt = jl_gf_mtable((jl_function_t*)jl_ascii_string_type); jl_array_t *spec = mt->defs->func->linfo->specializations; if (spec->length > 0 && ((jl_lambda_info_t*)jl_cellref(spec,0))->inferred == 0) { mt->cache = JL_NULL; mt->cache_arg1 = JL_NULL; mt->defs->func->linfo->tfunc = (jl_value_t*)jl_null; mt->defs->func->linfo->specializations = NULL; } jl_idtable_type = jl_get_global(jl_base_module, jl_symbol("ObjectIdDict")); jl_serialize_value(&f, jl_array_type->env); jl_serialize_value(&f, jl_main_module); write_int32(&f, jl_get_t_uid_ctr()); write_int32(&f, jl_get_gs_ctr()); htable_reset(&backref_table, 0); ios_t ss; ios_file(&ss, startscriptname, 1, 0, 0, 0); ios_copyall(&f, &ss); ios_close(&ss); ios_putc(0, &f); ios_close(&f); if (en) jl_gc_enable(); }
void jl_gc_collect(void) { allocd_bytes = 0; if (is_gc_enabled) { freed_bytes = 0; JL_SIGATOMIC_BEGIN(); #if defined(GCTIME) || defined(GC_FINAL_STATS) double t0 = clock_now(); #endif gc_mark(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "mark time %.3f ms\n", (clock_now()-t0)*1000); #endif #if defined(MEMPROFILE) all_pool_stats(); big_obj_stats(); #endif #ifdef GCTIME t0 = clock_now(); #endif sweep_weak_refs(); gc_sweep(); #ifdef GCTIME JL_PRINTF(JL_STDERR, "sweep time %.3f ms\n", (clock_now()-t0)*1000); #endif run_finalizers(); JL_SIGATOMIC_END(); #if defined(GC_FINAL_STATS) total_gc_time += (clock_now()-t0); total_freed_bytes += freed_bytes; #endif #ifdef OBJPROFILE print_obj_profile(); htable_reset(&obj_counts, 0); #endif // tune collect interval based on current live ratio if (freed_bytes < ((2*collect_interval)/5)) { if (collect_interval <= (2*max_collect_interval)/5) collect_interval = (5*collect_interval)/2; } else { collect_interval = default_collect_interval; } } }
DLLEXPORT void jl_restore_system_image(char *fname) { ios_t f; char *fpath = jl_find_file_in_path(fname); if (ios_file(&f, fpath, 1, 0, 0, 0) == NULL) { ios_printf(ios_stderr, "system image file not found\n"); exit(1); } #ifdef JL_GC_MARKSWEEP int en = jl_gc_is_enabled(); jl_gc_disable(); #endif tagtype_list = jl_alloc_cell_1d(0); jl_array_type->env = jl_deserialize_value(&f); jl_base_module = (jl_module_t*)jl_deserialize_value(&f); jl_current_module = (jl_module_t*)jl_deserialize_value(&f); jl_system_module = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("System")); jl_array_t *idtl = (jl_array_t*)jl_deserialize_value(&f); // rehash IdTables for(int i=0; i < idtl->length; i++) { jl_value_t *v = jl_cellref(idtl, i); jl_idtable_rehash(&((jl_array_t**)v)[1], ((jl_array_t**)v)[1]->length); } // cache builtin parametric types for(int i=0; i < tagtype_list->length; i++) { jl_value_t *v = jl_cellref(tagtype_list, i); uint32_t uid=0; if (jl_is_struct_type(v)) uid = ((jl_struct_type_t*)v)->uid; else if (jl_is_bits_type(v)) uid = ((jl_bits_type_t*)v)->uid; jl_cache_type_((jl_tag_type_t*)v); if (jl_is_struct_type(v)) ((jl_struct_type_t*)v)->uid = uid; else if (jl_is_bits_type(v)) ((jl_bits_type_t*)v)->uid = uid; } jl_get_builtin_hooks(); jl_get_system_hooks(); jl_boot_file_loaded = 1; jl_typeinf_func = (jl_function_t*)jl_get_global(jl_system_module, jl_symbol("typeinf_ext")); jl_init_box_caches(); //jl_deserialize_finalizers(&f); jl_set_t_uid_ctr(read_int32(&f)); jl_set_gs_ctr(read_int32(&f)); htable_reset(&backref_table, 0); ios_t ss; ios_mem(&ss, 0); ios_copyuntil(&ss, &f, '\0'); ios_close(&f); if (fpath != fname) free(fpath); #ifdef JL_GC_MARKSWEEP if (en) jl_gc_enable(); #endif // TODO: there is no exception handler here! jl_load_file_string(ss.buf); ios_close(&ss); }
DLLEXPORT void jl_save_system_image(char *fname, char *startscriptname) { jl_gc_collect(); jl_gc_collect(); int en = jl_gc_is_enabled(); jl_gc_disable(); htable_reset(&backref_table, 50000); ios_t f; ios_file(&f, fname, 1, 1, 1, 1); if (jl_current_module != jl_system_module) { // set up for stage 1 bootstrap, where the System module is already // loaded and we are loading an updated copy in a separate module. // step 1: set Base.System = current_module jl_binding_t *b = jl_get_binding_wr(jl_base_module, jl_symbol("System")); b->value = (jl_value_t*)jl_current_module; assert(b->constp); // step 2: set current_module.Base = Base jl_set_const(jl_current_module, jl_symbol("Base"), (jl_value_t*)jl_base_module); // step 3: current_module.System = current_module b = jl_get_binding_wr(jl_current_module, jl_symbol("System")); b->value = (jl_value_t*)jl_current_module; assert(b->constp); // step 4: remove current_module.current_module b = jl_get_binding_wr(jl_current_module, jl_current_module->name); b->value = NULL; b->constp = 0; // step 5: rename current_module to System jl_current_module->name = jl_symbol("System"); // step 6: orphan old system module jl_system_module = jl_current_module; } else { // delete cached slow ASCIIString constructor jl_methtable_t *mt = jl_gf_mtable((jl_function_t*)jl_ascii_string_type); mt->cache = NULL; mt->cache_1arg = NULL; mt->defs->func->linfo->tfunc = (jl_value_t*)jl_null; mt->defs->func->linfo->specializations = NULL; } jl_idtable_type = jl_get_global(jl_system_module, jl_symbol("IdTable")); idtable_list = jl_alloc_cell_1d(0); jl_serialize_value(&f, jl_array_type->env); jl_serialize_value(&f, jl_base_module); jl_serialize_value(&f, jl_current_module); jl_serialize_value(&f, idtable_list); //jl_serialize_finalizers(&f); write_int32(&f, jl_get_t_uid_ctr()); write_int32(&f, jl_get_gs_ctr()); htable_reset(&backref_table, 0); ios_t ss; ios_file(&ss, startscriptname, 1, 0, 0, 0); ios_copyall(&f, &ss); ios_close(&ss); ios_putc(0, &f); ios_close(&f); if (en) jl_gc_enable(); }