[mini] Rename mini_parse_debug_option's argument to match the header file (and match...
[mono.git] / mono / mini / mini-runtime.c
index cb1dc353b0681c4d68f84919f21043dad62fba7e..7bd111d26323e164a09d378956f2786c173a76ad 100644 (file)
@@ -2111,6 +2111,32 @@ mono_jit_find_compiled_method_with_jit_info (MonoDomain *domain, MonoMethod *met
        return NULL;
 }
 
+static guint32 bisect_opt = 0;
+static GHashTable *bisect_methods_hash = NULL;
+
+void
+mono_set_bisect_methods (guint32 opt, const char *method_list_filename)
+{
+       FILE *file;
+       char method_name [2048];
+
+       bisect_opt = opt;
+       bisect_methods_hash = g_hash_table_new (g_str_hash, g_str_equal);
+       g_assert (bisect_methods_hash);
+
+       file = fopen (method_list_filename, "r");
+       g_assert (file);
+
+       while (fgets (method_name, sizeof (method_name), file)) {
+               size_t len = strlen (method_name);
+               g_assert (len > 0);
+               g_assert (method_name [len - 1] == '\n');
+               method_name [len - 1] = 0;
+               g_hash_table_insert (bisect_methods_hash, g_strdup (method_name), GINT_TO_POINTER (1));
+       }
+       g_assert (feof (file));
+}
+
 gboolean mono_do_single_method_regression = FALSE;
 guint32 mono_single_method_regression_opt = 0;
 MonoMethod *mono_current_single_method;
