Exemple #1
0
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();
}
Exemple #2
0
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();
}