Skip to content

Commit 7645c8b

Browse files
committed
Revert "[interp] Optimise method execution start (mono#11328)"
This reverts commit ecf399d. It breaks a webassembly test.
1 parent db5666c commit 7645c8b

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

mono/mini/interp/interp-internals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ struct _InterpFrame {
135135
unsigned char invoke_trap;
136136
const unsigned short *ip;
137137
MonoException *ex;
138+
MonoExceptionClause *ex_handler;
139+
MonoDomain *domain;
138140
};
139141

140142
typedef struct {
143+
InterpFrame *current_frame;
141144
/* Resume state for resuming execution in mixed mode */
142145
gboolean has_resume_state;
143146
/* Frame to resume execution at */

mono/mini/interp/interp.c

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ ves_pinvoke_method (InterpFrame *frame, MonoMethodSignature *sig, MonoFuncV addr
12041204
g_print ("ICALL: mono_interp_to_native_trampoline = %p, addr = %p\n", mono_interp_to_native_trampoline, addr);
12051205
#endif
12061206

1207-
INTERP_PUSH_LMF_WITH_CTX (frame, ext, &&exit_pinvoke);
1207+
context->current_frame = frame;
1208+
INTERP_PUSH_LMF_WITH_CTX (context->current_frame, ext, &&exit_pinvoke);
12081209
#ifdef MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP
12091210
mono_interp_to_native_trampoline (addr, &ccontext);
12101211
#else
@@ -1601,7 +1602,7 @@ get_trace_ips (MonoDomain *domain, InterpFrame *top)
16011602
static MonoObject*
16021603
interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
16031604
{
1604-
InterpFrame frame;
1605+
InterpFrame frame, *old_frame;
16051606
ThreadContext *context = get_context ();
16061607
MonoMethodSignature *sig = mono_method_signature_internal (method);
16071608
MonoClass *klass = mono_class_from_mono_type_internal (sig->ret);
@@ -1614,6 +1615,8 @@ interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject
16141615

16151616
frame.ex = NULL;
16161617

1618+
old_frame = context->current_frame;
1619+
16171620
MonoDomain *domain = mono_domain_get ();
16181621

16191622
if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
@@ -1640,6 +1643,8 @@ interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject
16401643

16411644
interp_exec_method (&frame, context);
16421645

1646+
context->current_frame = old_frame;
1647+
16431648
if (frame.ex) {
16441649
if (exc) {
16451650
*exc = (MonoObject*) frame.ex;
@@ -1666,6 +1671,7 @@ interp_entry (InterpEntryData *data)
16661671
InterpFrame frame;
16671672
InterpMethod *rmethod = data->rmethod;
16681673
ThreadContext *context;
1674+
InterpFrame *old_frame;
16691675
stackval result;
16701676
stackval *args;
16711677
MonoMethod *method;
@@ -1687,6 +1693,7 @@ interp_entry (InterpEntryData *data)
16871693
//printf ("%s\n", mono_method_full_name (method, 1));
16881694

16891695
frame.ex = NULL;
1696+
old_frame = context->current_frame;
16901697

16911698
args = g_newa (stackval, sig->param_count + (sig->hasthis ? 1 : 0));
16921699
if (sig->hasthis)
@@ -1737,6 +1744,7 @@ interp_entry (InterpEntryData *data)
17371744
}
17381745

17391746
interp_exec_method (&frame, context);
1747+
context->current_frame = old_frame;
17401748

17411749
if (rmethod->needs_thread_attach)
17421750
mono_threads_detach_coop (orig_domain, &attach_cookie);
@@ -1770,10 +1778,10 @@ interp_entry (InterpEntryData *data)
17701778

17711779
/* MONO_NO_OPTIMIATION is needed due to usage of INTERP_PUSH_LMF_WITH_CTX. */
17721780
static MONO_NO_OPTIMIZATION MONO_NEVER_INLINE stackval *
1773-
do_icall (InterpFrame *frame, MonoMethodSignature *sig, int op, stackval *sp, gpointer ptr)
1781+
do_icall (ThreadContext *context, MonoMethodSignature *sig, int op, stackval *sp, gpointer ptr)
17741782
{
17751783
MonoLMFExt ext;
1776-
INTERP_PUSH_LMF_WITH_CTX (frame, ext, &&exit_icall);
1784+
INTERP_PUSH_LMF_WITH_CTX (context->current_frame, ext, &&exit_icall);
17771785

17781786
switch (op) {
17791787
case MINT_ICALL_V_V: {
@@ -2360,6 +2368,7 @@ interp_entry_from_trampoline (gpointer ccontext_untyped, gpointer rmethod_untype
23602368
{
23612369
InterpFrame frame;
23622370
ThreadContext *context;
2371+
InterpFrame *old_frame;
23632372
stackval result;
23642373
stackval *args;
23652374
MonoMethod *method;
@@ -2378,6 +2387,7 @@ interp_entry_from_trampoline (gpointer ccontext_untyped, gpointer rmethod_untype
23782387
sig = mono_method_signature_internal (method);
23792388

23802389
frame.ex = NULL;
2390+
old_frame = context->current_frame;
23812391

23822392
args = (stackval*)alloca (sizeof (stackval) * (sig->param_count + (sig->hasthis ? 1 : 0)));
23832393

@@ -2396,6 +2406,7 @@ interp_entry_from_trampoline (gpointer ccontext_untyped, gpointer rmethod_untype
23962406
mono_arch_get_native_call_context_args (ccontext, &frame, sig);
23972407

23982408
interp_exec_method (&frame, context);
2409+
context->current_frame = old_frame;
23992410

24002411
if (rmethod->needs_thread_attach)
24012412
mono_threads_detach_coop (orig_domain, &attach_cookie);
@@ -2611,19 +2622,23 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
26112622
0 };
26122623
#endif
26132624

2625+
26142626
frame->ex = NULL;
2627+
frame->ex_handler = NULL;
2628+
frame->ip = NULL;
2629+
frame->domain = mono_domain_get ();
2630+
context->current_frame = frame;
26152631

26162632
debug_enter (frame, &tracing);
26172633

26182634
rtm = frame->imethod;
2619-
if (!rtm->transformed) {
2635+
if (!frame->imethod->transformed) {
26202636
#if DEBUG_INTERP
26212637
char *mn = mono_method_full_name (frame->imethod->method, TRUE);
26222638
g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
26232639
g_free (mn);
26242640
#endif
26252641

2626-
frame->ip = NULL;
26272642
do_transform_method (frame, context);
26282643
if (frame->ex)
26292644
THROW_EX (frame->ex, NULL);
@@ -2632,6 +2647,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
26322647

26332648
if (!start_with_ip) {
26342649
frame->args = g_newa (char, rtm->alloca_size);
2650+
memset (frame->args, 0, rtm->alloca_size);
2651+
26352652
ip = rtm->code;
26362653
} else {
26372654
ip = start_with_ip;
@@ -2862,6 +2879,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
28622879

28632880
interp_exec_method (&child_frame, context);
28642881

2882+
context->current_frame = frame;
2883+
28652884
if (context->has_resume_state) {
28662885
if (frame == context->handler_frame)
28672886
SET_RESUME_STATE (context);
@@ -2886,7 +2905,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
28862905
sp--;
28872906
frame->ip = ip;
28882907

2889-
sp = do_icall (frame, csignature, opcode, sp, target_ip);
2908+
sp = do_icall (context, csignature, opcode, sp, target_ip);
28902909
EXCEPTION_CHECKPOINT;
28912910
if (context->has_resume_state) {
28922911
if (frame == context->handler_frame)
@@ -2941,6 +2960,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
29412960
} else {
29422961
ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
29432962
}
2963+
context->current_frame = frame;
29442964

29452965
if (context->has_resume_state) {
29462966
if (frame == context->handler_frame)
@@ -3000,6 +3020,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
30003020

30013021
interp_exec_method (&child_frame, context);
30023022

3023+
context->current_frame = frame;
3024+
30033025
if (context->has_resume_state) {
30043026
if (frame == context->handler_frame)
30053027
SET_RESUME_STATE (context);
@@ -4044,6 +4066,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
40444066

40454067
interp_exec_method (&child_frame, context);
40464068

4069+
context->current_frame = frame;
4070+
40474071
if (context->has_resume_state) {
40484072
if (frame == context->handler_frame)
40494073
SET_RESUME_STATE (context);
@@ -4126,6 +4150,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
41264150

41274151
interp_exec_method (&child_frame, context);
41284152

4153+
context->current_frame = frame;
4154+
41294155
if (context->has_resume_state) {
41304156
if (frame == context->handler_frame)
41314157
SET_RESUME_STATE (context);
@@ -4230,6 +4256,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
42304256
MINT_IN_BREAK;
42314257
MINT_IN_CASE(MINT_THROW)
42324258
--sp;
4259+
frame->ex_handler = NULL;
42334260
if (!sp->data.p)
42344261
sp->data.p = mono_get_exception_null_reference ();
42354262

@@ -5232,6 +5259,11 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
52325259
}
52335260
frame->ip = ip;
52345261

5262+
if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
5263+
frame->ex_handler = NULL;
5264+
frame->ex = NULL;
5265+
}
5266+
52355267
if (frame->imethod->method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE) {
52365268
stackval tmp_sp;
52375269

@@ -5242,7 +5274,9 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
52425274
* to check the abort threshold. For this to work we use child_frame as a
52435275
* dummy frame that is stored in the lmf and serves as the transition frame
52445276
*/
5245-
do_icall (&child_frame, NULL, MINT_ICALL_V_P, &tmp_sp, (gpointer)mono_thread_get_undeniable_exception);
5277+
context->current_frame = &child_frame;
5278+
do_icall (context, NULL, MINT_ICALL_V_P, &tmp_sp, (gpointer)mono_thread_get_undeniable_exception);
5279+
context->current_frame = frame;
52465280

52475281
MonoException *abort_exc = (MonoException*)tmp_sp.data.p;
52485282
if (abort_exc)
@@ -5272,7 +5306,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
52725306
MINT_IN_CASE(MINT_ICALL_PPPPPP_V)
52735307
MINT_IN_CASE(MINT_ICALL_PPPPPP_P)
52745308
frame->ip = ip;
5275-
sp = do_icall (frame, NULL, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
5309+
sp = do_icall (context, NULL, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
52765310
EXCEPTION_CHECKPOINT;
52775311
if (context->has_resume_state) {
52785312
if (frame == context->handler_frame)
@@ -5769,6 +5803,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
57695803
* actually run the new found handler.
57705804
*/
57715805
int exvar_offset = *(guint16*)(ip + 1);
5806+
frame->ex_handler = NULL;
57725807
THROW_EX_GENERAL (*(MonoException**)(frame->locals + exvar_offset), ip - 1, TRUE);
57735808
MINT_IN_BREAK;
57745809
}
@@ -5782,6 +5817,7 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
57825817
*/
57835818

57845819
--sp;
5820+
frame->ex_handler = NULL;
57855821
if (!sp->data.p)
57865822
sp->data.p = mono_get_exception_null_reference ();
57875823

@@ -5852,8 +5888,12 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
58525888

58535889
if (endfinally_ip != NULL)
58545890
finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
5891+
for (i = 0; i < rtm->num_clauses; ++i)
5892+
if (frame->ex_handler == &rtm->clauses [i])
5893+
break;
58555894

5856-
for (i = rtm->num_clauses - 1; i >= 0; i--) {
5895+
while (i > 0) {
5896+
--i;
58575897
clause = &rtm->clauses [i];
58585898
if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
58595899
if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
@@ -6051,7 +6091,7 @@ interp_frame_iter_next (MonoInterpStackIter *iter, StackFrameInfo *frame)
60516091
return FALSE;
60526092

60536093
MonoMethod *method = iframe->imethod->method;
6054-
frame->domain = iframe->imethod->domain;
6094+
frame->domain = iframe->domain;
60556095
frame->interp_frame = iframe;
60566096
frame->method = method;
60576097
frame->actual_method = method;

mono/mini/interp/transform.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,13 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, unsig
22262226

22272227
body_start_offset = td->new_ip - td->new_code;
22282228

2229-
if (header->num_locals && header->init_locals)
2230-
ADD_CODE(td, MINT_INITLOCALS);
2229+
for (i = 0; i < header->num_locals; i++) {
2230+
int mt = mint_type(header->locals [i]);
2231+
if (mt == MINT_TYPE_VT || mt == MINT_TYPE_O || mt == MINT_TYPE_P) {
2232+
ADD_CODE(td, MINT_INITLOCALS);
2233+
break;
2234+
}
2235+
}
22312236

22322237
if (rtm->prof_flags & MONO_PROFILER_CALL_INSTRUMENTATION_ENTER)
22332238
ADD_CODE (td, MINT_PROF_ENTER);

0 commit comments

Comments
 (0)