[runtime] MonoError-ize mono_compile_method
[mono.git] / mono / mini / jit-icalls.c
index 6d87c74e92d01e1fb087a6f8c19e57dc65084c08..13946834eec730ed76672cb91de14c153256a494 100644 (file)
@@ -35,7 +35,8 @@ mono_ldftn (MonoMethod *method)
        if (mono_llvm_only) {
                // FIXME: No error handling
 
-               addr = mono_compile_method (method);
+               addr = mono_compile_method_checked (method, &error);
+               mono_error_assert_ok (&error);
                g_assert (addr);
 
                if (mono_method_needs_static_rgctx_invoke (method, FALSE))
@@ -1094,6 +1095,7 @@ mono_fmod(double a, double b)
 gpointer
 mono_helper_compile_generic_method (MonoObject *obj, MonoMethod *method, gpointer *this_arg)
 {
+       MonoError error;
        MonoMethod *vmethod;
        gpointer addr;
        MonoGenericContext *context = mono_method_get_context (method);
@@ -1109,7 +1111,9 @@ mono_helper_compile_generic_method (MonoObject *obj, MonoMethod *method, gpointe
        g_assert (!vmethod->klass->generic_class || !vmethod->klass->generic_class->context.class_inst->is_open);
        g_assert (!context->method_inst || !context->method_inst->is_open);
 
-       addr = mono_compile_method (vmethod);
+       addr = mono_compile_method_checked (vmethod, &error);
+       if (mono_error_set_pending_exception (&error))
+               return NULL;
 
        addr = mini_add_method_trampoline (vmethod, addr, mono_method_needs_static_rgctx_invoke (vmethod, FALSE), FALSE);
 
@@ -1283,6 +1287,7 @@ mono_object_isinst_with_cache (MonoObject *obj, MonoClass *klass, gpointer *cach
 gpointer
 mono_get_native_calli_wrapper (MonoImage *image, MonoMethodSignature *sig, gpointer func)
 {
+       MonoError error;
        MonoMarshalSpec **mspecs;
        MonoMethodPInvoke piinfo;
        MonoMethod *m;
@@ -1292,7 +1297,9 @@ mono_get_native_calli_wrapper (MonoImage *image, MonoMethodSignature *sig, gpoin
 
        m = mono_marshal_get_native_func_wrapper (image, sig, &piinfo, mspecs, func);
 
-       return mono_compile_method (m);
+       gpointer compiled_ptr = mono_compile_method_checked (m, &error);
+       mono_error_set_pending_exception (&error);
+       return compiled_ptr;
 }
 
 static MonoMethod*
@@ -1459,6 +1466,7 @@ mono_fill_method_rgctx (MonoMethodRuntimeGenericContext *mrgctx, int index)
 static gpointer
 resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method, gpointer *out_arg, gboolean caller_gsharedvt)
 {
+       MonoError error;
        MonoVTable *vt;
        gpointer *imt, *vtable_slot;
        MonoMethod *impl_method, *generic_virtual = NULL, *variant_iface = NULL;
@@ -1475,7 +1483,8 @@ resolve_iface_call (MonoObject *this_obj, int imt_slot, MonoMethod *imt_method,
        vtable_slot = mini_resolve_imt_method (vt, imt + imt_slot, imt_method, &impl_method, &aot_addr, &need_rgctx_tramp, &variant_iface);
 
        // FIXME: This can throw exceptions
-       addr = compiled_method = mono_compile_method (impl_method);
+       addr = compiled_method = mono_compile_method_checked (impl_method, &error);
+       mono_error_assert_ok (&error);
        g_assert (addr);
 
        if (imt_method->is_inflated && ((MonoMethodInflated*)imt_method)->context.method_inst)
@@ -1536,6 +1545,7 @@ is_generic_method_definition (MonoMethod *m)
 static gpointer
 resolve_vcall (MonoVTable *vt, int slot, MonoMethod *imt_method, gpointer *out_arg, gboolean gsharedvt)
 {
+       MonoError error;
        MonoMethod *m, *generic_virtual = NULL;
        gpointer addr, compiled_method;
        gboolean need_unbox_tramp = FALSE;
@@ -1550,7 +1560,6 @@ resolve_vcall (MonoVTable *vt, int slot, MonoMethod *imt_method, gpointer *out_a
        m = mono_class_get_vtable_entry (vt->klass, slot);
 
        if (is_generic_method_definition (m)) {
-               MonoError error;
                MonoGenericContext context = { NULL, NULL };
                MonoMethod *declaring;
 
@@ -1570,7 +1579,7 @@ resolve_vcall (MonoVTable *vt, int slot, MonoMethod *imt_method, gpointer *out_a
                context.method_inst = ((MonoMethodInflated*)generic_virtual)->context.method_inst;
 
                m = mono_class_inflate_generic_method_checked (declaring, &context, &error);
-               g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
        }
 
        if (generic_virtual) {
@@ -1582,7 +1591,8 @@ resolve_vcall (MonoVTable *vt, int slot, MonoMethod *imt_method, gpointer *out_a
        }
 
        // FIXME: This can throw exceptions
-       addr = compiled_method = mono_compile_method (m);
+       addr = compiled_method = mono_compile_method_checked (m, &error);
+       mono_error_assert_ok (&error);
        g_assert (addr);
 
        addr = mini_add_method_wrappers_llvmonly (m, addr, gsharedvt, need_unbox_tramp, out_arg);
@@ -1648,7 +1658,8 @@ mono_resolve_generic_virtual_call (MonoVTable *vt, int slot, MonoMethod *generic
                need_unbox_tramp = TRUE;
 
        // FIXME: This can throw exceptions
-       addr = compiled_method = mono_compile_method (m);
+       addr = compiled_method = mono_compile_method_checked (m, &error);
+       mono_error_assert_ok (&error);
        g_assert (addr);
 
        addr = mini_add_method_wrappers_llvmonly (m, addr, FALSE, need_unbox_tramp, &arg);
@@ -1675,6 +1686,7 @@ mono_resolve_generic_virtual_call (MonoVTable *vt, int slot, MonoMethod *generic
 MonoFtnDesc*
 mono_resolve_generic_virtual_iface_call (MonoVTable *vt, int imt_slot, MonoMethod *generic_virtual)
 {
+       MonoError error;
        MonoMethod *m, *variant_iface;
        gpointer addr, aot_addr, compiled_method;
        gboolean need_unbox_tramp = FALSE;
@@ -1690,7 +1702,8 @@ mono_resolve_generic_virtual_iface_call (MonoVTable *vt, int imt_slot, MonoMetho
                need_unbox_tramp = TRUE;
 
        // FIXME: This can throw exceptions
-       addr = compiled_method = mono_compile_method (m);
+       addr = compiled_method = mono_compile_method_checked (m, &error);
+       mono_error_assert_ok (&error);
        g_assert (addr);
 
        addr = mini_add_method_wrappers_llvmonly (m, addr, FALSE, need_unbox_tramp, &arg);
@@ -1741,6 +1754,7 @@ mono_init_vtable_slot (MonoVTable *vtable, int slot)
 void
 mono_llvmonly_init_delegate (MonoDelegate *del)
 {
+       MonoError error;
        MonoFtnDesc *ftndesc = *(MonoFtnDesc**)del->method_code;
 
        /*
@@ -1749,7 +1763,9 @@ mono_llvmonly_init_delegate (MonoDelegate *del)
         * but we don't have a a structure which could own its memory.
         */
        if (G_UNLIKELY (!ftndesc)) {
-               gpointer addr = mono_compile_method (del->method);
+               gpointer addr = mono_compile_method_checked (del->method, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return;
 
                if (del->method->klass->valuetype && mono_method_signature (del->method)->hasthis)
                    addr = mono_aot_get_unbox_trampoline (del->method);
@@ -1767,12 +1783,16 @@ mono_llvmonly_init_delegate (MonoDelegate *del)
 void
 mono_llvmonly_init_delegate_virtual (MonoDelegate *del, MonoObject *target, MonoMethod *method)
 {
+       MonoError error;
+
        g_assert (target);
 
        method = mono_object_get_virtual_method (target, method);
 
        del->method = method;
-       del->method_ptr = mono_compile_method (method);
+       del->method_ptr = mono_compile_method_checked (method, &error);
+       if (mono_error_set_pending_exception (&error))
+               return;
        if (method->klass->valuetype)
                del->method_ptr = mono_aot_get_unbox_trampoline (method);
        del->extra_arg = mini_get_delegate_arg (del->method, del->method_ptr);