[interp][wasm] Remove more varargs to conserve stack. (mono/mono#17388)
authorJay Krell <jaykrell@microsoft.com>
Fri, 18 Oct 2019 07:39:05 +0000 (00:39 -0700)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 18 Oct 2019 07:39:05 +0000 (10:39 +0300)
Commit migrated from https://github.com/mono/mono/commit/958b9b2658f6d866ba451781cfa2180e2b340f35

src/mono/mono/mini/interp/interp.c

index 6b7f9a1..5447e4d 100644 (file)
@@ -3198,6 +3198,27 @@ mono_interp_call (InterpFrame *frame, ThreadContext *context, InterpFrame *child
        return sp;
 }
 
+// varargs in wasm consumes extra linear stack per call-site.
+// These g_warning/g_error wrappers fix that. It is not the
+// small wasm stack, but conserving it is still desirable.
+static void
+g_warning_d (const char *format, int d)
+{
+       g_warning (format, d);
+}
+
+static void
+g_warning_ds (const char *format, int d, const char *s)
+{
+       g_warning (format, d, s);
+}
+
+static void
+g_error_xsx (const char *format, int x1, const char *s, int x2)
+{
+       g_error (format, x1, s, x2);
+}
+
 /*
  * 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.
@@ -3659,18 +3680,18 @@ common_vcall:
                        --sp;
                        *frame->retval = *sp;
                        if (sp > frame->stack)
-                               g_warning ("ret: more values on stack: %d", sp-frame->stack);
+                               g_warning_d ("ret: more values on stack: %d", sp -frame->stack);
                        goto exit_frame;
                MINT_IN_CASE(MINT_RET_VOID)
                        if (sp > frame->stack)
-                               g_warning ("ret.void: more values on stack: %d %s", sp-frame->stack, mono_method_full_name (frame->imethod->method, TRUE));
+                               g_warning_ds ("ret.void: more values on stack: %d %s", sp - frame->stack, mono_method_full_name (frame->imethod->method, TRUE));
                        goto exit_frame;
                MINT_IN_CASE(MINT_RET_VT) {
                        int const i32 = READ32 (ip + 1);
                        --sp;
                        memcpy(frame->retval->data.p, sp->data.p, i32);
                        if (sp > frame->stack)
-                               g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
+                               g_warning_d ("ret.vt: more values on stack: %d", sp - frame->stack);
                        goto exit_frame;
                }
                MINT_IN_CASE(MINT_BR_S)
@@ -5953,7 +5974,7 @@ common_vcall:
                        stackval_from_data (mono_method_signature_internal (frame->imethod->method)->ret, frame->retval, sp->data.p,
                             mono_method_signature_internal (frame->imethod->method)->pinvoke);
                        if (sp > frame->stack)
-                               g_warning ("retobj: more values on stack: %d", sp-frame->stack);
+                               g_warning_d ("retobj: more values on stack: %d", sp - frame->stack);
                        goto exit_frame;
                MINT_IN_CASE(MINT_MONO_SGEN_THREAD_INFO)
                        sp->data.p = mono_tls_get_sgen_thread_info ();
@@ -6536,7 +6557,7 @@ common_vcall:
 
 #if !USE_COMPUTED_GOTO
                default:
-                       g_error ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname (*ip), ip - frame->imethod->code);
+                       g_error_xsx ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname (*ip), ip - frame->imethod->code);
 #endif
                }
        }