@@ -2122,6 +2148,13 @@ mono_get_optimizations_for_method (MonoMethod *method, guint32 default_opt)
 {
        g_assert (method);
 
+       if (bisect_methods_hash) {
+               char *name = mono_method_full_name (method, TRUE);
+               void *res = g_hash_table_lookup (bisect_methods_hash, name);
+               g_free (name);
+               if (res)
+                       return default_opt | bisect_opt;
+       }
        if (!mono_do_single_method_regression)
                return default_opt;
        if (!mono_current_single_method) {
@@ -2156,18 +2189,6 @@ typedef struct {
        gpointer *wrapper_arg;
 } RuntimeInvokeInfo;
 
-gboolean
-mini_gsharedvt_runtime_invoke_supported (MonoMethodSignature *sig)
-{
-       gboolean supported = TRUE;
-
-       // FIXME:
-       if (sig->ret->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type (sig->ret)))
-               supported = FALSE;
-
-       return supported;
-}
-
 static RuntimeInvokeInfo*
 create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer compiled_method, gboolean callee_gsharedvt)
 {
@@ -2176,6 +2197,7 @@ create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer com
 
        info = g_new0 (RuntimeInvokeInfo, 1);
        info->compiled_method = compiled_method;
+       info->sig = mono_method_signature (method);
 
        invoke = mono_marshal_get_runtime_invoke (method, FALSE);
        info->vtable = mono_class_vtable_full (domain, method->klass, TRUE);
@@ -2255,17 +2277,10 @@ create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer com
 
        if (!info->dyn_call_info) {
                if (mono_llvm_only) {
-                       gboolean supported;
-
-                       supported = mini_gsharedvt_runtime_invoke_supported (sig);
-
-                       if (mono_class_is_contextbound (method->klass) || !info->compiled_method)
-                               supported = FALSE;
-
 #ifndef ENABLE_GSHAREDVT
-                       supported = FALSE;
+                       g_assert_not_reached ();
 #endif
-                       if (supported && !callee_gsharedvt) {
+                       if (!callee_gsharedvt) {
                                /* Invoke a gsharedvt out wrapper instead */
                                MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
                                MonoMethodSignature *wrapper_sig = mini_get_gsharedvt_out_sig_wrapper_signature (sig->hasthis, sig->ret->type != MONO_TYPE_VOID, sig->param_count);
@@ -2280,7 +2295,7 @@ create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer com
                                g_free (wrapper_sig);
 
                                info->compiled_method = mono_jit_compile_method (wrapper);
-                       } else if (supported) {
+                       } else {
                                /* Gsharedvt methods can be invoked the same way */
                                /* The out wrapper has the same signature as the compiled gsharedvt method */
                                MonoMethodSignature *wrapper_sig = mini_get_gsharedvt_out_sig_wrapper_signature (sig->hasthis, sig->ret->type != MONO_TYPE_VOID, sig->param_count);
@@ -2298,6 +2313,77 @@ create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer com
        return info;
 }
 
+static MonoObject*
+mono_llvmonly_runtime_invoke (MonoMethod *method, RuntimeInvokeInfo *info, void *obj, void **params, MonoObject **exc)
+{
+       MonoMethodSignature *sig = info->sig;
+       MonoDomain *domain = mono_domain_get ();
+       MonoObject *(*runtime_invoke) (MonoObject *this_obj, void **params, MonoObject **exc, void* compiled_method);
+       gpointer *args;
+       gpointer retval_ptr;
+       guint8 retval [256];
+       gpointer *param_refs;
+       int i, pindex;
+
+       g_assert (info->gsharedvt_invoke);
+
+       /*
+        * Instead of invoking the method directly, we invoke a gsharedvt out wrapper.
+        * The advantage of this is the gsharedvt out wrappers have a reduced set of
+        * signatures, so we only have to generate runtime invoke wrappers for these
+        * signatures.
+        * This code also handles invocation of gsharedvt methods directly, no
+        * out wrappers are used in that case.
+        */
+       args = (void **)g_alloca ((sig->param_count + sig->hasthis + 2) * sizeof (gpointer));
+       param_refs = (gpointer*)g_alloca ((sig->param_count + sig->hasthis + 2) * sizeof (gpointer));
+       pindex = 0;
+       /*
+        * The runtime invoke wrappers expects pointers to primitive types, so have to
+        * use indirections.
+        */
+       if (sig->hasthis)
+               args [pindex ++] = &obj;
+       if (sig->ret->type != MONO_TYPE_VOID) {
+               retval_ptr = (gpointer)&retval;
+               args [pindex ++] = &retval_ptr;
+       }
+       for (i = 0; i < sig->param_count; ++i) {
+               MonoType *t = sig->params [i];
+
+               if (t->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type (t))) {
+                       MonoClass *klass = mono_class_from_mono_type (t);
+                       guint8 *nullable_buf;
+                       int size;
+
+                       size = mono_class_value_size (klass, NULL);
+                       nullable_buf = g_alloca (size);
+                       g_assert (nullable_buf);
+
+                       /* The argument pointed to by params [i] is either a boxed vtype or null */
+                       mono_nullable_init (nullable_buf, (MonoObject*)params [i], klass);
+                       params [i] = nullable_buf;
+               }
+
+               if (MONO_TYPE_IS_REFERENCE (t)) {
+                       param_refs [i] = params [i];
+                       params [i] = &(param_refs [i]);
+               }
+               args [pindex ++] = &params [i];
+       }
+       /* The gsharedvt out wrapper has an extra argument which contains the method to call */
+       args [pindex ++] = &info->wrapper_arg;
+
+       runtime_invoke = (MonoObject *(*)(MonoObject *, void **, MonoObject **, void *))info->runtime_invoke;
+
+       runtime_invoke (NULL, args, exc, info->compiled_method);
+
+       if (sig->ret->type != MONO_TYPE_VOID && info->ret_box_class)
+               return mono_value_box (domain, info->ret_box_class, retval);
+       else
+               return *(MonoObject**)retval;
+}
+
 /**
  * mono_jit_runtime_invoke:
  * @method: the method to invoke
@@ -2463,69 +2549,10 @@ mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObjec
        }
 #endif
 
-       runtime_invoke = (MonoObject *(*)(MonoObject *, void **, MonoObject **, void *))info->runtime_invoke;
-
-       if (info->gsharedvt_invoke) {
-               MonoMethodSignature *sig = mono_method_signature (method);
-               gpointer *args;
-               gpointer retval_ptr;
-               guint8 retval [256];
-               gpointer *param_refs;
-               int i, pindex;
-
-               /*
-                * Instead of invoking the method directly, we invoke a gsharedvt out wrapper.
-                * The advantage of this is the gsharedvt out wrappers have a reduced set of
-                * signatures, so we only have to generate runtime invoke wrappers for these
-                * signatures.
-                * This code also handles invocation of gsharedvt methods directly, no
-                * out wrappers are used in that case.
-                */
-               args = (void **)g_alloca ((sig->param_count + sig->hasthis + 2) * sizeof (gpointer));
-               param_refs = (gpointer*)g_alloca ((sig->param_count + sig->hasthis + 2) * sizeof (gpointer));
-               pindex = 0;
-               /*
-                * The runtime invoke wrappers expects pointers to primitive types, so have to
-                * use indirections.
-                */
-               if (sig->hasthis)
-                       args [pindex ++] = &obj;
-               if (sig->ret->type != MONO_TYPE_VOID) {
-                       retval_ptr = (gpointer)&retval;
-                       args [pindex ++] = &retval_ptr;
-               }
-               for (i = 0; i < sig->param_count; ++i) {
-                       MonoType *t = sig->params [i];
-
-                       if (t->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type (t))) {
-                               MonoClass *klass = mono_class_from_mono_type (t);
-                               guint8 *nullable_buf;
-                               int size;
-
-                               size = mono_class_value_size (klass, NULL);
-                               nullable_buf = g_alloca (size);
-                               g_assert (nullable_buf);
-
-                               /* The argument pointed to by params [i] is either a boxed vtype or null */
-                               mono_nullable_init (nullable_buf, (MonoObject*)params [i], klass);
-                               params [i] = nullable_buf;
-                       }
-
-                       if (MONO_TYPE_IS_REFERENCE (t)) {
-                               param_refs [i] = params [i];
-                               params [i] = &(param_refs [i]);
-                       }
-                       args [pindex ++] = &params [i];
-               }
-               /* The gsharedvt out wrapper has an extra argument which contains the method to call */
-               args [pindex ++] = &info->wrapper_arg;
-               runtime_invoke (NULL, args, exc, info->compiled_method);
+       if (mono_llvm_only)
+               return mono_llvmonly_runtime_invoke (method, info, obj, params, exc);
 
-               if (sig->ret->type != MONO_TYPE_VOID && info->ret_box_class)
-                       return mono_value_box (domain, info->ret_box_class, retval);
-               else
-                       return *(MonoObject**)retval;
-       }
+       runtime_invoke = (MonoObject *(*)(MonoObject *, void **, MonoObject **, void *))info->runtime_invoke;
 
        return runtime_invoke ((MonoObject *)obj, params, exc, info->compiled_method);
 }
