[jit] Convert some of the error handling to use cfg->error instead of cfg->exception_...
authorZoltan Varga <vargaz@gmail.com>
Wed, 27 Jan 2016 21:01:41 +0000 (16:01 -0500)
committerZoltan Varga <vargaz@gmail.com>
Wed, 27 Jan 2016 21:01:41 +0000 (16:01 -0500)
mono/mini/decompose.c
mono/mini/method-to-ir.c
mono/mini/mini-amd64.c
mono/mini/mini-x86.c
mono/mini/mini.c
mono/mini/mini.h

index ea53056e69531214470fbd73a9eefad910f35dde..d8c46e88c0d87377365817747d1f59495e8790cf 100644 (file)
@@ -439,8 +439,7 @@ mono_decompose_opcode (MonoCompile *cfg, MonoInst *ins)
        case OP_FCONV_TO_OVF_U8_UN:
        case OP_FCONV_TO_OVF_I_UN:
        case OP_FCONV_TO_OVF_U_UN:
-               cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
-               cfg->exception_message = g_strdup_printf ("float conv.ovf.un opcodes not supported.");
+               mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("float conv.ovf.un opcodes not supported."));
                break;
 
        case OP_IDIV:
index 85cf2aca184eed3fd46b15d1f849cc6e6549f4bb..2ff04067b88226719d44f607901d0d9e004cb485 100644 (file)
        }                                                                                                                                       \
        } while (0)
 #define OUT_OF_MEMORY_FAILURE do {     \
-               mono_cfg_set_exception (cfg, MONO_EXCEPTION_OUT_OF_MEMORY);             \
+               mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);                \
+               mono_error_set_out_of_memory (&cfg->error, "");                                 \
                goto exception_exit;    \
        } while (0)
 #define DISABLE_AOT(cfg) do { \
@@ -373,8 +374,8 @@ method_access_failure (MonoCompile *cfg, MonoMethod *method, MonoMethod *cil_met
 {
        char *method_fname = mono_method_full_name (method, TRUE);
        char *cil_method_fname = mono_method_full_name (cil_method, TRUE);
-       mono_cfg_set_exception (cfg, MONO_EXCEPTION_METHOD_ACCESS);
-       cfg->exception_message = g_strdup_printf ("Method `%s' is inaccessible from method `%s'\n", cil_method_fname, method_fname);
+       mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);
+       mono_error_set_generic_error (&cfg->error, "System", "MethodAccessException", "Method `%s' is inaccessible from method `%s'\n", cil_method_fname, method_fname);
        g_free (method_fname);
        g_free (cil_method_fname);
 }
@@ -384,8 +385,8 @@ field_access_failure (MonoCompile *cfg, MonoMethod *method, MonoClassField *fiel
 {
        char *method_fname = mono_method_full_name (method, TRUE);
        char *field_fname = mono_field_full_name (field);
-       mono_cfg_set_exception (cfg, MONO_EXCEPTION_FIELD_ACCESS);
-       cfg->exception_message = g_strdup_printf ("Field `%s' is inaccessible from method `%s'\n", field_fname, method_fname);
+       mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);
+       mono_error_set_generic_error (&cfg->error, "System", "FieldAccessException", "Field `%s' is inaccessible from method `%s'\n", field_fname, method_fname);
        g_free (method_fname);
        g_free (field_fname);
 }
@@ -7601,21 +7602,12 @@ set_exception_type_from_invalid_il (MonoCompile *cfg, MonoMethod *method, unsign
                method_code = g_strdup ("method body is empty.");
        else
                method_code = mono_disasm_code_one (NULL, method, ip, NULL);
-       mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM);
-       cfg->exception_message = g_strdup_printf ("Invalid IL code in %s: %s\n", method_fname, method_code);
+       mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Invalid IL code in %s: %s\n", method_fname, method_code));
        g_free (method_fname);
        g_free (method_code);
        cfg->headers_to_free = g_slist_prepend_mempool (cfg->mempool, cfg->headers_to_free, header);
 }
 
