Skip to content

Commit

Permalink
wipe out non-interned static callsites
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Oct 12, 2014
1 parent 3e8e71b commit c3f7682
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 103 deletions.
37 changes: 10 additions & 27 deletions src/6model/6model.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
#include "moar.h"

/* Dummy callsite for find_method. */
static MVMCallsiteEntry fm_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite fm_callsite = { fm_flags, 3, 3, 0 };

/* Dummy callsite for method not found errors. */
static MVMCallsiteEntry mnfe_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite mnfe_callsite = { mnfe_flags, 2, 2, 0 };

/* Dummy callsite for type_check. */
static MVMCallsiteEntry tc_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ };
static MVMCallsite tc_callsite = { tc_flags, 3, 3, 0 };

/* Gets the HOW (meta-object), which may be lazily deserialized. */
MVMObject * MVM_6model_get_how(MVMThreadContext *tc, MVMSTable *st) {
MVMObject *HOW = st->HOW;
Expand Down Expand Up @@ -57,10 +40,10 @@ static void die_over_missing_method(MVMThreadContext *tc, MVMObject *obj, MVMStr
MVMObject *handler = MVM_hll_current(tc)->method_not_found_error;
if (!MVM_is_null(tc, handler)) {
handler = MVM_frame_find_invokee(tc, handler, NULL);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, &mnfe_callsite);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_METH_NOT_FOUND));
tc->cur_frame->args[0].o = obj;
tc->cur_frame->args[1].s = name;
STABLE(handler)->invoke(tc, handler, &mnfe_callsite, tc->cur_frame->args);
STABLE(handler)->invoke(tc, handler, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_METH_NOT_FOUND), tc->cur_frame->args);
return;
}
else {
Expand Down Expand Up @@ -121,7 +104,7 @@ void MVM_6model_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *nam

/* Set up the call, using the result register as the target. */
code = MVM_frame_find_invokee(tc, find_method, NULL);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, &fm_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD));
{
FindMethodSRData *fm = MVM_malloc(sizeof(FindMethodSRData));
fm->obj = obj;
Expand All @@ -134,7 +117,7 @@ void MVM_6model_find_method(MVMThreadContext *tc, MVMObject *obj, MVMString *nam
tc->cur_frame->args[0].o = HOW;
tc->cur_frame->args[1].o = obj;
tc->cur_frame->args[2].s = name;
STABLE(code)->invoke(tc, code, &fm_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD), tc->cur_frame->args);
}

MVMint32 MVM_6model_find_method_spesh(MVMThreadContext *tc, MVMObject *obj, MVMString *name,
Expand Down Expand Up @@ -216,13 +199,13 @@ void MVM_6model_can_method(MVMThreadContext *tc, MVMObject *obj, MVMString *name
/* Set up the call, using the result register as the target. A little bad
* as we're really talking about */
code = MVM_frame_find_invokee(tc, find_method, NULL);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, &fm_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD));
tc->cur_frame->special_return = late_bound_can_return;
tc->cur_frame->special_return_data = res;
tc->cur_frame->args[0].o = HOW;
tc->cur_frame->args[1].o = obj;
tc->cur_frame->args[2].s = name;
STABLE(code)->invoke(tc, code, &fm_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_FIND_METHOD), tc->cur_frame->args);
}
void late_bound_can_return(MVMThreadContext *tc, void *sr_data) {
/* Transform to an integer result. */
Expand All @@ -239,11 +222,11 @@ static void do_accepts_type_check(MVMThreadContext *tc, MVMObject *obj, MVMObjec
if (!MVM_is_null(tc, meth)) {
/* Set up the call, using the result register as the target. */
MVMObject *code = MVM_frame_find_invokee(tc, meth, NULL);
MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, &tc_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK));
tc->cur_frame->args[0].o = HOW;
tc->cur_frame->args[1].o = type;
tc->cur_frame->args[2].o = obj;
STABLE(code)->invoke(tc, code, &tc_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK), tc->cur_frame->args);
return;
}
else {
Expand Down Expand Up @@ -313,7 +296,7 @@ void MVM_6model_istype(MVMThreadContext *tc, MVMObject *obj, MVMObject *type, MV
if (!MVM_is_null(tc, meth)) {
/* Set up the call, using the result register as the target. */
MVMObject *code = MVM_frame_find_invokee(tc, meth, NULL);
MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, &tc_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_INT, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK));
tc->cur_frame->args[0].o = HOW;
tc->cur_frame->args[1].o = obj;
tc->cur_frame->args[2].o = type;
Expand All @@ -326,7 +309,7 @@ void MVM_6model_istype(MVMThreadContext *tc, MVMObject *obj, MVMObject *type, MV
tc->cur_frame->special_return_data = atd;
tc->cur_frame->mark_special_return_data = mark_sr_data;
}
STABLE(code)->invoke(tc, code, &tc_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TYPECHECK), tc->cur_frame->args);
return;
}
}
Expand Down
14 changes: 4 additions & 10 deletions src/6model/containers.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,25 @@ typedef struct {
MVMObject *store_code;
} CodePairContData;

