Skip to content

Commit

Permalink
Adding macros to push pinning roots - port PR #43 (#71)
Browse files Browse the repository at this point in the history
Port #43 to dev. Add _NO_TPIN macros for pushing GC frames.
  • Loading branch information
qinsoon authored Nov 7, 2024
1 parent b484fe7 commit 7a953be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ extern void JL_GC_ENABLEFRAME(interpreter_state*) JL_NOTSAFEPOINT;

#else

#ifdef MMTK_GC
#define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<3)|2)
// For roots that are not transitively pinned
#define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) ((((size_t)(n))<<3)|6)
#else
#define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<2)|2)
#define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) JL_GC_ENCODE_PUSHFRAME(n)
#endif

#define JL_GC_PUSHFRAME(frame,locals,n) \
JL_CPPALLOCA(frame, sizeof(*frame)+(((n)+3)*sizeof(jl_value_t*))); \
Expand Down
33 changes: 33 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,41 @@ struct _jl_gcframe_t {

#define jl_pgcstack (jl_current_task->gcstack)

#ifndef MMTK_GC
#define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<2)
#define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<2)|1)
#define JL_GC_DECODE_NROOTS(n) (n >> 2)

#define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) JL_GC_ENCODE_PUSHARGS(n)
#define JL_GC_ENCODE_PUSH_NO_TPIN(n) JL_GC_ENCODE_PUSH(n)
#else

// We use an extra bit (100) in the nroots value from the frame to indicate that the roots
// in the frame are/are not transitively pinning.
// There are currently 3 macros that encode passing nroots to the gcframe
// and they use the two lowest bits to encode information about what is in the frame (as below).
// To support the distinction between transtively pinning roots and non transitively pinning roots
// on the stack, we take another bit from nroots to encode information about whether or not to
// transitively pin the roots in the frame.
//
// So the ones that transitively pin look like:
// #define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<3)
// #define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<3)|1)
// #define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<3)|2)
// and the ones that do not look like:
// #define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) (((size_t)(n))<<3|4)
// #define JL_GC_ENCODE_PUSH_NO_TPIN(n) ((((size_t)(n))<<3)|5)
// #define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) ((((size_t)(n))<<3)|6)

// these are transitively pinning
#define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<3)
#define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<3)|1)
#define JL_GC_DECODE_NROOTS(n) (n >> 3)

// these only pin the root object itself
#define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) (((size_t)(n))<<3|4)
#define JL_GC_ENCODE_PUSH_NO_TPIN(n) ((((size_t)(n))<<3)|5)
#endif

#ifdef __clang_gcanalyzer__

Expand Down
6 changes: 3 additions & 3 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void re_save_env(jl_stenv_t *e, jl_savedenv_t *se, int root)
}
else {
roots = se->roots;
nroots = se->gcframe.nroots >> 2;
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
}
}
jl_varbinding_t *v = e->vars;
Expand Down Expand Up @@ -367,7 +367,7 @@ static void restore_env(jl_stenv_t *e, jl_savedenv_t *se, int root) JL_NOTSAFEPO
}
else {
roots = se->roots;
nroots = se->gcframe.nroots >> 2;
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
}
}
jl_varbinding_t *v = e->vars;
Expand Down Expand Up @@ -4146,7 +4146,7 @@ static int merge_env(jl_stenv_t *e, jl_savedenv_t *me, jl_savedenv_t *se, int co
else {
saved = se->roots;
merged = me->roots;
nroots = se->gcframe.nroots >> 2;
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
}
assert(nroots == current_env_length(e) * 3);
assert(nroots % 3 == 0);
Expand Down

0 comments on commit 7a953be

Please sign in to comment.