[runtime] MonoError-ize mono_compile_method
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 30 Mar 2016 21:36:47 +0000 (17:36 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Mon, 16 May 2016 23:10:54 +0000 (19:10 -0400)
Mark it external only.  Runtime should use mono_compile_method_checked.

12 files changed:
mono/metadata/cominterop.c
mono/metadata/gc.c
mono/metadata/icall.c
mono/metadata/marshal.c
mono/metadata/object-internals.h
mono/metadata/object.c
mono/metadata/object.h
mono/metadata/remoting.c
mono/mini/jit-icalls.c
mono/mini/mini-generic-sharing.c
mono/mini/mini-runtime.c
mono/mini/mini.c

index 8b4143b7ac5d34cb9805cea47c685e8838d2a4ce..d500fb626ce2a66029d2687aa1ffbd3888ed6f88 100644 (file)
@@ -2115,12 +2115,14 @@ cominterop_get_ccw_checked (MonoObject* object, MonoClass* itf, MonoError *error
                        wrapper_method = mono_mb_create_method (mb, m.csig, m.csig->param_count + 16);
                        mono_cominterop_unlock ();
 
-                       vtable [vtable_index--] = mono_compile_method (wrapper_method);
+                       vtable [vtable_index--] = mono_compile_method_checked (wrapper_method, error);
 
+                       // cleanup, then error out if compile_method failed
                        for (param_index = sig_adjusted->param_count; param_index >= 0; param_index--)
                                if (mspecs [param_index])
                                        mono_metadata_free_marshal_spec (mspecs [param_index]);
                        g_free (mspecs);
+                       return_val_if_nok (error, NULL);
                }
 
                ccw_entry = g_new0 (MonoCCWInterface, 1);
index 6050c0dc4b727581e0ba3dd751c25b15f7421de4..51b9306fc67c984693ab0f09f7a2499ef55ca3a6 100644 (file)
@@ -244,7 +244,8 @@ mono_gc_run_finalize (void *obj, void *data)
        if (!domain->finalize_runtime_invoke) {
                MonoMethod *invoke = mono_marshal_get_runtime_invoke (mono_class_get_method_from_name_flags (mono_defaults.object_class, "Finalize", 0, 0), TRUE);
 
-               domain->finalize_runtime_invoke = mono_compile_method (invoke);
+               domain->finalize_runtime_invoke = mono_compile_method_checked (invoke, &error);
+               mono_error_assert_ok (&error); /* expect this not to fail */
        }
 
        runtime_invoke = (RuntimeInvokeFunction)domain->finalize_runtime_invoke;
index 81ffe98fa2649b334cde41b997ac26ebcae23884..3a47c3286ee772462fe9bb2714535c84f47f6f14 100644 (file)
@@ -6559,7 +6559,9 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
 
        if (method_is_dynamic (method)) {
                /* Creating a trampoline would leak memory */
-               func = mono_compile_method (method);
+               func = mono_compile_method_checked (method, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return NULL;
        } else {
                if (target && method->flags & METHOD_ATTRIBUTE_VIRTUAL && method->klass != mono_object_class (target))
                        method = mono_object_get_virtual_method (target, method);
@@ -7489,7 +7491,10 @@ ves_icall_System_IO_DriveInfo_GetDriveType (MonoString *root_path_name)
 ICALL_EXPORT gpointer
 ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method)
 {
-       return mono_compile_method (method);
+       MonoError error;
+       gpointer result = mono_compile_method_checked (method, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoString *
index 4d7f6cb95a1069c95ce4ad51e24fddfc9f19cece..3ef72af387fa55637032d48c9cb68254bc785a7e 100644 (file)
@@ -86,6 +86,9 @@ static MonoFtnPtrEHCallback ftnptr_eh_callback = ftnptr_eh_callback_default;
 static void
 delegate_hash_table_add (MonoDelegate *d);
 
+static void
+delegate_hash_table_remove (MonoDelegate *d);
+
 static void
 emit_struct_conv (MonoMethodBuilder *mb, MonoClass *klass, gboolean to_object);
 
@@ -314,7 +317,6 @@ mono_marshal_init (void)
                register_icall (mono_struct_delete_old, "mono_struct_delete_old", "void ptr ptr", FALSE);
                register_icall (mono_delegate_begin_invoke, "mono_delegate_begin_invoke", "object object ptr", FALSE);
                register_icall (mono_delegate_end_invoke, "mono_delegate_end_invoke", "object object ptr", FALSE);
-               register_icall (mono_compile_method, "mono_compile_method", "ptr ptr", FALSE);
                register_icall (mono_context_get, "mono_context_get", "object", FALSE);
                register_icall (mono_context_set, "mono_context_set", "void object", FALSE);
                register_icall (mono_gc_wbarrier_generic_nostore, "wb_generic", "void ptr", FALSE);
@@ -395,19 +397,26 @@ mono_delegate_to_ftnptr (MonoDelegate *delegate)
 
        wrapper = mono_marshal_get_managed_wrapper (method, klass, target_handle);
 
-       delegate->delegate_trampoline = mono_compile_method (wrapper);
+       delegate->delegate_trampoline = mono_compile_method_checked (wrapper, &error);
+       if (!is_ok (&error))
+               goto fail;
 
        // Add the delegate to the delegate hash table
        delegate_hash_table_add (delegate);
 
        /* when the object is collected, collect the dynamic method, too */
        mono_object_register_finalizer ((MonoObject*)delegate, &error);
-       if (!mono_error_ok (&error)) {
-               mono_error_set_pending_exception (&error);
-               return NULL;
-       }
+       if (!is_ok (&error))
+               goto fail2;
 
        return delegate->delegate_trampoline;
+
+fail2:
+       delegate_hash_table_remove (delegate);
+fail:
+       mono_gchandle_free (target_handle);
+       mono_error_set_pending_exception (&error);
+       return NULL;
 }
 
 /* 
@@ -572,7 +581,10 @@ mono_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
                        mono_error_set_pending_exception (&error);
                        return NULL;
                }
-               mono_delegate_ctor_with_method ((MonoObject*)d, this_obj, mono_compile_method (wrapper), wrapper);
+               gpointer compiled_ptr = mono_compile_method_checked (wrapper, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return NULL;
+               mono_delegate_ctor_with_method ((MonoObject*)d, this_obj, compiled_ptr, wrapper);
        }
 
        if (d->object.vtable->domain != mono_domain_get ()) {
@@ -8501,7 +8513,9 @@ mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type)
                                mono_metadata_free_marshal_spec (mspecs [i]);
                g_free (mspecs);
 
-               return mono_compile_method (method);
+               gpointer compiled_ptr = mono_compile_method_checked (method, &error);
+               mono_error_assert_ok (&error);
+               return compiled_ptr;
        }
 
        sig = mono_method_signature (method);
@@ -8524,7 +8538,9 @@ mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type)
        method = mono_mb_create (mb, sig, param_count, NULL);
        mono_mb_free (mb);
 
-       return mono_compile_method (method);
+       gpointer compiled_ptr = mono_compile_method_checked (method, &error);
+       mono_error_assert_ok (&error);
+       return compiled_ptr;
 }
 
 #ifndef DISABLE_JIT
index 13ad74572d2c42353517dde92c1966c158649661..2587d877e642b6d6bb6a204bc8fe65f4104c7492 100644 (file)
@@ -1706,6 +1706,8 @@ mono_runtime_try_invoke (MonoMethod *method, void *obj, void **params, MonoObjec
 MonoObject*
 mono_runtime_invoke_checked (MonoMethod *method, void *obj, void **params, MonoError *error);
 
+void* 
+mono_compile_method_checked (MonoMethod *method, MonoError *error);
 
 MonoArray*
 mono_runtime_get_main_args_checked (MonoError *error);
index fa68faab7123b38defc9d0daa800c10e23ad4dbc..9cd1ae22152b903057256a1132ea38110b254b65 100644 (file)
@@ -612,18 +612,34 @@ mono_set_always_build_imt_thunks (gboolean value)
 gpointer 
 mono_compile_method (MonoMethod *method)
 {
-       gpointer res;
        MonoError error;
+       gpointer result = mono_compile_method_checked (method, &error);
+       mono_error_cleanup (&error);
+       return result;
+}
+
+/**
+ * mono_compile_method:
+ * @method: The method to compile.
+ * @error: set on error.
+ *
+ * This JIT-compiles the method, and returns the pointer to the native code
+ * produced.  On failure returns NULL and sets @error.
+ */
+gpointer
+mono_compile_method_checked (MonoMethod *method, MonoError *error)
+{
+       gpointer res;
 
        MONO_REQ_GC_NEUTRAL_MODE
 
+       mono_error_init (error);
+
        if (!callbacks.compile_method) {
                g_error ("compile method called on uninitialized runtime");
                return NULL;
        }
-       res = callbacks.compile_method (method, &error);
-       if (!mono_error_ok (&error))
-               mono_error_raise_exception (&error);
+       res = callbacks.compile_method (method, error);
        return res;
 }
 
@@ -3113,13 +3129,15 @@ mono_method_get_unmanaged_thunk (MonoMethod *method)
        MONO_REQ_GC_NEUTRAL_MODE;
        MONO_REQ_API_ENTRYPOINT;
 
+       MonoError error;
        gpointer res;
 
        g_assert (!mono_threads_is_coop_enabled ());
 
        MONO_ENTER_GC_UNSAFE;
        method = mono_marshal_get_thunk_invoke_wrapper (method);
-       res = mono_compile_method (method);
+       res = mono_compile_method_checked (method, &error);
+       mono_error_cleanup (&error);
        MONO_EXIT_GC_UNSAFE;
 
        return res;
@@ -7011,20 +7029,24 @@ mono_wait_handle_get_handle (MonoWaitHandle *handle)
 
 
 static MonoObject*
-mono_runtime_capture_context (MonoDomain *domain)
+mono_runtime_capture_context (MonoDomain *domain, MonoError *error)
 {
        MONO_REQ_GC_UNSAFE_MODE;
 
        RuntimeInvokeFunction runtime_invoke;
 
+       mono_error_init (error);
+
        if (!domain->capture_context_runtime_invoke || !domain->capture_context_method) {
                MonoMethod *method = mono_get_context_capture_method ();
                MonoMethod *wrapper;
                if (!method)
                        return NULL;
                wrapper = mono_marshal_get_runtime_invoke (method, FALSE);
-               domain->capture_context_runtime_invoke = mono_compile_method (wrapper);
-               domain->capture_context_method = mono_compile_method (method);
+               domain->capture_context_runtime_invoke = mono_compile_method_checked (wrapper, error);
+               return_val_if_nok (error, NULL);
+               domain->capture_context_method = mono_compile_method_checked (method, error);
+               return_val_if_nok (error, NULL);
        }
 
        runtime_invoke = (RuntimeInvokeFunction)domain->capture_context_runtime_invoke;
@@ -7050,7 +7072,8 @@ mono_async_result_new (MonoDomain *domain, HANDLE handle, MonoObject *state, gpo
        MonoError error;
        MonoAsyncResult *res = (MonoAsyncResult *)mono_object_new_checked (domain, mono_defaults.asyncresult_class, &error);
        mono_error_raise_exception (&error); /* FIXME don't raise here */
-       MonoObject *context = mono_runtime_capture_context (domain);
+       MonoObject *context = mono_runtime_capture_context (domain, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
        /* we must capture the execution context from the original thread */
        if (context) {
                MONO_OBJECT_SETREF (res, execution_context, context);
@@ -7438,6 +7461,7 @@ mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpoint
 {
        MONO_REQ_GC_UNSAFE_MODE;
 
+       MonoError error;
        MonoDelegate *delegate = (MonoDelegate *)this_obj;
 
        g_assert (this_obj);
@@ -7454,7 +7478,8 @@ mono_delegate_ctor_with_method (MonoObject *this_obj, MonoObject *target, gpoint
        if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
                g_assert (method);
                method = mono_marshal_get_remoting_invoke (method);
-               delegate->method_ptr = mono_compile_method (method);
+               delegate->method_ptr = mono_compile_method_checked (method, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
                MONO_OBJECT_SETREF (delegate, target, target);
        } else
 #endif
index 52b6b079aa2eafb7efe8178f61f18d79c1aa537e..bf23c26c61a1d1d0da6583be1b80e018799fedbd 100644 (file)
@@ -311,6 +311,7 @@ mono_unhandled_exception    (MonoObject *exc);
 MONO_API void
 mono_print_unhandled_exception (MonoObject *exc);
 
+MONO_RT_EXTERNAL_ONLY
 MONO_API void* 
 mono_compile_method       (MonoMethod *method);
 
index 2b1a9d6b1949a31bf130d234779c79b43eee4102..8a8b22676ed1301f5217958956ee6062337ce4e1 100644 (file)
@@ -81,6 +81,9 @@ static MonoMethod *method_rs_serialize, *method_rs_deserialize, *method_exc_fixe
 static MonoMethod *method_set_call_context, *method_needs_context_sink, *method_rs_serialize_exc;
 #endif
 
+static gpointer
+mono_compile_method_icall (MonoMethod *method);
+
 static void
 register_icall (gpointer func, const char *name, const char *sigstr, gboolean save)
 {
@@ -194,6 +197,7 @@ mono_remoting_marshal_init (void)
                register_icall (mono_marshal_xdomain_copy_out_value, "mono_marshal_xdomain_copy_out_value", "void object object", FALSE);
                register_icall (mono_remoting_wrapper, "mono_remoting_wrapper", "object ptr ptr", FALSE);
                register_icall (mono_upgrade_remote_class_wrapper, "mono_upgrade_remote_class_wrapper", "void object object", FALSE);
+               register_icall (mono_compile_method_icall, "mono_compile_method_icall", "ptr ptr", FALSE);
                /* mono_load_remote_field_new_icall registered  by mini-runtime.c */
                /* mono_store_remote_field_new_icall registered  by mini-runtime.c */
 
@@ -579,6 +583,15 @@ mono_marshal_emit_switch_domain (MonoMethodBuilder *mb)
        mono_mb_emit_icall (mb, mono_marshal_set_domain_by_id);
 }
 
+gpointer
+mono_compile_method_icall (MonoMethod *method)
+{
+       MonoError error;
+       gpointer result = mono_compile_method_checked (method, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
+}
+
 /* mono_marshal_emit_load_domain_method ()
  * Loads into the stack a pointer to the code of the provided method for
  * the current domain.
@@ -590,7 +603,7 @@ mono_marshal_emit_load_domain_method (MonoMethodBuilder *mb, MonoMethod *method)
         * that compiles the method).
         */
        mono_mb_emit_ptr (mb, method);
-       mono_mb_emit_icall (mb, mono_compile_method);
+       mono_mb_emit_icall (mb, mono_compile_method_icall);
 }
 #endif
 
@@ -1233,10 +1246,15 @@ mono_marshal_get_remoting_invoke_for_target (MonoMethod *method, MonoRemotingTar
 G_GNUC_UNUSED static gpointer
 mono_marshal_load_remoting_wrapper (MonoRealProxy *rp, MonoMethod *method)
 {
+       MonoError error;
+       MonoMethod *marshal_method = NULL;
        if (rp->target_domain_id != -1)
-               return mono_compile_method (mono_marshal_get_xappdomain_invoke (method));
+               marshal_method = mono_marshal_get_xappdomain_invoke (method);
        else
-               return mono_compile_method (mono_marshal_get_remoting_invoke (method));
+               marshal_method = mono_marshal_get_remoting_invoke (method);
+       gpointer compiled_ptr = mono_compile_method_checked (marshal_method, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
+       return compiled_ptr;
 }
 
 MonoMethod *
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);
index 3b55b58689c3eec7ce46bff99fe168499a063582..e778f7561ff100d127adfcd475e76a941fda020b 100644 (file)
@@ -936,9 +936,10 @@ class_type_info (MonoDomain *domain, MonoClass *klass, MonoRgctxInfoType info_ty
                                memcpy_method [size] = m;
                        }
                        if (!domain_info->memcpy_addr [size]) {
-                               gpointer addr = mono_compile_method (memcpy_method [size]);
+                               gpointer addr = mono_compile_method_checked (memcpy_method [size], error);
                                mono_memory_barrier ();
                                domain_info->memcpy_addr [size] = (gpointer *)addr;
+                               mono_error_assert_ok (error);
                        }
                        return domain_info->memcpy_addr [size];
                } else {
@@ -956,9 +957,10 @@ class_type_info (MonoDomain *domain, MonoClass *klass, MonoRgctxInfoType info_ty
                                bzero_method [size] = m;
                        }
                        if (!domain_info->bzero_addr [size]) {
-                               gpointer addr = mono_compile_method (bzero_method [size]);
+                               gpointer addr = mono_compile_method_checked (bzero_method [size], error);
                                mono_memory_barrier ();
                                domain_info->bzero_addr [size] = (gpointer *)addr;
+                               mono_error_assert_ok (error);
                        }
                        return domain_info->bzero_addr [size];
                }
@@ -1418,6 +1420,7 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign
 {
        static gboolean inited = FALSE;
        static int num_trampolines;
+       MonoError error;
        gpointer res, info;
        MonoDomain *domain = mono_domain_get ();
        MonoJitDomainInfo *domain_info;
@@ -1436,7 +1439,8 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign
                        wrapper = mini_get_gsharedvt_in_sig_wrapper (normal_sig);
                else
                        wrapper = mini_get_gsharedvt_out_sig_wrapper (normal_sig);
-               res = mono_compile_method (wrapper);
+               res = mono_compile_method_checked (wrapper, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
                return res;
        }
 
@@ -1469,8 +1473,9 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign
 
                if (!tramp_addr) {
                        wrapper = mono_marshal_get_gsharedvt_in_wrapper ();
-                       addr = mono_compile_method (wrapper);
+                       addr = mono_compile_method_checked (wrapper, &error);
                        mono_memory_barrier ();
+                       mono_error_assert_ok (&error);
                        tramp_addr = addr;
                }
                addr = tramp_addr;
@@ -1480,8 +1485,9 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign
 
                if (!tramp_addr) {
                        wrapper = mono_marshal_get_gsharedvt_out_wrapper ();
-                       addr = mono_compile_method (wrapper);
+                       addr = mono_compile_method_checked (wrapper, &error);
                        mono_memory_barrier ();
+                       mono_error_assert_ok (&error);
                        tramp_addr = addr;
                }
                addr = tramp_addr;
@@ -1578,13 +1584,15 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
                gpointer arg = NULL;
 
                if (mono_llvm_only) {
-                       addr = mono_compile_method (m);
+                       addr = mono_compile_method_checked (m, error);
+                       return_val_if_nok (error, NULL);
                        addr = mini_add_method_wrappers_llvmonly (m, addr, FALSE, FALSE, &arg);
 
                        /* Returns an ftndesc */
                        return mini_create_llvmonly_ftndesc (domain, addr, arg);
                } else {
-                       addr = mono_compile_method ((MonoMethod *)data);
+                       addr = mono_compile_method_checked ((MonoMethod *)data, error);
+                       return_val_if_nok (error, NULL);
                        return mini_add_method_trampoline ((MonoMethod *)data, addr, mono_method_needs_static_rgctx_invoke ((MonoMethod *)data, FALSE), FALSE);
                }
        }
@@ -1595,7 +1603,8 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
 
                g_assert (mono_llvm_only);
 
-               addr = mono_compile_method (m);
+               addr = mono_compile_method_checked (m, error);
+               return_val_if_nok (error, NULL);
 
                MonoJitInfo *ji;
                gboolean callee_gsharedvt;
@@ -1636,9 +1645,9 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
                method = info->klass->vtable [ioffset + slot];
 
                method = mono_class_inflate_generic_method_checked (method, context, error);
-               if (!mono_error_ok (error))
-                       return NULL;
-               addr = mono_compile_method (method);
+               return_val_if_nok (error, NULL);
+               addr = mono_compile_method_checked (method, error);
+               return_val_if_nok (error, NULL);
                return mini_add_method_trampoline (method, addr, mono_method_needs_static_rgctx_invoke (method, FALSE), FALSE);
        }
        case MONO_RGCTX_INFO_VIRT_METHOD_BOX_TYPE: {
@@ -1671,7 +1680,7 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
        }
 #ifndef DISABLE_REMOTING
        case MONO_RGCTX_INFO_REMOTING_INVOKE_WITH_CHECK:
-               return mono_compile_method (mono_marshal_get_remoting_invoke_with_check ((MonoMethod *)data));
+               return mono_compile_method_checked (mono_marshal_get_remoting_invoke_with_check ((MonoMethod *)data), error);
 #endif
        case MONO_RGCTX_INFO_METHOD_DELEGATE_CODE:
                return mono_domain_alloc0 (domain, sizeof (gpointer));
@@ -1749,9 +1758,10 @@ instantiate_info (MonoDomain *domain, MonoRuntimeGenericContextInfoTemplate *oti
 
                g_assert (method->is_inflated);
 
-               if (!virtual_)
-                       addr = mono_compile_method (method);
-               else
+               if (!virtual_) {
+                       addr = mono_compile_method_checked (method, error);
+                       return_val_if_nok (error, NULL);
+               } else
                        addr = NULL;
 
                if (virtual_) {
index ac123365f90fd3e8dd1a0c02f624c89502c41e99..8e909b1cbc9fe26d1183d9f86e4a69ccaa936380 100644 (file)
@@ -616,6 +616,7 @@ mono_debug_count (void)
 gconstpointer
 mono_icall_get_wrapper_full (MonoJitICallInfo* callinfo, gboolean do_compile)
 {
+       MonoError error;
        char *name;
        MonoMethod *wrapper;
        gconstpointer trampoline;
@@ -637,9 +638,9 @@ mono_icall_get_wrapper_full (MonoJitICallInfo* callinfo, gboolean do_compile)
        g_free (name);
 
        if (do_compile) {
-               trampoline = mono_compile_method (wrapper);
+               trampoline = mono_compile_method_checked (wrapper, &error);
+               mono_error_assert_ok (&error);
        } else {
-               MonoError error;
 
                trampoline = mono_create_jit_trampoline (domain, wrapper, &error);
                mono_error_assert_ok (&error);
@@ -3031,6 +3032,7 @@ MONO_SIG_HANDLER_FUNC (, mono_sigint_signal_handler)
 static gpointer
 mono_jit_create_remoting_trampoline (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target)
 {
+       MonoError error;
        MonoMethod *nm;
        guint8 *addr = NULL;
 
@@ -3042,10 +3044,12 @@ mono_jit_create_remoting_trampoline (MonoDomain *domain, MonoMethod *method, Mon
        if ((method->flags & METHOD_ATTRIBUTE_ABSTRACT) ||
            (mono_method_signature (method)->hasthis && (mono_class_is_marshalbyref (method->klass) || method->klass == mono_defaults.object_class))) {
                nm = mono_marshal_get_remoting_invoke_for_target (method, target);
-               addr = (guint8 *)mono_compile_method (nm);
+               addr = (guint8 *)mono_compile_method_checked (nm, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
        } else
        {
-               addr = (guint8 *)mono_compile_method (method);
+               addr = (guint8 *)mono_compile_method_checked (method, &error);
+               mono_error_raise_exception (&error); /* FIXME don't raise here */
        }
        return mono_get_addr_from_ftnptr (addr);
 }
@@ -4308,15 +4312,21 @@ mono_precompile_assembly (MonoAssembly *ass, void *user_data)
                        g_print ("Compiling %d %s\n", count, desc);
                        g_free (desc);
                }
-               mono_compile_method (method);
+               mono_compile_method_checked (method, &error);
+               if (!is_ok (&error)) {
+                       mono_error_cleanup (&error); /* FIXME don't swallow the error */
+                       continue;
+               }
                if (strcmp (method->name, "Finalize") == 0) {
                        invoke = mono_marshal_get_runtime_invoke (method, FALSE);
-                       mono_compile_method (invoke);
+                       mono_compile_method_checked (invoke, &error);
+                       mono_error_assert_ok (&error);
                }
 #ifndef DISABLE_REMOTING
                if (mono_class_is_marshalbyref (method->klass) && mono_method_signature (method)->hasthis) {
                        invoke = mono_marshal_get_remoting_invoke_with_check (method);
-                       mono_compile_method (invoke);
+                       mono_compile_method_checked (invoke, &error);
+                       mono_error_assert_ok (&error);
                }
 #endif
        }
index 76adac07895b888867a6e4dd680952b838894803..9bb50e93302e010f63c3f7bd77b69f07dd125414 100644 (file)
@@ -4216,7 +4216,9 @@ mono_jit_compile_method_inner (MonoMethod *method, MonoDomain *target_domain, in
                                mono_lookup_pinvoke_call (method, NULL, NULL);
                }
                nm = mono_marshal_get_native_wrapper (method, TRUE, mono_aot_only);
-               code = mono_get_addr_from_ftnptr (mono_compile_method (nm));
+               gpointer compiled_method = mono_compile_method_checked (nm, error);
+               return_val_if_nok (error, NULL);
+               code = mono_get_addr_from_ftnptr (compiled_method);
                jinfo = mono_jit_info_table_find (target_domain, (char *)code);
                if (!jinfo)
                        jinfo = mono_jit_info_table_find (mono_domain_get (), (char *)code);
@@ -4246,15 +4248,21 @@ mono_jit_compile_method_inner (MonoMethod *method, MonoDomain *target_domain, in
                        } else if (*name == 'I' && (strcmp (name, "Invoke") == 0)) {
                                if (mono_llvm_only) {
                                        nm = mono_marshal_get_delegate_invoke (method, NULL);
-                                       return mono_get_addr_from_ftnptr (mono_compile_method (nm));
+                                       gpointer compiled_ptr = mono_compile_method_checked (nm, error);
+                                       mono_error_assert_ok (error);
+                                       return mono_get_addr_from_ftnptr (compiled_ptr);
                                }
                                return mono_create_delegate_trampoline (target_domain, method->klass);
                        } else if (*name == 'B' && (strcmp (name, "BeginInvoke") == 0)) {
                                nm = mono_marshal_get_delegate_begin_invoke (method);
-                               return mono_get_addr_from_ftnptr (mono_compile_method (nm));
+                               gpointer compiled_ptr = mono_compile_method_checked (nm, error);
+                               mono_error_assert_ok (error);
+                               return mono_get_addr_from_ftnptr (compiled_ptr);
                        } else if (*name == 'E' && (strcmp (name, "EndInvoke") == 0)) {
                                nm = mono_marshal_get_delegate_end_invoke (method);
-                               return mono_get_addr_from_ftnptr (mono_compile_method (nm));
+                               gpointer compiled_ptr = mono_compile_method_checked (nm, error);
+                               mono_error_assert_ok (error);
+                               return mono_get_addr_from_ftnptr (compiled_ptr);
                        }
                }