/* Dummy, code pair fetch and store arg callsite. */
static MVMCallsiteEntry fetch_arg_flags[] = { MVM_CALLSITE_ARG_OBJ };
static MVMCallsiteEntry store_arg_flags[] = { MVM_CALLSITE_ARG_OBJ, MVM_CALLSITE_ARG_OBJ };
static MVMCallsite fetch_arg_callsite = { fetch_arg_flags, 1, 1, 0 };
static MVMCallsite store_arg_callsite = { store_arg_flags, 2, 2, 0 };

static void code_pair_fetch(MVMThreadContext *tc, MVMObject *cont, MVMRegister *res) {
CodePairContData *data = (CodePairContData *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->fetch_code, NULL);

MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, &fetch_arg_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG));
tc->cur_frame->args[0].o = cont;

STABLE(code)->invoke(tc, code, &fetch_arg_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG), tc->cur_frame->args);
}

static void code_pair_store(MVMThreadContext *tc, MVMObject *cont, MVMObject *obj) {
CodePairContData *data = (CodePairContData *)STABLE(cont)->container_data;
MVMObject *code = MVM_frame_find_invokee(tc, data->store_code, NULL);

MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, &store_arg_callsite);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ));
tc->cur_frame->args[0].o = cont;
tc->cur_frame->args[1].o = obj;

STABLE(code)->invoke(tc, code, &store_arg_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ), tc->cur_frame->args);
}

static void code_pair_gc_mark_data(MVMThreadContext *tc, MVMSTable *st, MVMGCWorklist *worklist) {
Expand Down
8 changes: 2 additions & 6 deletions src/core/args.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "moar.h"

/* Dummy one-arg callsite. */
static MVMCallsiteEntry one_arg_flags[] = { MVM_CALLSITE_ARG_OBJ };
static MVMCallsite one_arg_callsite = { one_arg_flags, 1, 1, 0 };

static void init_named_used(MVMThreadContext *tc, MVMArgProcContext *ctx, MVMuint16 num) {
if (ctx->named_used && ctx->named_used_size >= num) { /* reuse the old one */
memset(ctx->named_used, 0, ctx->named_used_size * sizeof(MVMuint8));
Expand Down Expand Up @@ -837,10 +833,10 @@ void MVM_args_bind_failed(MVMThreadContext *tc) {
MVM_exception_throw_adhoc(tc, "Bind erorr occurred, but HLL has no handler");
bind_error = MVM_frame_find_invokee(tc, bind_error, NULL);
res = MVM_calloc(1, sizeof(MVMRegister));
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, &one_arg_callsite);
MVM_args_setup_thunk(tc, res, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG));
tc->cur_frame->special_return = bind_error_return;
tc->cur_frame->special_return_data = res;
tc->cur_frame->mark_special_return_data = mark_sr_data;
tc->cur_frame->args[0].o = cc_obj;
STABLE(bind_error)->invoke(tc, bind_error, &one_arg_callsite, tc->cur_frame->args);
STABLE(bind_error)->invoke(tc, bind_error, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG), tc->cur_frame->args);
}
38 changes: 35 additions & 3 deletions src/core/callsite.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,56 @@ static MVMint32 callsites_equal(MVMThreadContext *tc, MVMCallsite *cs1, MVMCalls
return 1;
}

static MVMCallsite null_args_callsite = { NULL, 0, 0, 0, 0, 0, 0 };

static MVMCallsiteEntry obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ };
static MVMCallsite inv_arg_callsite = { obj_arg_flags, 1, 1, 0, 0, 0, 0 };
static MVMCallsite *callsite_inv_arg = &inv_arg_callsite;

static MVMCallsiteEntry mnfe_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite methnotfound_callsite = { mnfe_flags, 2, 2, 0 };

static MVMCallsiteEntry fm_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_STR };
static MVMCallsite findmeth_callsite = { fm_flags, 3, 3, 0 };

static MVMCallsiteEntry tc_flags[] = { MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ,
MVM_CALLSITE_ARG_OBJ };
static MVMCallsite typecheck_callsite = { tc_flags, 3, 3, 0 };

