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

Adding macros to push pinning roots #43

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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_RELAXED(n) ((((size_t)(n))<<3)|6)
#else
#define JL_GC_ENCODE_PUSHFRAME(n) ((((size_t)(n))<<2)|2)
#define JL_GC_ENCODE_PUSHFRAME_RELAXED(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
77 changes: 76 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,22 @@ 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_ENCODE_PUSHARGS_RELAXED(n) JL_GC_ENCODE_PUSHARGS(n)
#define JL_GC_ENCODE_PUSH_RELAXED(n) JL_GC_ENCODE_PUSH_RELAXED(n)
#else
// 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)

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

#ifdef __clang_gcanalyzer__

// When running with the analyzer make these real function calls, that are
Expand Down Expand Up @@ -905,11 +918,11 @@ extern void JL_GC_POP() JL_NOTSAFEPOINT;
#define JL_GC_PUSH7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(7), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(8), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;


#define JL_GC_PUSHARGS(rts_var,n) \
rts_var = ((jl_value_t**)alloca(((n)+2)*sizeof(jl_value_t*)))+2; \
((void**)rts_var)[-2] = (void*)JL_GC_ENCODE_PUSHARGS(n); \
Expand All @@ -921,6 +934,68 @@ extern void JL_GC_POP() JL_NOTSAFEPOINT;

#endif

#ifdef MMTK_GC
// these are pinning roots: only the root object needs to be pinned as opposed to
// the functions above which are transitively pinning
#define JL_GC_PUSH1_RELAXED(arg1) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(1), jl_pgcstack, arg1}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH2_RELAXED(arg1, arg2) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(2), jl_pgcstack, arg1, arg2}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH3_RELAXED(arg1, arg2, arg3) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(3), jl_pgcstack, arg1, arg2, arg3}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH4_RELAXED(arg1, arg2, arg3, arg4) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(4), jl_pgcstack, arg1, arg2, arg3, arg4}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH5_RELAXED(arg1, arg2, arg3, arg4, arg5) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(5), jl_pgcstack, arg1, arg2, arg3, arg4, arg5}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH6_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(6), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH7_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(7), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSH8_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH_RELAXED(8), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;

#define JL_GC_PUSHARGS_RELAXED(rts_var,n) \
rts_var = ((jl_value_t**)alloca(((n)+2)*sizeof(jl_value_t*)))+2; \
((void**)rts_var)[-2] = (void*)JL_GC_ENCODE_PUSHARGS_RELAXED(n); \
((void**)rts_var)[-1] = jl_pgcstack; \
memset((void*)rts_var, 0, (n)*sizeof(jl_value_t*)); \
jl_pgcstack = (jl_gcframe_t*)&(((void**)rts_var)[-2])
#else
// When not using MMTk, default to the stock functions
#define JL_GC_PUSH1_RELAXED(arg1) JL_GC_PUSH1(arg1)

#define JL_GC_PUSH2_RELAXED(arg1, arg2) JL_GC_PUSH2(arg1, arg2)

#define JL_GC_PUSH3_RELAXED(arg1, arg2, arg3) JL_GC_PUSH3(arg1, arg2, arg3)

#define JL_GC_PUSH4_RELAXED(arg1, arg2, arg3, arg4) JL_GC_PUSH4(arg1, arg2, arg3, arg4)

#define JL_GC_PUSH5_RELAXED(arg1, arg2, arg3, arg4, arg5) JL_GC_PUSH5(arg1, arg2, arg3, arg4, arg5)

#define JL_GC_PUSH6_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6) JL_GC_PUSH6(arg1, arg2, arg3, arg4, arg5, arg6)

#define JL_GC_PUSH7_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6, arg7) JL_GC_PUSH7(arg1, arg2, arg3, arg4, arg5, arg6, arg7)

#define JL_GC_PUSH8_RELAXED(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) JL_GC_PUSH8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)

#define JL_GC_PUSHARGS_RELAXED(rts_var,n) JL_GC_PUSHARGS(rts_var,n)
#endif

JL_DLLEXPORT int jl_gc_enable(int on);
JL_DLLEXPORT int jl_gc_is_enabled(void);

Expand Down
Loading