Skip to content

Commit

Permalink
Automated renaming exc_stack -> excstack
Browse files Browse the repository at this point in the history
cd src
ag -l exc_stack  | xargs sed -i -e 's/exc_stack/excstack/g'
ag -l excstk_raw | xargs sed -i -e 's/excstk_raw/excstack_raw/g'
sed -i -e 's/jlcurrent_exception_func/jl_current_exception_func/g' codegen.cpp

cd ../base
ag -l exc_stack  | xargs sed -i -e 's/exc_stack/excstack/g'
  • Loading branch information
c42f committed Oct 17, 2018
1 parent 5cab916 commit 5b0ca63
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ arbitrary task. This is useful for inspecting tasks which have failed due to
uncaught exceptions.
"""
function catch_stack(task=current_task(); include_bt=true)
raw = ccall(:jl_get_exc_stack, Any, (Any,Cint,Cint), task, include_bt, typemax(Cint))
raw = ccall(:jl_get_excstack, Any, (Any,Cint,Cint), task, include_bt, typemax(Cint))
formatted = Any[]
stride = include_bt ? 3 : 1
for i = reverse(1:stride:length(raw))
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ jl_value_t *jl_parse_eval_all(const char *fname,
form = jl_pchar_to_string(fname, len);
result = jl_box_long(jl_lineno);
err = 1;
goto finally; // skip jl_restore_exc_stack
goto finally; // skip jl_restore_excstack
}
finally:
jl_get_ptls_states()->world_age = last_age;
Expand Down
36 changes: 18 additions & 18 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ static Function *jlgetfield_func;
static Function *jlmethod_func;
static Function *jlgenericfunction_func;
static Function *jlenter_func;
static Function *jlcurrent_exception_func;
static Function *jl_current_exception_func;
static Function *jlleave_func;
static Function *jl_restore_exc_stack_func;
static Function *jl_exc_stack_state_func;
static Function *jl_restore_excstack_func;
static Function *jl_excstack_state_func;
static Function *jlegal_func;
static Function *jl_alloc_obj_func;
static Function *jl_newbits_func;
Expand Down Expand Up @@ -3775,9 +3775,9 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result)
ConstantInt::get(T_int32, jl_unbox_long(args[0])));
}
else if (head == pop_exception_sym) {
jl_cgval_t exc_stack_state = emit_expr(ctx, jl_exprarg(expr, 0));
assert(exc_stack_state.V && exc_stack_state.V->getType() == T_size);
ctx.builder.CreateCall(prepare_call(jl_restore_exc_stack_func), exc_stack_state.V);
jl_cgval_t excstack_state = emit_expr(ctx, jl_exprarg(expr, 0));
assert(excstack_state.V && excstack_state.V->getType() == T_size);
ctx.builder.CreateCall(prepare_call(jl_restore_excstack_func), excstack_state.V);
return;
}
else {
Expand Down Expand Up @@ -4003,7 +4003,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval)
}
else if (head == exc_sym) {
return mark_julia_type(ctx,
ctx.builder.CreateCall(prepare_call(jlcurrent_exception_func)),
ctx.builder.CreateCall(prepare_call(jl_current_exception_func)),
true, jl_any_type);
}
else if (head == copyast_sym) {
Expand Down Expand Up @@ -6195,10 +6195,10 @@ static std::unique_ptr<Module> emit_function(
assert(jl_is_long(args[0]));
int lname = jl_unbox_long(args[0]);
// Save exception stack depth at enter for use in pop_exception
Value *exc_stack_state =
ctx.builder.CreateCall(prepare_call(jl_exc_stack_state_func));
Value *excstack_state =
ctx.builder.CreateCall(prepare_call(jl_excstack_state_func));
assert(!ctx.ssavalue_assigned.at(cursor));
ctx.SAvalues.at(cursor) = jl_cgval_t(exc_stack_state, NULL, false,
ctx.SAvalues.at(cursor) = jl_cgval_t(excstack_state, NULL, false,
(jl_value_t*)jl_ulong_type, NULL);
ctx.ssavalue_assigned.at(cursor) = true;
CallInst *sj = ctx.builder.CreateCall(prepare_call(except_enter_func));
Expand Down Expand Up @@ -7102,11 +7102,11 @@ static void init_julia_llvm_env(Module *m)
"jl_enter_handler", m);
add_named_global(jlenter_func, &jl_enter_handler);

jlcurrent_exception_func =
jl_current_exception_func =
Function::Create(FunctionType::get(T_prjlvalue, false),
Function::ExternalLinkage,
"jl_current_exception", m);
add_named_global(jlcurrent_exception_func, &jl_current_exception);
add_named_global(jl_current_exception_func, &jl_current_exception);

#ifdef _OS_WINDOWS_
#if defined(_CPU_X86_64_)
Expand Down Expand Up @@ -7147,17 +7147,17 @@ static void init_julia_llvm_env(Module *m)
"jl_pop_handler", m);
add_named_global(jlleave_func, &jl_pop_handler);

jl_restore_exc_stack_func =
jl_restore_excstack_func =
Function::Create(FunctionType::get(T_void, T_size, false),
Function::ExternalLinkage,
"jl_restore_exc_stack", m);
add_named_global(jl_restore_exc_stack_func, &jl_restore_exc_stack);
"jl_restore_excstack", m);
add_named_global(jl_restore_excstack_func, &jl_restore_excstack);

jl_exc_stack_state_func =
jl_excstack_state_func =
Function::Create(FunctionType::get(T_size, false),
Function::ExternalLinkage,
"jl_exc_stack_state", m);
add_named_global(jl_exc_stack_state_func, &jl_exc_stack_state);
"jl_excstack_state", m);
add_named_global(jl_excstack_state_func, &jl_excstack_state);

std::vector<Type *> args_2vals_callee_rooted(0);
args_2vals_callee_rooted.push_back(PointerType::get(T_jlvalue, AddressSpace::CalleeRooted));
Expand Down
24 changes: 12 additions & 12 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2070,13 +2070,13 @@ stack: {

excstack: {
// Scan an exception stack
gc_mark_exc_stack_t *stackitr = gc_pop_markdata(&sp, gc_mark_exc_stack_t);
jl_exc_stack_t *exc_stack = stackitr->s;
gc_mark_excstack_t *stackitr = gc_pop_markdata(&sp, gc_mark_excstack_t);
jl_excstack_t *excstack = stackitr->s;
size_t itr = stackitr->itr;
size_t i = stackitr->i;
while (itr > 0) {
size_t bt_size = jl_exc_stack_bt_size(exc_stack, itr);
uintptr_t *bt_data = jl_exc_stack_bt_data(exc_stack, itr);
size_t bt_size = jl_excstack_bt_size(excstack, itr);
uintptr_t *bt_data = jl_excstack_bt_data(excstack, itr);
while (i+2 < bt_size) {
if (bt_data[i] != JL_BT_INTERP_FRAME) {
i++;
Expand All @@ -2089,19 +2089,19 @@ excstack: {
if (gc_try_setmark(new_obj, &nptr, &tag, &bits)) {
stackitr->i = i;
stackitr->itr = itr;
gc_repush_markdata(&sp, gc_mark_exc_stack_t);
gc_repush_markdata(&sp, gc_mark_excstack_t);
goto mark;
}
}
// mark the exception
new_obj = jl_exc_stack_exception(exc_stack, itr);
itr = jl_exc_stack_next(exc_stack, itr);
new_obj = jl_excstack_exception(excstack, itr);
itr = jl_excstack_next(excstack, itr);
i = 0;
uintptr_t nptr = 0;
if (gc_try_setmark(new_obj, &nptr, &tag, &bits)) {
stackitr->i = i;
stackitr->itr = itr;
gc_repush_markdata(&sp, gc_mark_exc_stack_t);
gc_repush_markdata(&sp, gc_mark_excstack_t);
goto mark;
}
}
Expand Down Expand Up @@ -2367,10 +2367,10 @@ mark: {
gc_mark_stack_push(&ptls->gc_cache, &sp, gc_mark_laddr(stack),
&stackdata, sizeof(stackdata), 1);
}
if (ta->exc_stack) {
gc_setmark_buf_(ptls, ta->exc_stack, bits, sizeof(jl_exc_stack_t) +
sizeof(uintptr_t)*ta->exc_stack->reserved_size);
gc_mark_exc_stack_t stackdata = {ta->exc_stack, ta->exc_stack->top, 0};
if (ta->excstack) {
gc_setmark_buf_(ptls, ta->excstack, bits, sizeof(jl_excstack_t) +
sizeof(uintptr_t)*ta->excstack->reserved_size);
gc_mark_excstack_t stackdata = {ta->excstack, ta->excstack->top, 0};
gc_mark_stack_push(&ptls->gc_cache, &sp, gc_mark_laddr(excstack),
&stackdata, sizeof(stackdata), 1);
}
Expand Down
6 changes: 3 additions & 3 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ typedef struct {

// Exception stack data
typedef struct {
jl_exc_stack_t *s; // Stack of exceptions
jl_excstack_t *s; // Stack of exceptions
size_t itr; // Iterator into exception stack
size_t i; // Iterator into backtrace data for exception
} gc_mark_exc_stack_t;
} gc_mark_excstack_t;

// Module bindings. This is also the beginning of module scanning.
// The loop will start marking other references in a module after the bindings are marked
Expand Down Expand Up @@ -185,7 +185,7 @@ union _jl_gc_mark_data {
gc_mark_obj16_t obj16;
gc_mark_obj32_t obj32;
gc_mark_stackframe_t stackframe;
gc_mark_exc_stack_t excstackframe;
gc_mark_excstack_t excstackframe;
gc_mark_binding_t binding;
gc_mark_finlist_t finlist;
};
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ SECT_INTERP static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s
catch_ip += 1;
}
// store current top of exception stack for restore in pop_exception.
s->locals[jl_source_nslots(s->src) + ip] = jl_box_ulong(jl_exc_stack_state());
s->locals[jl_source_nslots(s->src) + ip] = jl_box_ulong(jl_excstack_state());
if (!jl_setjmp(__eh.eh_ctx, 1)) {
return eval_body(stmts, s, next_ip, toplevel);
}
Expand Down Expand Up @@ -712,7 +712,7 @@ SECT_INTERP static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s
}
else if (head == pop_exception_sym) {
size_t prev_state = jl_unbox_ulong(eval_value(jl_exprarg(stmt, 0), s));
jl_restore_exc_stack(prev_state);
jl_restore_excstack(prev_state);
}
else if (head == const_sym) {
jl_sym_t *sym = (jl_sym_t*)jl_exprarg(stmt, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ JL_DLLEXPORT jl_value_t *jl_eval_string(const char *str)

JL_DLLEXPORT jl_value_t *jl_current_exception(void) JL_GLOBALLY_ROOTED
{
jl_exc_stack_t *s = jl_get_ptls_states()->current_task->exc_stack;
return s && s->top != 0 ? jl_exc_stack_exception(s, s->top) : jl_nothing;
jl_excstack_t *s = jl_get_ptls_states()->current_task->excstack;
return s && s->top != 0 ? jl_excstack_exception(s, s->top) : jl_nothing;
}

JL_DLLEXPORT jl_value_t *jl_exception_occurred(void)
Expand Down
10 changes: 5 additions & 5 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ typedef struct _jl_task_t {
// saved gc stack top for context switches
jl_gcframe_t *gcstack;
// saved exception stack
jl_exc_stack_t *exc_stack;
jl_excstack_t *excstack;
// current world age
size_t world_age;

Expand All @@ -1656,8 +1656,8 @@ JL_DLLEXPORT void JL_NORETURN jl_no_exc_handler(jl_value_t *e);
JL_DLLEXPORT void jl_enter_handler(jl_handler_t *eh);
JL_DLLEXPORT void jl_eh_restore_state(jl_handler_t *eh);
JL_DLLEXPORT void jl_pop_handler(int n);
JL_DLLEXPORT size_t jl_exc_stack_state(void);
JL_DLLEXPORT void jl_restore_exc_stack(size_t state);
JL_DLLEXPORT size_t jl_excstack_state(void);
JL_DLLEXPORT void jl_restore_excstack(size_t state);

#if defined(_OS_WINDOWS_)
#if defined(_COMPILER_MINGW_)
Expand Down Expand Up @@ -1697,14 +1697,14 @@ extern int had_exception;

#define JL_TRY \
int i__tr, i__ca; jl_handler_t __eh; \
size_t __exc_stack_state = jl_exc_stack_state(); \
size_t __excstack_state = jl_excstack_state(); \
jl_enter_handler(&__eh); \
if (!jl_setjmp(__eh.eh_ctx,0)) \
for (i__tr=1; i__tr; i__tr=0, jl_eh_restore_state(&__eh))

#define JL_CATCH \
else \
for (i__ca=1, jl_eh_restore_state(&__eh); i__ca; i__ca=0, jl_restore_exc_stack(__exc_stack_state))
for (i__ca=1, jl_eh_restore_state(&__eh); i__ca; i__ca=0, jl_restore_excstack(__excstack_state))

#endif

Expand Down
30 changes: 15 additions & 15 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,46 +661,46 @@ JL_DLLEXPORT size_t jl_capture_interp_frame(uintptr_t *data, uintptr_t sp, uintp

// Exception stack: a stack of pairs of (exception,raw_backtrace).
// The stack may be traversed and accessed with the functions below.
typedef struct _jl_exc_stack_t {
typedef struct _jl_excstack_t {
size_t top;
size_t reserved_size;
// Pack all stack entries into a growable buffer to amortize allocation
// across repeated exception handling.
// Layout: [bt_data1... bt_size1 exc1 bt_data2... bt_size2 exc2 ..]
// uintptr_t data[]; // Access with jl_excstk_raw
} jl_exc_stack_t;
// uintptr_t data[]; // Access with jl_excstack_raw
} jl_excstack_t;

STATIC_INLINE uintptr_t *jl_excstk_raw(jl_exc_stack_t* stack) JL_NOTSAFEPOINT
STATIC_INLINE uintptr_t *jl_excstack_raw(jl_excstack_t* stack) JL_NOTSAFEPOINT
{
return (uintptr_t*)(stack + 1);
}

// Exception stack access
STATIC_INLINE jl_value_t *jl_exc_stack_exception(jl_exc_stack_t *stack JL_PROPAGATES_ROOT,
STATIC_INLINE jl_value_t *jl_excstack_exception(jl_excstack_t *stack JL_PROPAGATES_ROOT,
size_t itr) JL_NOTSAFEPOINT
{
return (jl_value_t*)(jl_excstk_raw(stack)[itr-1]);
return (jl_value_t*)(jl_excstack_raw(stack)[itr-1]);
}
STATIC_INLINE size_t jl_exc_stack_bt_size(jl_exc_stack_t *stack, size_t itr) JL_NOTSAFEPOINT
STATIC_INLINE size_t jl_excstack_bt_size(jl_excstack_t *stack, size_t itr) JL_NOTSAFEPOINT
{
return jl_excstk_raw(stack)[itr-2];
return jl_excstack_raw(stack)[itr-2];
}
STATIC_INLINE uintptr_t *jl_exc_stack_bt_data(jl_exc_stack_t *stack, size_t itr) JL_NOTSAFEPOINT
STATIC_INLINE uintptr_t *jl_excstack_bt_data(jl_excstack_t *stack, size_t itr) JL_NOTSAFEPOINT
{
return jl_excstk_raw(stack) + itr-2 - jl_exc_stack_bt_size(stack, itr);
return jl_excstack_raw(stack) + itr-2 - jl_excstack_bt_size(stack, itr);
}
// Exception stack iteration (start at itr=stack->top, stop at itr=0)
STATIC_INLINE size_t jl_exc_stack_next(jl_exc_stack_t *stack, size_t itr) JL_NOTSAFEPOINT
STATIC_INLINE size_t jl_excstack_next(jl_excstack_t *stack, size_t itr) JL_NOTSAFEPOINT
{
return itr-2 - jl_exc_stack_bt_size(stack, itr);
return itr-2 - jl_excstack_bt_size(stack, itr);
}
// Exception stack manipulation
void jl_reserve_exc_stack(jl_exc_stack_t **stack JL_REQUIRE_ROOTED_SLOT,
void jl_reserve_excstack(jl_excstack_t **stack JL_REQUIRE_ROOTED_SLOT,
size_t reserved_size);
void jl_push_exc_stack(jl_exc_stack_t **stack JL_REQUIRE_ROOTED_SLOT JL_ROOTING_ARGUMENT,
void jl_push_excstack(jl_excstack_t **stack JL_REQUIRE_ROOTED_SLOT JL_ROOTING_ARGUMENT,
jl_value_t *exception JL_ROOTED_ARGUMENT,
uintptr_t *bt_data, size_t bt_size);
void jl_copy_exc_stack(jl_exc_stack_t *dest, jl_exc_stack_t *src) JL_NOTSAFEPOINT;
void jl_copy_excstack(jl_excstack_t *dest, jl_excstack_t *src) JL_NOTSAFEPOINT;

// timers
// Returns time in nanosec
Expand Down
2 changes: 1 addition & 1 deletion src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ typedef struct {
jl_gc_mark_data_t *data_stack;
} jl_gc_mark_cache_t;

typedef struct _jl_exc_stack_t jl_exc_stack_t;
typedef struct _jl_excstack_t jl_excstack_t;
// This includes all the thread local states we care about for a thread.
// Changes to TLS field types must be reflected in codegen.
#define JL_MAX_BT_SIZE 80000
Expand Down
34 changes: 17 additions & 17 deletions src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,55 +280,55 @@ JL_DLLEXPORT void jl_pop_handler(int n)
jl_eh_restore_state(eh);
}

JL_DLLEXPORT size_t jl_exc_stack_state(void)
JL_DLLEXPORT size_t jl_excstack_state(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_exc_stack_t *s = ptls->current_task->exc_stack;
jl_excstack_t *s = ptls->current_task->excstack;
return s ? s->top : 0;
}

JL_DLLEXPORT void jl_restore_exc_stack(size_t state)
JL_DLLEXPORT void jl_restore_excstack(size_t state)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_exc_stack_t *s = ptls->current_task->exc_stack;
jl_excstack_t *s = ptls->current_task->excstack;
if (s) {
assert(s->top >= state);
s->top = state;
}
}

void jl_copy_exc_stack(jl_exc_stack_t *dest, jl_exc_stack_t *src) JL_NOTSAFEPOINT
void jl_copy_excstack(jl_excstack_t *dest, jl_excstack_t *src) JL_NOTSAFEPOINT
{
assert(dest->reserved_size >= src->top);
memcpy(jl_excstk_raw(dest), jl_excstk_raw(src), sizeof(uintptr_t)*src->top);
memcpy(jl_excstack_raw(dest), jl_excstack_raw(src), sizeof(uintptr_t)*src->top);
dest->top = src->top;
}

void jl_reserve_exc_stack(jl_exc_stack_t **stack JL_REQUIRE_ROOTED_SLOT,
void jl_reserve_excstack(jl_excstack_t **stack JL_REQUIRE_ROOTED_SLOT,
size_t reserved_size)
{
jl_exc_stack_t *s = *stack;
jl_excstack_t *s = *stack;
if (s && s->reserved_size >= reserved_size)
return;
size_t bufsz = sizeof(jl_exc_stack_t) + sizeof(uintptr_t)*reserved_size;
jl_exc_stack_t *new_s = (jl_exc_stack_t*)jl_gc_alloc_buf(jl_get_ptls_states(), bufsz);
size_t bufsz = sizeof(jl_excstack_t) + sizeof(uintptr_t)*reserved_size;
jl_excstack_t *new_s = (jl_excstack_t*)jl_gc_alloc_buf(jl_get_ptls_states(), bufsz);
new_s->top = 0;
new_s->reserved_size = reserved_size;
if (s)
jl_copy_exc_stack(new_s, s);
jl_copy_excstack(new_s, s);
*stack = new_s;
}

void jl_push_exc_stack(jl_exc_stack_t **stack JL_REQUIRE_ROOTED_SLOT JL_ROOTING_ARGUMENT,
void jl_push_excstack(jl_excstack_t **stack JL_REQUIRE_ROOTED_SLOT JL_ROOTING_ARGUMENT,
jl_value_t *exception JL_ROOTED_ARGUMENT,
uintptr_t *bt_data, size_t bt_size)
{
jl_reserve_exc_stack(stack, (*stack ? (*stack)->top : 0) + bt_size + 2);
jl_exc_stack_t *s = *stack;
memcpy(jl_excstk_raw(s) + s->top, bt_data, sizeof(uintptr_t)*bt_size);
jl_reserve_excstack(stack, (*stack ? (*stack)->top : 0) + bt_size + 2);
jl_excstack_t *s = *stack;
memcpy(jl_excstack_raw(s) + s->top, bt_data, sizeof(uintptr_t)*bt_size);
s->top += bt_size + 2;
jl_excstk_raw(s)[s->top-2] = bt_size;
jl_excstk_raw(s)[s->top-1] = (uintptr_t)exception;
jl_excstack_raw(s)[s->top-2] = bt_size;
jl_excstack_raw(s)[s->top-1] = (uintptr_t)exception;
}

// misc -----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 5b0ca63

Please sign in to comment.