MVMCallsite *MVM_callsite_get_common(MVMThreadContext *tc, MVMCommonCallsiteID id) {
switch (id) {
case MVM_CALLSITE_ID_INV_ARG:
return callsite_inv_arg;
return &inv_arg_callsite;
case MVM_CALLSITE_ID_NULL_ARGS:
return &null_args_callsite;
case MVM_CALLSITE_ID_METH_NOT_FOUND:
return &methnotfound_callsite;
case MVM_CALLSITE_ID_FIND_METHOD:
return &findmeth_callsite;
case MVM_CALLSITE_ID_TYPECHECK:
return &typecheck_callsite;
default:
MVM_exception_throw_adhoc(tc, "get_common_callsite: id %d unknown", id);
return NULL;
}
}

void MVM_callsite_initialize_common(MVMInstance *instance) {
MVM_callsite_try_intern(instance->main_thread, &callsite_inv_arg);
MVMCallsite *ptr;

ptr = &inv_arg_callsite;
MVM_callsite_try_intern(instance->main_thread, &ptr);
ptr = &null_args_callsite;
MVM_callsite_try_intern(instance->main_thread, &ptr);
ptr = &methnotfound_callsite;
MVM_callsite_try_intern(instance->main_thread, &ptr);
ptr = &findmeth_callsite;
MVM_callsite_try_intern(instance->main_thread, &ptr);
ptr = &typecheck_callsite;
MVM_callsite_try_intern(instance->main_thread, &ptr);
}

/* Tries to intern the callsite, freeing and updating the one passed in and
Expand Down
24 changes: 22 additions & 2 deletions src/core/callsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,28 @@ typedef enum {
} MVMCallsiteFlags;

typedef enum {
/* Dummy, invocant-arg callsite. Taken from coerce.c */
MVM_CALLSITE_ID_INV_ARG = 1
/* Zero argument callsite. */
MVM_CALLSITE_ID_NULL_ARGS,

/* Dummy, invocant-arg callsite. Taken from coerce.c;
* OBJ */
MVM_CALLSITE_ID_INV_ARG,

/* Callsite for container store. Taken from containers.c;
* OBJ, OBJ */
MVM_CALLSITE_ID_TWO_OBJ,

/* Callsite for method not found errors. Taken from 6model.c;
* OBJ, STR */
MVM_CALLSITE_ID_METH_NOT_FOUND,

/* Callsite for finding methods. Taken from 6model.c;
* OBJ, OBJ, STR */
MVM_CALLSITE_ID_FIND_METHOD,

/* Callsite for typechecks. Taken from 6model.c;
* OBJ, OBJ, OBJ */
MVM_CALLSITE_ID_TYPECHECK,
} MVMCommonCallsiteID;

/* A callsite entry is just one of the above flags. */
Expand Down
16 changes: 6 additions & 10 deletions src/core/continuation.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "moar.h"

static MVMCallsite no_arg_callsite = { NULL, 0, 0, 0 };
static MVMCallsiteEntry obj_arg_flags[] = { MVM_CALLSITE_ARG_OBJ };
static MVMCallsite obj_arg_callsite = { obj_arg_flags, 1, 1, 0 };

static void clear_tag(MVMThreadContext *tc, void *sr_data) {
MVMContinuationTag **update = &tc->cur_frame->continuation_tags;
while (*update) {
Expand Down Expand Up @@ -33,10 +29,10 @@ void MVM_continuation_reset(MVMThreadContext *tc, MVMObject *tag,
else {
/* Run the passed code. */
code = MVM_frame_find_invokee(tc, code, NULL);
MVM_args_setup_thunk(tc, res_reg, MVM_RETURN_OBJ, &no_arg_callsite);
MVM_args_setup_thunk(tc, res_reg, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS));
tc->cur_frame->special_return = clear_tag;
tc->cur_frame->special_return_data = tag_record;
STABLE(code)->invoke(tc, code, &no_arg_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS), tc->cur_frame->args);
}
}

Expand Down Expand Up @@ -122,9 +118,9 @@ void MVM_continuation_control(MVMThreadContext *tc, MVMint64 protect,
* interpreter to run this, which then returns control to the
* original reset or invoke. */
code = MVM_frame_find_invokee(tc, code, NULL);
MVM_args_setup_thunk(tc, tc->cur_frame->return_value, tc->cur_frame->return_type, &obj_arg_callsite);
MVM_args_setup_thunk(tc, tc->cur_frame->return_value, tc->cur_frame->return_type, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG));
tc->cur_frame->args[0].o = cont;
STABLE(code)->invoke(tc, code, &obj_arg_callsite, tc->cur_frame->args);
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_INV_ARG), tc->cur_frame->args);
}

