Skip to content

Commit

Permalink
[interp] Avoid declaring MonoError's in interp_exec_method_full (), i…
Browse files Browse the repository at this point in the history
…t increases the native stack frame size because the optimizer can't seem to figure out live ranges. (mono/mono#15613)

* [interp] Avoid declaring MonoError's in interp_exec_method_full (), it increases the native stack frame size because the optimizer can't seem to figure out live ranges.

* Remove some unused fields from InterpFrame.


Commit migrated from mono/mono@cba8741
  • Loading branch information
vargaz authored Jul 9, 2019
1 parent 248f2d7 commit 6e096e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/mono/mono/mini/interp/interp-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ struct _InterpFrame {
char *varargs;
stackval *stack_args; /* parent */
stackval *stack;
stackval *sp; /* For GC stack marking */
unsigned char *locals;
/* exception info */
unsigned char invoke_trap;
const unsigned short *ip;
MonoException *ex;
};
Expand Down
53 changes: 27 additions & 26 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ init_frame (InterpFrame *frame, InterpFrame *parent_frame, InterpMethod *rmethod
frame->imethod = rmethod;
frame->ex = NULL;
frame->ip = NULL;
frame->invoke_trap = 0;
}

#define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) do { \
InterpMethod *_rmethod = mono_interp_get_imethod ((domain), (mono_method), (error)); \
init_frame ((frame), (parent_frame), _rmethod, (method_args), (method_retval)); \
} while (0)

#define interp_exec_method(frame, context) interp_exec_method_full ((frame), (context), NULL)
#define interp_exec_method(frame, context, error) interp_exec_method_full ((frame), (context), NULL, error)

/*
* List of classes whose methods will be executed by transitioning to JITted code.
Expand All @@ -131,7 +130,7 @@ static gboolean ss_enabled;

static gboolean interp_init_done = FALSE;

static void interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClauseArgs *clause_args);
static void interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClauseArgs *clause_args, MonoError *error);
static InterpMethod* lookup_method_pointer (gpointer addr);

typedef void (*ICallMethod) (InterpFrame *frame);
Expand Down Expand Up @@ -287,7 +286,7 @@ get_context (void)
return context;
}

static void
static MONO_NEVER_INLINE void
ves_real_abort (int line, MonoMethod *mh,
const unsigned short *ip, stackval *stack, stackval *sp)
{
Expand Down Expand Up @@ -452,7 +451,7 @@ interp_pop_lmf (MonoLMFExt *ext)
mono_pop_lmf (&ext->lmf);
}

static InterpMethod*
static MONO_NEVER_INLINE InterpMethod*
get_virtual_method (InterpMethod *imethod, MonoObject *obj)
{
MonoMethod *m = imethod->method;
Expand Down Expand Up @@ -992,7 +991,7 @@ ves_array_calculate_index (MonoArray *ao, stackval *sp, InterpFrame *frame, gboo
return pos;
}

static void
static MONO_NEVER_INLINE void
ves_array_set (InterpFrame *frame, stackval *sp, MonoMethodSignature *sig)
{
MonoObject *o = sp->data.o;
Expand Down Expand Up @@ -1735,10 +1734,7 @@ interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject

INIT_FRAME (&frame, NULL, args, &result, domain, invoke_wrapper, error);

if (exc)
frame.invoke_trap = 1;

interp_exec_method (&frame, context);
interp_exec_method (&frame, context, error);

if (frame.ex) {
if (exc) {
Expand Down Expand Up @@ -1843,7 +1839,8 @@ interp_entry (InterpEntryData *data)
break;
}

interp_exec_method (&frame, context);
ERROR_DECL (error);
interp_exec_method (&frame, context, error);

if (rmethod->needs_thread_attach)
mono_threads_detach_coop (orig_domain, &attach_cookie);
Expand Down Expand Up @@ -2326,7 +2323,7 @@ do_transform_method (InterpFrame *frame, ThreadContext *context)
interp_pop_lmf (&ext);
}

static void
static MONO_NEVER_INLINE void
copy_varargs_vtstack (MonoMethodSignature *csig, stackval *sp, unsigned char **vt_sp)
{
char *vt = *(char**)vt_sp;
Expand Down Expand Up @@ -2563,7 +2560,8 @@ interp_entry_from_trampoline (gpointer ccontext_untyped, gpointer rmethod_untype
/* Copy the args saved in the trampoline to the frame stack */
mono_arch_get_native_call_context_args (ccontext, &frame, sig);