-static void
-set_exception_object (MonoCompile *cfg, MonoException *exception)
-{
-       mono_cfg_set_exception (cfg, MONO_EXCEPTION_OBJECT_SUPPLIED);
-       MONO_GC_REGISTER_ROOT_SINGLE (cfg->exception_ptr, MONO_ROOT_SOURCE_JIT, "jit exception");
-       cfg->exception_ptr = exception;
-}
-
 static void
 emit_stloc_ir (MonoCompile *cfg, MonoInst **sp, MonoMethodHeader *header, int n)
 {
@@ -8165,8 +8157,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                if ((error = mono_loader_get_last_error ())) {
                        mono_cfg_set_exception (cfg, error->exception_type);
                } else {
-                       mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM);
-                       cfg->exception_message = g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name);
+                       mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name));
                }
                goto exception_exit;
        }
@@ -11649,7 +11640,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                                                INLINE_FAILURE ("class init");
                                                        ex = mono_runtime_class_init_full (vtable, FALSE);
                                                        if (ex) {
-                                                               set_exception_object (cfg, ex);
+                                                               mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);
+                                                               mono_error_set_exception_instance (&cfg->error, ex);
+                                                               g_assert_not_reached ();
                                                                goto exception_exit;
                                                        }
                                                }
@@ -13636,8 +13629,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
 
                /* Method is too large */
                mname = mono_method_full_name (method, TRUE);
-               mono_cfg_set_exception (cfg, MONO_EXCEPTION_INVALID_PROGRAM);
-               cfg->exception_message = g_strdup_printf ("Method %s is too complex.", mname);
+               mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s is too complex.", mname));
                g_free (mname);
        }
 
index a97493988ce3e39f80e1a40b7c5b2144df161e38..d37ad6818bfb9c856f29c738c29a8798ddd71fe7 100644 (file)
@@ -1958,8 +1958,7 @@ mono_arch_allocate_vars (MonoCompile *cfg)
        offsets = mono_allocate_stack_slots (cfg, cfg->arch.omit_fp ? FALSE: TRUE, &locals_stack_size, &locals_stack_align);
        if (locals_stack_size > MONO_ARCH_MAX_FRAME_SIZE) {
                char *mname = mono_method_full_name (cfg->method, TRUE);
-               cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
-               cfg->exception_message = g_strdup_printf ("Method %s stack is too big.", mname);
+               mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s stack is too big.", mname));
                g_free (mname);
                return;
        }
@@ -2475,8 +2474,7 @@ mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
 
                        if (size >= 10000) {
                                /* Avoid asserts in emit_memcpy () */
-                               cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
-                               cfg->exception_message = g_strdup_printf ("Passing an argument of size '%d'.", size);
+                               mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Passing an argument of size '%d'.", size));
                                /* Continue normally */
                        }
 
index dfea009165db3619193940062ed2c720a88ebf9b..03e2eca527228f726b3589ab7d09bcd4f7ab5847 100644 (file)
@@ -1096,8 +1096,7 @@ mono_arch_allocate_vars (MonoCompile *cfg)
        offsets = mono_allocate_stack_slots (cfg, TRUE, &locals_stack_size, &locals_stack_align);
        if (locals_stack_size > MONO_ARCH_MAX_FRAME_SIZE) {
                char *mname = mono_method_full_name (cfg->method, TRUE);
-               cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
-               cfg->exception_message = g_strdup_printf ("Method %s stack is too big.", mname);
+               mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Method %s stack is too big.", mname));
                g_free (mname);
                return;
        }
