From 06d01c2c773d6c4a2c44cdd809d541585ae489de Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sat, 22 Nov 2014 15:55:11 -0500 Subject: [PATCH] fix #8551 and make stack switch more efficient previously, each new stack would have a copy of a small portion of the stack that started it. in small amounts, this was fine, but it is bad if the user is starting many tasks. additionally, it wasted memory inside every task to have a per-task base_ctx. (cherry picked from commit ac1371136e1aae1ca7366b4d19cc0ffa0d659d72) --- src/julia.h | 4 ++-- src/task.c | 15 ++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/julia.h b/src/julia.h index 8d6368efdeb52..00f2146ed2e09 100644 --- a/src/julia.h +++ b/src/julia.h @@ -992,11 +992,12 @@ DLLEXPORT void jl_handle_stack_switch(); #ifdef COPY_STACKS // initialize base context of root task +extern jl_jmp_buf jl_base_ctx; #define JL_SET_STACK_BASE \ { \ int __stk; \ jl_root_task->stackbase = (char*)&__stk; \ - if (jl_setjmp(jl_root_task->base_ctx, 1)) { \ + if (jl_setjmp(jl_base_ctx, 1)) { \ jl_handle_stack_switch(); \ } \ } @@ -1145,7 +1146,6 @@ typedef struct _jl_task_t { void *stackbase; void *stack; }; - jl_jmp_buf base_ctx; size_t bufsz; void *stkbuf; size_t ssize; diff --git a/src/task.c b/src/task.c index 3fa0e52fdc878..6804376c75e25 100644 --- a/src/task.c +++ b/src/task.c @@ -30,6 +30,8 @@ volatile int jl_in_stackwalk = 0; #include // for dladdr #endif +jl_jmp_buf jl_base_ctx; + /* This probing code is derived from Douglas Jones' user thread library */ /* true if stack grows up, false if down */ @@ -211,11 +213,6 @@ static void switch_stack(jl_task_t *t, jl_jmp_buf *where) restore_stack(t, where, NULL); } } - -void jl_switch_stack(jl_task_t *t, jl_jmp_buf *where) -{ - switch_stack(t, where); -} #endif static void ctx_switch(jl_task_t *t, jl_jmp_buf *where) @@ -262,7 +259,7 @@ static void ctx_switch(jl_task_t *t, jl_jmp_buf *where) #ifdef COPY_STACKS jl_jmp_target = where; - jl_longjmp(lastt->base_ctx, 1); + jl_longjmp(jl_base_ctx, 1); #else jl_longjmp(*where, 1); #endif @@ -418,10 +415,6 @@ static void start_task(jl_task_t *t) local_sp += sizeof(jl_gcframe_t); local_sp += 12*sizeof(void*); t->stackbase = (void*)(local_sp + _frame_offset); - if (jl_setjmp(t->base_ctx, 0)) { - // we get here to remove our data from the process stack - switch_stack(jl_current_task, jl_jmp_target); - } #endif res = jl_apply(t->start, NULL, 0); JL_GC_POP(); @@ -431,7 +424,7 @@ static void start_task(jl_task_t *t) DLLEXPORT void jl_handle_stack_switch() { - jl_switch_stack(jl_current_task, jl_jmp_target); + switch_stack(jl_current_task, jl_jmp_target); } #ifndef COPY_STACKS