interp_exec_method (&frame, context);
ERROR_DECL (error);
interp_exec_method (&frame, context, error);

if (rmethod->needs_thread_attach)
mono_threads_detach_coop (orig_domain, &attach_cookie);
Expand Down Expand Up @@ -2881,9 +2879,11 @@ static int opcode_counts[512];
/*
* If EXIT_AT_FINALLY is not -1, exit after exiting the finally clause with that index.
* If BASE_FRAME is not NULL, copy arguments/locals from BASE_FRAME.
* The ERROR argument is used to avoid declaring an error object for every interp frame, its not used
* to return error information.
*/
static void
interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClauseArgs *clause_args)
interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClauseArgs *clause_args, MonoError *error)
{
InterpFrame child_frame;
GSList *finally_ips = NULL;
Expand All @@ -2900,7 +2900,6 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
int i32;
unsigned char *vt_sp;
unsigned char *locals = NULL;
ERROR_DECL (error);
MonoObject *o = NULL;
MonoClass *c;
#if USE_COMPUTED_GOTO
Expand Down Expand Up @@ -3167,7 +3166,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
}
}

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -3235,7 +3234,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
child_frame.imethod = mono_interp_get_imethod (imethod->domain, m, error);
mono_error_cleanup (error); /* FIXME: don't swallow the error */

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);
} else {
ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context, save_last_error);
}
Expand Down Expand Up @@ -3282,7 +3281,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
sp [0].data.p = unboxed;
}

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -3316,7 +3315,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
sp -= child_frame.imethod->param_count + child_frame.imethod->hasthis + num_varargs;
child_frame.stack_args = sp;

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -3357,7 +3356,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
}
}

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -4404,7 +4403,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
ip += 4;
}

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -4481,7 +4480,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
}
}

interp_exec_method (&child_frame, context);
interp_exec_method (&child_frame, context, error);

CHECK_RESUME_STATE (context);

Expand Down Expand Up @@ -6407,6 +6406,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause

exit_frame:

error_init_reuse (error);

if (clause_args && clause_args->base_frame)
memcpy (clause_args->base_frame->args, frame->args, imethod->alloca_size);

Expand Down Expand Up @@ -6463,8 +6464,6 @@ interp_parse_options (const char *options)
}
}

typedef int (*TestMethod) (void);

/*
* interp_set_resume_state:
*
Expand Down Expand Up @@ -6510,7 +6509,8 @@ interp_run_finally (StackFrameInfo *frame, int clause_index, gpointer handler_ip
clause_args.end_at_ip = (guint16*) handler_ip_end;
clause_args.exit_clause = clause_index;

interp_exec_method_full (iframe, context, &clause_args);
ERROR_DECL (error);
interp_exec_method_full (iframe, context, &clause_args, error);
if (context->has_resume_state) {
return TRUE;
} else {
Expand Down Expand Up @@ -6550,7 +6550,8 @@ interp_run_filter (StackFrameInfo *frame, MonoException *ex, int clause_index, g
clause_args.filter_exception = ex;
clause_args.base_frame = iframe;

interp_exec_method_full (&child_frame, context, &clause_args);
ERROR_DECL (error);
interp_exec_method_full (&child_frame, context, &clause_args, error);
/* ENDFILTER stores the result into child_frame->retval */
return child_frame.retval->data.i ? TRUE : FALSE;
}
Expand Down

0 comments on commit 6e096e5

Please sign in to comment.