index 7a490f01304c16d85d0ded4c14478ddc8cbc4bd6..ba5577ef60a07a481a482295b098f9a5c59c2c2c 100644 (file)
@@ -1256,8 +1256,17 @@ mini_method_verify (MonoCompile *cfg, MonoMethod *method, gboolean fail_compile)
                        if (info->info.status == MONO_VERIFY_NOT_VERIFIABLE && (!is_fulltrust || info->exception_type == MONO_EXCEPTION_METHOD_ACCESS || info->exception_type == MONO_EXCEPTION_FIELD_ACCESS)) {
                                if (fail_compile) {
                                        char *method_name = mono_method_full_name (method, TRUE);
-                                       cfg->exception_type = info->exception_type;
-                                       cfg->exception_message = g_strdup_printf ("Error verifying %s: %s", method_name, info->info.message);
+
+                                       if (info->exception_type == MONO_EXCEPTION_METHOD_ACCESS || info->exception_type == MONO_EXCEPTION_FIELD_ACCESS) {
+                                               if (info->exception_type == MONO_EXCEPTION_METHOD_ACCESS)
+                                                       mono_error_set_generic_error (&cfg->error, "System", "MethodAccessException", "Error verifying %s: %s", method_name, info->info.message);
+                                               else
+                                                       mono_error_set_generic_error (&cfg->error, "System", "FieldAccessException", "Error verifying %s: %s", method_name, info->info.message);
+                                               cfg->exception_type = MONO_EXCEPTION_MONO_ERROR;
+                                       } else {
+                                               cfg->exception_type = info->exception_type;
+                                               cfg->exception_message = g_strdup_printf ("Error verifying %s: %s", method_name, info->info.message);
+                                       }
                                        g_free (method_name);
                                }
                                mono_free_verify_list (res);
@@ -3477,8 +3486,7 @@ mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, JitFl
                if ((error = mono_loader_get_last_error ())) {
                        cfg->exception_type = error->exception_type;
                } else {
-                       cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
-                       cfg->exception_message = g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name);
+                       mono_cfg_set_exception_invalid_program (cfg, g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name));
                }
                if (MONO_METHOD_COMPILE_END_ENABLED ())
                        MONO_PROBE_METHOD_COMPILE_END (method, FALSE);
@@ -4135,6 +4143,14 @@ mono_cfg_set_exception (MonoCompile *cfg, int type)
        cfg->exception_type = type;
 }
 
+/* Assumes ownership of the MSG argument */
+void
+mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg)
+{
+       mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);
+       mono_error_set_generic_error (&cfg->error, "System", "InvalidProgramException", msg);
+}
+
 #endif /* DISABLE_JIT */
 
 static MonoJitInfo*
@@ -4335,28 +4351,9 @@ mono_jit_compile_method_inner (MonoMethod *method, MonoDomain *target_domain, in
                }
                break;
        }
-       case MONO_EXCEPTION_INVALID_PROGRAM:
-               ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", cfg->exception_message);
-               break;
        case MONO_EXCEPTION_UNVERIFIABLE_IL:
                ex = mono_exception_from_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", cfg->exception_message);
                break;
-       case MONO_EXCEPTION_METHOD_ACCESS:
-               ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MethodAccessException", cfg->exception_message);
-               break;
-       case MONO_EXCEPTION_FIELD_ACCESS:
-               ex = mono_exception_from_name_msg (mono_defaults.corlib, "System", "FieldAccessException", cfg->exception_message);
-               break;
-       case MONO_EXCEPTION_OBJECT_SUPPLIED: {
-               MonoException *exp = (MonoException *)cfg->exception_ptr;
-               MONO_GC_UNREGISTER_ROOT (cfg->exception_ptr);
-
-               ex = exp;
-               break;
-       }
-       case MONO_EXCEPTION_OUT_OF_MEMORY:
-               ex = mono_domain_get ()->out_of_memory_ex;
-               break;
        case MONO_EXCEPTION_MONO_ERROR:
                g_assert (!mono_error_ok (&cfg->error));
                ex = mono_error_convert_to_exception (&cfg->error);
index 5cf8fb5503895b818735664b7002213e73d9242c..592d2945d2fdc1f1914c7efd5b3d4686ca7aeba4 100644 (file)
@@ -3005,6 +3005,7 @@ guint mono_type_to_regmove (MonoCompile *cfg, MonoType *type) MONO_LLVM_INTERNAL
 void mono_cfg_add_try_hole (MonoCompile *cfg, MonoExceptionClause *clause, guint8 *start, MonoBasicBlock *bb);
 
 void mono_cfg_set_exception (MonoCompile *cfg, int type);
+void mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg);
 
 gboolean mini_type_is_reference (MonoType *type);
 gboolean mini_type_is_vtype (MonoType *t) MONO_LLVM_INTERNAL;