@@ -3046,57 +3073,57 @@ mono_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *met
 }
 
 gboolean
-mini_parse_debug_option (const char *arg)
+mini_parse_debug_option (const char *option)
 {
-       if (!strcmp (arg, "handle-sigint"))
+       if (!strcmp (option, "handle-sigint"))
                debug_options.handle_sigint = TRUE;
-       else if (!strcmp (arg, "keep-delegates"))
+       else if (!strcmp (option, "keep-delegates"))
                debug_options.keep_delegates = TRUE;
-       else if (!strcmp (arg, "reverse-pinvoke-exceptions"))
+       else if (!strcmp (option, "reverse-pinvoke-exceptions"))
                debug_options.reverse_pinvoke_exceptions = TRUE;
-       else if (!strcmp (arg, "collect-pagefault-stats"))
+       else if (!strcmp (option, "collect-pagefault-stats"))
                debug_options.collect_pagefault_stats = TRUE;
-       else if (!strcmp (arg, "break-on-unverified"))
+       else if (!strcmp (option, "break-on-unverified"))
                debug_options.break_on_unverified = TRUE;
-       else if (!strcmp (arg, "no-gdb-backtrace"))
+       else if (!strcmp (option, "no-gdb-backtrace"))
                debug_options.no_gdb_backtrace = TRUE;
-       else if (!strcmp (arg, "suspend-on-sigsegv"))
+       else if (!strcmp (option, "suspend-on-sigsegv"))
                debug_options.suspend_on_sigsegv = TRUE;
-       else if (!strcmp (arg, "suspend-on-exception"))
+       else if (!strcmp (option, "suspend-on-exception"))
                debug_options.suspend_on_exception = TRUE;
-       else if (!strcmp (arg, "suspend-on-unhandled"))
+       else if (!strcmp (option, "suspend-on-unhandled"))
                debug_options.suspend_on_unhandled = TRUE;
-       else if (!strcmp (arg, "dont-free-domains"))
+       else if (!strcmp (option, "dont-free-domains"))
                mono_dont_free_domains = TRUE;
-       else if (!strcmp (arg, "dyn-runtime-invoke"))
+       else if (!strcmp (option, "dyn-runtime-invoke"))
                debug_options.dyn_runtime_invoke = TRUE;
-       else if (!strcmp (arg, "gdb"))
+       else if (!strcmp (option, "gdb"))
                debug_options.gdb = TRUE;
-       else if (!strcmp (arg, "explicit-null-checks"))
+       else if (!strcmp (option, "explicit-null-checks"))
                debug_options.explicit_null_checks = TRUE;
-       else if (!strcmp (arg, "gen-seq-points"))
+       else if (!strcmp (option, "gen-seq-points"))
                debug_options.gen_sdb_seq_points = TRUE;
-       else if (!strcmp (arg, "gen-compact-seq-points"))
+       else if (!strcmp (option, "gen-compact-seq-points"))
                debug_options.gen_seq_points_compact_data = TRUE;
-       else if (!strcmp (arg, "single-imm-size"))
+       else if (!strcmp (option, "single-imm-size"))
                debug_options.single_imm_size = TRUE;
-       else if (!strcmp (arg, "init-stacks"))
+       else if (!strcmp (option, "init-stacks"))
                debug_options.init_stacks = TRUE;
-       else if (!strcmp (arg, "casts"))
+       else if (!strcmp (option, "casts"))
                debug_options.better_cast_details = TRUE;
-       else if (!strcmp (arg, "soft-breakpoints"))
+       else if (!strcmp (option, "soft-breakpoints"))
                debug_options.soft_breakpoints = TRUE;
-       else if (!strcmp (arg, "check-pinvoke-callconv"))
+       else if (!strcmp (option, "check-pinvoke-callconv"))
                debug_options.check_pinvoke_callconv = TRUE;
-       else if (!strcmp (arg, "arm-use-fallback-tls"))
+       else if (!strcmp (option, "arm-use-fallback-tls"))
                debug_options.arm_use_fallback_tls = TRUE;
-       else if (!strcmp (arg, "debug-domain-unload"))
+       else if (!strcmp (option, "debug-domain-unload"))
                mono_enable_debug_domain_unload (TRUE);
-       else if (!strcmp (arg, "partial-sharing"))
+       else if (!strcmp (option, "partial-sharing"))
                mono_set_partial_sharing_supported (TRUE);
-       else if (!strcmp (arg, "align-small-structs"))
+       else if (!strcmp (option, "align-small-structs"))
                mono_align_small_structs = TRUE;
-       else if (!strcmp (arg, "native-debugger-break"))
+       else if (!strcmp (option, "native-debugger-break"))
                debug_options.native_debugger_break = TRUE;
        else
                return FALSE;