Skip to content

Commit

Permalink
codegen/gc-root/serialization of smalled boxed-cached ints
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Aug 16, 2015
1 parent eec5511 commit c86b379
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
38 changes: 22 additions & 16 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3111,16 +3111,6 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed, bool
jl_error("Linenode in value position");
return NULL;
}
if (jl_is_quotenode(expr)) {
jl_value_t *jv = jl_fieldref(expr,0);
if (jl_is_bitstype(jl_typeof(jv))) {
return emit_expr(jv, ctx, isboxed, valuepos);
}
if (!jl_is_symbol(jv)) {
jl_add_linfo_root(ctx->linfo, jv);
}
return literal_pointer_val(jv);
}
if (jl_is_gotonode(expr)) {
if (builder.GetInsertBlock()->getTerminator() == NULL) {
int labelname = jl_gotonode_label(expr);
Expand Down Expand Up @@ -3166,17 +3156,33 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed, bool
}
return NULL;
}
if (jl_is_lambda_info(expr)) {
return emit_lambda_closure(expr, ctx);
}
if (!jl_is_expr(expr)) {
int needroot = true;
if (jl_is_quotenode(expr)) {
expr = jl_fieldref(expr,0);
if (jl_is_symbol(expr)) {
needroot = false;
}
}
// numeric literals
int needroot = 1;
if (jl_is_int32(expr)) {
needroot = !((uint32_t)(jl_unbox_int32(expr)+512) < 1024);
int32_t val = jl_unbox_int32(expr);
if ((uint32_t)(val+512) < 1024) {
// this can be gotten from the box cache
needroot = false;
expr = jl_box_int32(val);
}
}
else if (jl_is_int64(expr)) {
needroot = !((uint64_t)(jl_unbox_int64(expr)+512) < 1024);
}
else if (jl_is_lambda_info(expr)) {
return emit_lambda_closure(expr, ctx);
uint64_t val = jl_unbox_uint64(expr);
if ((uint64_t)(val+512) < 1024) {
// this can be gotten from the box cache
needroot = false;
expr = jl_box_int64(val);
}
}
if (needroot) {
jl_add_linfo_root(ctx->linfo, expr);
Expand Down
43 changes: 37 additions & 6 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ static void jl_deserialize_globalvals(ios_t *s)

static void jl_serialize_gv_syms(ios_t *s, jl_sym_t *v)
{
// ensures all symbols referenced in the code have
// references in the system image to their global variable
// since symbols are static, they might not have had a
// reference anywhere in the code image other than here
void *bp = ptrhash_get(&backref_table, v);
Expand All @@ -335,7 +333,41 @@ static void jl_serialize_gv_syms(ios_t *s, jl_sym_t *v)
if (v->right) jl_serialize_gv_syms(s, v->right);
}

static void jl_deserialize_gv_syms(ios_t *s)
static void jl_serialize_gv_others(ios_t *s)
{
// ensures all objects referenced in the code have
// references in the system image to their global variable
// since codegen knows that some integer boxes are static,
// they might not have had a reference anywhere in the code
// image other than here
int32_t i;
for (i = -512; i < 512; i++) {
jl_value_t *v32 = jl_box_int32(i);
void *bp32 = ptrhash_get(&backref_table, v32);
if (bp32 == HT_NOTFOUND) {
int32_t gv32 = jl_get_llvm_gv(v32);
if (gv32 != 0) {
jl_serialize_value(s, v32);
write_int32(s, gv32);
}
}
}
for (i = -512; i < 512; i++) {
jl_value_t *v64 = jl_box_int64(i);
void *bp64 = ptrhash_get(&backref_table, v64);
if (bp64 == HT_NOTFOUND) {
int32_t gv64 = jl_get_llvm_gv(v64);
if (gv64 != 0) {
jl_serialize_value(s, v64);
write_int32(s, gv64);
}
}
}
jl_serialize_gv_syms(s, jl_get_root_symbol());
jl_serialize_value(s, NULL); // signal the end of this list
}

static void jl_deserialize_gv_others(ios_t *s)
{
while (1) {
jl_value_t *v = jl_deserialize_value(s, NULL);
Expand Down Expand Up @@ -1737,8 +1769,7 @@ void jl_save_system_image_to_stream(ios_t *f)
jl_serialize_gv(f, deser_tag[i]);
}
jl_serialize_globalvals(f);
jl_serialize_gv_syms(f, jl_get_root_symbol()); // serialize symbols with GlobalValue references
jl_serialize_value(f, NULL); // signal the end of the symbols list
jl_serialize_gv_others(f); // serialize things that might not have visible gc roots roots with GlobalValue references

write_int32(f, jl_get_t_uid_ctr());
write_int32(f, jl_get_gs_ctr());
Expand Down Expand Up @@ -1828,7 +1859,7 @@ void jl_restore_system_image_from_stream(ios_t *f)
jl_deserialize_gv(f, deser_tag[i]);
}
jl_deserialize_globalvals(f);
jl_deserialize_gv_syms(f);
jl_deserialize_gv_others(f);

int uid_ctr = read_int32(f);
int gs_ctr = read_int32(f);
Expand Down

0 comments on commit c86b379

Please sign in to comment.