Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also serialize dt->instance. Fixes #5129 #5149

Merged
merged 1 commit into from
Dec 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void write_as_tag(ios_t *s, uint8_t tag)
#define jl_serialize_value(s, v) jl_serialize_value_(s,(jl_value_t*)(v))
static void jl_serialize_value_(ios_t *s, jl_value_t *v);
static jl_value_t *jl_deserialize_value(ios_t *s);
static jl_value_t *jl_deserialize_value_internal(ios_t *s);
static jl_value_t ***sysimg_gvars = NULL;

static void jl_load_sysimg_so(char *fname)
Expand Down Expand Up @@ -260,7 +261,8 @@ static void jl_serialize_datatype(ios_t *s, jl_datatype_t *dt)
jl_serialize_value(s, dt->names);
jl_serialize_value(s, dt->types);
}
write_uint8(s, dt->abstract | (dt->mutabl<<1) | (dt->pointerfree<<2));
int has_instance = !!(dt->instance != NULL);
write_uint8(s, dt->abstract | (dt->mutabl<<1) | (dt->pointerfree<<2) | (has_instance<<3));
if (!dt->abstract)
write_int32(s, dt->uid);

Expand All @@ -270,6 +272,8 @@ static void jl_serialize_datatype(ios_t *s, jl_datatype_t *dt)
jl_serialize_value(s, dt->ctor_factory);
jl_serialize_value(s, dt->env);
jl_serialize_value(s, dt->linfo);
if (has_instance)
jl_serialize_value(s, dt->instance);
jl_serialize_fptr(s, dt->fptr);
}

Expand Down Expand Up @@ -563,6 +567,8 @@ static jl_fptr_t jl_deserialize_fptr(ios_t *s)
return *(jl_fptr_t*)pbp;
}

#define DTINSTANCE_PLACEHOLDER ((void*)2)

static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos)
{
int tag = read_uint8(s);
Expand Down Expand Up @@ -600,6 +606,7 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos)
dt->abstract = flags&1;
dt->mutabl = (flags>>1)&1;
dt->pointerfree = (flags>>2)&1;
int has_instance = (flags>>3)&1;
if (!dt->abstract)
dt->uid = read_int32(s);
else
Expand All @@ -610,6 +617,12 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos)
dt->ctor_factory = jl_deserialize_value(s);
dt->env = jl_deserialize_value(s);
dt->linfo = (jl_lambda_info_t*)jl_deserialize_value(s);
if (has_instance) {
jl_value_t *instance = (jl_value_t*)jl_deserialize_value_internal(s);
if (instance == DTINSTANCE_PLACEHOLDER)
instance = jl_new_struct_uninit(dt);
dt->instance = instance;
}
dt->fptr = jl_deserialize_fptr(s);
if (dt->name == jl_array_type->name || dt->name == jl_pointer_type->name ||
dt->name == jl_type_type->name || dt->name == jl_vararg_type->name ||
Expand All @@ -625,7 +638,8 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos)

jl_array_t *jl_eqtable_put(jl_array_t *h, void *key, void *val);

static jl_value_t *jl_deserialize_value(ios_t *s)
// Internal jl_deserialize_value. May return the placeholder value DTINSTANCE_PLACEHOLDER, unlike jl_deserialize_value
static jl_value_t *jl_deserialize_value_internal(ios_t *s)
{
int pos = ios_pos(s);
int32_t tag = read_uint8(s);
Expand Down Expand Up @@ -828,6 +842,14 @@ static jl_value_t *jl_deserialize_value(ios_t *s)
return v;
}
else if (vtag == (jl_value_t*)jl_datatype_type || vtag == (jl_value_t*)IdTable_tag) {
// If the value v we are about to deserialize is some dt->instance, we have a circular
// reference, because v == v->type->instance. To avoid this, we put a null value in
// the backref table to reserve the space. If jl_deserialize_value encounters this,
// it knows to do the allocation itself. This work, because in all instances where
// v->type->instance != null, v->type has no fields, so there is no further serialized
// data stored that we would need to construct the type.
if (usetable)
ptrhash_put(&backref_table, (void*)(ptrint_t)pos, DTINSTANCE_PLACEHOLDER);
jl_datatype_t *dt = (jl_datatype_t*)jl_deserialize_value(s);
if (dt == jl_datatype_type)
return jl_deserialize_datatype(s, pos);
Expand Down Expand Up @@ -860,6 +882,11 @@ static jl_value_t *jl_deserialize_value(ios_t *s)
ptrhash_put(&backref_table, (void*)(ptrint_t)pos, v);
}
else {
if (dt->instance) {
if (usetable)
*ptrhash_bp(&backref_table, (void*)(ptrint_t)pos) = dt->instance;
return dt->instance;
}
v = jl_new_struct_uninit(dt);
if (usetable)
ptrhash_put(&backref_table, (void*)(ptrint_t)pos, v);
Expand Down Expand Up @@ -887,6 +914,13 @@ static jl_value_t *jl_deserialize_value(ios_t *s)
return NULL;
}

static jl_value_t* jl_deserialize_value(ios_t *s)
{
jl_value_t *v = jl_deserialize_value_internal(s);
assert(v != DTINSTANCE_PLACEHOLDER);
return v;
}

// --- entry points ---

DLLEXPORT
Expand Down
2 changes: 1 addition & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ static size_t mark_sp = 0;

static void push_root(jl_value_t *v, int d);

#define gc_push_root(v,d) if (!gc_marked(v)) push_root((jl_value_t*)(v),d);
#define gc_push_root(v,d) do { assert(v != NULL); if (!gc_marked(v)) { push_root((jl_value_t*)(v),d); } } while (0)

void jl_gc_setmark(jl_value_t *v)
{
Expand Down
1 change: 1 addition & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void restore_signals()
}
void jl_throw_in_ctx(jl_value_t* excpt, CONTEXT *ctxThread, int bt)
{
assert(excpt != NULL);
bt_size = bt ? rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ctxThread) : 0;
jl_exception_in_transit = excpt;
#if defined(_CPU_X86_64_)
Expand Down
2 changes: 2 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ DLLEXPORT void gdbbacktrace()
// yield to exception handler
void NORETURN throw_internal(jl_value_t *e)
{
assert(e != NULL);
jl_exception_in_transit = e;
if (jl_current_task->eh != NULL) {
jl_longjmp(jl_current_task->eh->eh_ctx, 1);
Expand Down Expand Up @@ -751,6 +752,7 @@ void NORETURN throw_internal(jl_value_t *e)
// record backtrace and raise an error
DLLEXPORT void jl_throw(jl_value_t *e)
{
assert(e != NULL);
record_backtrace();
throw_internal(e);
}
Expand Down