Skip to content

Commit 7a953be

Browse files
authored
Adding macros to push pinning roots - port PR #43 (#71)
Port #43 to dev. Add _NO_TPIN macros for pushing GC frames.
1 parent b484fe7 commit 7a953be

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/interpreter.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ extern void JL_GC_ENABLEFRAME(interpreter_state*) JL_NOTSAFEPOINT;
5252

5353
#else
5454

55+
#ifdef MMTK_GC
56+
#define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<3)|2)
57+
// For roots that are not transitively pinned
58+
#define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) ((((size_t)(n))<<3)|6)
59+
#else
5560
#define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<2)|2)
61+
#define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) JL_GC_ENCODE_PUSHFRAME(n)
62+
#endif
5663

5764
#define JL_GC_PUSHFRAME(frame,locals,n) \
5865
JL_CPPALLOCA(frame, sizeof(*frame)+(((n)+3)*sizeof(jl_value_t*))); \

src/julia.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,41 @@ struct _jl_gcframe_t {
10531053

10541054
#define jl_pgcstack (jl_current_task->gcstack)
10551055

1056+
#ifndef MMTK_GC
10561057
#define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<2)
10571058
#define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<2)|1)
1059+
#define JL_GC_DECODE_NROOTS(n) (n >> 2)
1060+
1061+
#define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) JL_GC_ENCODE_PUSHARGS(n)
1062+
#define JL_GC_ENCODE_PUSH_NO_TPIN(n) JL_GC_ENCODE_PUSH(n)
1063+
#else
1064+
1065+
// We use an extra bit (100) in the nroots value from the frame to indicate that the roots
1066+
// in the frame are/are not transitively pinning.
1067+
// There are currently 3 macros that encode passing nroots to the gcframe
1068+
// and they use the two lowest bits to encode information about what is in the frame (as below).
1069+
// To support the distinction between transtively pinning roots and non transitively pinning roots
1070+
// on the stack, we take another bit from nroots to encode information about whether or not to
1071+
// transitively pin the roots in the frame.
1072+
//
1073+
// So the ones that transitively pin look like:
1074+
// #define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<3)
1075+
// #define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<3)|1)
1076+
// #define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<3)|2)
1077+
// and the ones that do not look like:
1078+
// #define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) (((size_t)(n))<<3|4)
1079+
// #define JL_GC_ENCODE_PUSH_NO_TPIN(n) ((((size_t)(n))<<3)|5)
1080+
// #define JL_GC_ENCODE_PUSHFRAME_NO_TPIN(n) ((((size_t)(n))<<3)|6)
1081+
1082+
// these are transitively pinning
1083+
#define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<3)
1084+
#define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<3)|1)
1085+
#define JL_GC_DECODE_NROOTS(n) (n >> 3)
1086+
1087+
// these only pin the root object itself
1088+
#define JL_GC_ENCODE_PUSHARGS_NO_TPIN(n) (((size_t)(n))<<3|4)
1089+
#define JL_GC_ENCODE_PUSH_NO_TPIN(n) ((((size_t)(n))<<3)|5)
1090+
#endif
10581091

10591092
#ifdef __clang_gcanalyzer__
10601093

src/subtype.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void re_save_env(jl_stenv_t *e, jl_savedenv_t *se, int root)
274274
}
275275
else {
276276
roots = se->roots;
277-
nroots = se->gcframe.nroots >> 2;
277+
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
278278
}
279279
}
280280
jl_varbinding_t *v = e->vars;
@@ -367,7 +367,7 @@ static void restore_env(jl_stenv_t *e, jl_savedenv_t *se, int root) JL_NOTSAFEPO
367367
}
368368
else {
369369
roots = se->roots;
370-
nroots = se->gcframe.nroots >> 2;
370+
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
371371
}
372372
}
373373
jl_varbinding_t *v = e->vars;
@@ -4146,7 +4146,7 @@ static int merge_env(jl_stenv_t *e, jl_savedenv_t *me, jl_savedenv_t *se, int co
41464146
else {
41474147
saved = se->roots;
41484148
merged = me->roots;
4149-
nroots = se->gcframe.nroots >> 2;
4149+
nroots = JL_GC_DECODE_NROOTS(se->gcframe.nroots);
41504150
}
41514151
assert(nroots == current_env_length(e) * 3);
41524152
assert(nroots % 3 == 0);

0 commit comments

Comments
 (0)