void MVM_continuation_invoke(MVMThreadContext *tc, MVMContinuation *cont,
Expand Down Expand Up @@ -179,8 +175,8 @@ void MVM_continuation_invoke(MVMThreadContext *tc, MVMContinuation *cont,
}
else {
code = MVM_frame_find_invokee(tc, code, NULL);
MVM_args_setup_thunk(tc, cont->body.res_reg, MVM_RETURN_OBJ, &no_arg_callsite);
STABLE(code)->invoke(tc, code, &no_arg_callsite, tc->cur_frame->args);
MVM_args_setup_thunk(tc, cont->body.res_reg, MVM_RETURN_OBJ, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS));
STABLE(code)->invoke(tc, code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS), tc->cur_frame->args);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/core/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ static LocatedHandler search_for_handler_from(MVMThreadContext *tc, MVMFrame *f,
return lh;
}

/* Dummy, 0-arg callsite for invoking handlers. */
static MVMCallsite no_arg_callsite = { NULL, 0, 0, 0 };

/* Runs an exception handler (which really means updating interpreter state
* so that when we return to the runloop, we're in the handler). If there is
* an exception object already, it will be used; NULL can be passed if there
Expand Down Expand Up @@ -214,7 +211,7 @@ static void run_handler(MVMThreadContext *tc, LocatedHandler lh, MVMObject *ex_o
tc->cur_frame->special_return_data = ah;

/* Invoke the handler frame and return to runloop. */
STABLE(handler_code)->invoke(tc, handler_code, &no_arg_callsite,
STABLE(handler_code)->invoke(tc, handler_code, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS),
tc->cur_frame->args);
break;
}
Expand Down
12 changes: 4 additions & 8 deletions src/core/frame.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "moar.h"

/* Dummy, invocant-arg callsite. */
static MVMCallsiteEntry exit_arg_flags[] = { MVM_CALLSITE_ARG_OBJ, MVM_CALLSITE_ARG_OBJ };
static MVMCallsite exit_arg_callsite = { exit_arg_flags, 2, 2, 0 };

static void grow_frame_pool(MVMThreadContext *tc, MVMuint32 pool_index) {
MVMuint32 old_size = tc->frame_pool_table_size;
MVMuint32 new_size = tc->frame_pool_table_size;
Expand Down Expand Up @@ -757,13 +753,13 @@ MVMuint64 MVM_frame_try_return(MVMThreadContext *tc) {
result = NULL;
}

MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, &exit_arg_callsite);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ));
tc->cur_frame->args[0].o = tc->cur_frame->code_ref;
tc->cur_frame->args[1].o = result;
tc->cur_frame->special_return = remove_after_handler;
tc->cur_frame->flags |= MVM_FRAME_FLAG_EXIT_HAND_RUN;
handler = MVM_frame_find_invokee(tc, hll->exit_handler, NULL);
STABLE(handler)->invoke(tc, handler, &exit_arg_callsite, tc->cur_frame->args);
STABLE(handler)->invoke(tc, handler, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ), tc->cur_frame->args);
return 1;
}
else {
Expand Down Expand Up @@ -805,7 +801,7 @@ void MVM_frame_unwind_to(MVMThreadContext *tc, MVMFrame *frame, MVMuint8 *abs_ad
if (tc->cur_frame == tc->thread_entry_frame)
MVM_exception_throw_adhoc(tc, "Thread entry point frame cannot have an exit handler");

MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, &exit_arg_callsite);
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ));
tc->cur_frame->args[0].o = tc->cur_frame->code_ref;
tc->cur_frame->args[1].o = NULL;
tc->cur_frame->special_return = continue_unwind;
Expand All @@ -820,7 +816,7 @@ void MVM_frame_unwind_to(MVMThreadContext *tc, MVMFrame *frame, MVMuint8 *abs_ad
}
tc->cur_frame->flags |= MVM_FRAME_FLAG_EXIT_HAND_RUN;
handler = MVM_frame_find_invokee(tc, hll->exit_handler, NULL);
STABLE(handler)->invoke(tc, handler, &exit_arg_callsite, tc->cur_frame->args);
STABLE(handler)->invoke(tc, handler, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_TWO_OBJ), tc->cur_frame->args);
return;
}
else {
Expand Down
Loading

0 comments on commit c3f7682

Please sign in to comment.