Skip to content

Commit

Permalink
Pin pointer literals in code, and julia values in julia_to_scm (#63)
Browse files Browse the repository at this point in the history
Julia may embed heap pointers in the code. Those objects cannot be moved, otherwise the pointer value in the code becomes invalid. This PR pins those pointers in `literal_pointer_val` and `literal_static_pointer_val`.

Julia also reference heap pointers from scm/flisp values. We pin those heap pointers in `julia_to_scm_`.
  • Loading branch information
qinsoon authored Aug 16, 2024
1 parent 7bc3b32 commit f5f8510
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ static value_t julia_to_list2_noalloc(fl_context_t *fl_ctx, jl_value_t *a, jl_va

static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_valid)
{
PTR_PIN(v);
value_t retval;
if (julia_to_scm_noalloc1(fl_ctx, v, &retval))
return retval;
Expand Down
4 changes: 4 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_value_t *p)
if (p == NULL)
return Constant::getNullValue(ctx.types().T_pjlvalue);
if (!ctx.emission_context.imaging)
// literal_static_pointer_val will pin p.
return literal_static_pointer_val(p, ctx.types().T_pjlvalue);
PTR_PIN(p);
Value *pgv = literal_pointer_val_slot(ctx, p);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
return ai.decorateInst(maybe_mark_load_dereferenceable(
Expand All @@ -487,7 +489,9 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_binding_t *p)
if (p == NULL)
return Constant::getNullValue(ctx.types().T_pjlvalue);
if (!ctx.emission_context.imaging)
// literal_static_pointer_val will pin p.
return literal_static_pointer_val(p, ctx.types().T_pjlvalue);
PTR_PIN(p);
// bindings are prefixed with jl_bnd#
Value *pgv = julia_pgv(ctx, "jl_bnd#", p->name, p->owner, p);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
Expand Down
1 change: 1 addition & 0 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void add_named_global(StringRef name, void *addr);

static inline Constant *literal_static_pointer_val(const void *p, Type *T)
{
PTR_PIN((void*)p);
// this function will emit a static pointer into the generated code
// the generated code will only be valid during the current session,
// and thus, this should typically be avoided in new API's
Expand Down

0 comments on commit f5f8510

Please sign in to comment.