Skip to content

Commit

Permalink
allow tasks to request dedicated stack space when created
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 25, 2015
1 parent ac31862 commit 1a8676b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 107 deletions.
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ eval(:(Core.call(::Type{GlobalRef}, m::Module, s::Symbol) = $(Expr(:new, :Global

Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Any, (Any, Bool), name, std_imports)::Module

Task(f::ANY) = ccall(:jl_new_task, Any, (Any, Int), f::Function, 0)::Task
Task(f::ANY, reserved_stack::Int=0) = ccall(:jl_new_task, Any, (Any, Int), f::Function, reserved_stack)::Task

# simple convert for use by constructors of types in Core
# note that there is no actual conversion defined here,
Expand Down
12 changes: 5 additions & 7 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1562,17 +1562,15 @@ static void gc_mark_task_stack(jl_task_t *ta, int d)
if (ta == jl_current_task) {
gc_mark_stack((jl_value_t*)ta, jl_pgcstack, 0, d);
}
else if (ta == jl_root_task) {
else if (!ta->copy_stack) {
gc_mark_stack((jl_value_t*)ta, ta->gcstack, 0, d);
}
else if (ta->stkbuf != NULL && ta->stkbuf != (void*)(intptr_t)-1) {
#ifdef COPY_STACKS
else if (ta->stkbuf != NULL && ta->stkbuf != (void*)(intptr_t)-1) {
ptrint_t offset = (char *)ta->stkbuf + ta->ssize - (char *)jl_stackbase;
#else
ptrint_t offset = 0;
#endif
gc_mark_stack((jl_value_t*)ta, ta->gcstack, offset, d);
}
#endif
}

NOINLINE static void gc_mark_task(jl_task_t *ta, int d)
Expand Down Expand Up @@ -1808,7 +1806,7 @@ double clock_now(void);

extern jl_module_t *jl_old_base_module;
extern jl_array_t *jl_module_init_order;
extern jl_value_t *jl_unprotect_stack_func;
extern jl_value_t *jl_task_cleanup_func;

static int inc_count = 0;
static int quick_count = 0;
Expand Down Expand Up @@ -1846,7 +1844,7 @@ static void pre_mark(void)
}

jl_mark_box_caches();
gc_push_root(jl_unprotect_stack_func, 0);
gc_push_root(jl_task_cleanup_func, 0);
gc_push_root(jl_bottom_func, 0);
gc_push_root(jl_typetype_type, 0);

Expand Down
3 changes: 2 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,8 @@ typedef struct _jl_task_t {
#endif
jl_jmp_buf ctx; // saved thread state
void *stkbuf; // malloc'd memory
int ssize; // sizeof the portion of stack used in stkbuf
int ssize:31; // sizeof stkbuf
int copy_stack:1;

// current exception handler
jl_handler_t *eh;
Expand Down
13 changes: 4 additions & 9 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ void fpe_handler(int arg)

static int is_addr_on_stack(void *addr)
{
#ifdef COPY_STACKS
if (jl_current_task == jl_root_task)
return ((char*)addr > (char*)jl_stack_lo-3000000 &&
(char*)addr < (char*)jl_stack_hi);
else
if (jl_current_task->copy_stack)
return ((char*)addr > (char*)jl_stackbase - JL_STACK_SIZE &&
(char*)addr < (char*)jl_stackbase);
#else
return ((char*)addr > (char*)jl_current_task->stkbuf &&
(char*)addr < (char*)jl_current_task->stkbuf + jl_current_task->ssize);
#endif
else
return ((char*)addr > (char*)jl_current_task->stkbuf &&
(char*)addr < (char*)jl_current_task->stkbuf + jl_current_task->ssize);
}

#ifndef SIGINFO
Expand Down
Loading

0 comments on commit 1a8676b

Please sign in to comment.