#endif
MonoTraceSpec *mono_jit_trace_calls = NULL;
-gboolean mono_break_on_exc = FALSE;
gboolean mono_compile_aot = FALSE;
/* If this is set, no code is generated dynamically, everything is taken from AOT files */
gboolean mono_aot_only = FALSE;
MonoDomain *domain = mono_domain_get ();
MonoDebugSourceLocation *location;
FindTrampUserData user_data;
-
+
+ if (!domain)
+ domain = mono_get_root_domain ();
+
ji = mono_jit_info_table_find (domain, ip);
if (!ji) {
user_data.ip = ip;
g_free (info);
}
+G_GNUC_UNUSED static void
+break_count (void)
+{
+}
+
+/*
+ * Runtime debugging tool, use if (debug_count ()) <x> else <y> to do <x> the first COUNT times, then do <y> afterwards.
+ * Set a breakpoint in break_count () to break the last time <x> is done.
+ */
+G_GNUC_UNUSED gboolean
+mono_debug_count (void)
+{
+ static int count = 0;
+ count ++;
+
+ if (!getenv ("COUNT"))
+ return TRUE;
+
+ if (count == atoi (getenv ("COUNT"))) {
+ break_count ();
+ }
+
+ if (count > atoi (getenv ("COUNT"))) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
#define MONO_INIT_VARINFO(vi,id) do { \
(vi)->range.first_use.pos.bid = 0xffff; \
(vi)->reg = -1; \
#endif
}
-/* Called by native->managed wrappers */
-void
+/*
+ * mono_jit_thread_attach:
+ *
+ * Called by native->managed wrappers. Returns the original domain which needs to be
+ * restored, or NULL.
+ */
+MonoDomain*
mono_jit_thread_attach (MonoDomain *domain)
{
+ MonoDomain *orig;
+
if (!domain)
/*
* Happens when called from AOTed code which is only used in the root
mono_thread_set_state (mono_thread_internal_current (), ThreadState_Background);
}
#endif
- if (mono_domain_get () != domain)
- mono_domain_set (domain, TRUE);
+ orig = mono_domain_get ();
+ if (orig != domain)
+ mono_domain_set (domain, TRUE);
+
+ return orig != domain ? orig : NULL;
}
+/* Called by native->managed wrappers */
+void
+mono_jit_set_domain (MonoDomain *domain)
+{
+ if (domain)
+ mono_domain_set (domain, TRUE);
+}
+
/**
* mono_thread_abort:
* @obj: exception object
(obj->vtable->klass == mono_defaults.threadabortexception_class)) {
mono_thread_exit ();
} else {
- MonoObject *other = NULL;
- MonoString *str = mono_object_to_string (obj, &other);
- if (str) {
- char *msg = mono_string_to_utf8 (str);
- fprintf (stderr, "[ERROR] FATAL UNHANDLED EXCEPTION: %s\n", msg);
- fflush (stderr);
- g_free (msg);
- }
-
- exit (mono_environment_exitcode_get ());
+ mono_invoke_unhandled_exception_hook (obj);
}
}
#if defined(MONO_HAVE_FAST_TLS) && defined(MONO_ARCH_ENABLE_MONO_LMF_VAR)
/* jit_tls->lmf is unused */
MONO_FAST_TLS_SET (mono_lmf, lmf);
- mono_set_lmf_addr (&mono_lmf);
+ mono_set_lmf_addr (MONO_FAST_TLS_ADDR (mono_lmf));
#else
mono_set_lmf_addr (&jit_tls->lmf);
jit_tls->lmf = lmf;
#endif
- mono_arch_setup_jit_tls_data (jit_tls);
mono_setup_altstack (jit_tls);
return jit_tls;
return mono_create_tls_get (cfg, mono_thread_get_tls_offset ());
}
+MonoInst*
+mono_get_lmf_intrinsic (MonoCompile* cfg)
+{
+ return mono_create_tls_get (cfg, mono_get_lmf_tls_offset ());
+}
+
void
mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target)
{
target = code;
} else {
/* get the trampoline to the method from the domain */
- target = mono_create_jit_trampoline (patch_info->data.method);
+ target = mono_create_jit_trampoline_in_domain (domain, patch_info->data.method);
}
break;
case MONO_PATCH_INFO_SWITCH: {
break;
}
case MONO_PATCH_INFO_DELEGATE_TRAMPOLINE:
- target = mono_create_delegate_trampoline (patch_info->data.klass);
+ target = mono_create_delegate_trampoline (domain, patch_info->data.klass);
break;
case MONO_PATCH_INFO_SFLDA: {
MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
case MONO_PATCH_INFO_ICALL_ADDR:
/* run_cctors == 0 -> AOT */
if (patch_info->data.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
+ const char *exc_class;
+ const char *exc_arg;
+
if (run_cctors) {
- target = mono_lookup_pinvoke_call (patch_info->data.method, NULL, NULL);
- if (!target)
+ target = mono_lookup_pinvoke_call (patch_info->data.method, &exc_class, &exc_arg);
+ if (!target) {
+ if (mono_aot_only)
+ mono_raise_exception (mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg));
g_error ("Unable to resolve pinvoke method '%s' Re-run with MONO_LOG_LEVEL=debug for more information.\n", mono_method_full_name (patch_info->data.method, TRUE));
+ }
} else {
target = NULL;
}
switch (entry->data->type) {
case MONO_PATCH_INFO_CLASS:
- slot = mono_method_lookup_or_register_other_info (entry->method, entry->in_mrgctx, &entry->data->data.klass->byval_arg, entry->info_type, mono_method_get_context (entry->method));
+ slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, &entry->data->data.klass->byval_arg, entry->info_type, mono_method_get_context (entry->method));
break;
case MONO_PATCH_INFO_METHOD:
case MONO_PATCH_INFO_METHODCONST:
- slot = mono_method_lookup_or_register_other_info (entry->method, entry->in_mrgctx, entry->data->data.method, entry->info_type, mono_method_get_context (entry->method));
+ slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, entry->data->data.method, entry->info_type, mono_method_get_context (entry->method));
break;
case MONO_PATCH_INFO_FIELD:
- slot = mono_method_lookup_or_register_other_info (entry->method, entry->in_mrgctx, entry->data->data.field, entry->info_type, mono_method_get_context (entry->method));
+ slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, entry->data->data.field, entry->info_type, mono_method_get_context (entry->method));
break;
default:
g_assert_not_reached ();
bb->last_seq_point = ins;
}
+void
+mono_add_var_location (MonoCompile *cfg, MonoInst *var, gboolean is_reg, int reg, int offset, int from, int to)
+{
+ MonoDwarfLocListEntry *entry = mono_mempool_alloc0 (cfg->mempool, sizeof (MonoDwarfLocListEntry));
+
+ if (is_reg)
+ g_assert (offset == 0);
+
+ entry->is_reg = is_reg;
+ entry->reg = reg;
+ entry->offset = offset;
+ entry->from = from;
+ entry->to = to;
+
+ if (var == cfg->args [0])
+ cfg->this_loclist = g_slist_append_mempool (cfg->mempool, cfg->this_loclist, entry);
+ else if (var == cfg->rgctx_var)
+ cfg->rgctx_loclist = g_slist_append_mempool (cfg->mempool, cfg->rgctx_loclist, entry);
+}
+
#ifndef DISABLE_JIT
static void
last = ins;
}
+
+ if (bb->last_ins && bb->last_ins->opcode == OP_ENDFINALLY) {
+ MonoBasicBlock *bb2;
+ MonoInst *endfinally_seq_point = NULL;
+
+ /*
+ * The ENDFINALLY branches are not represented in the cfg, so link it with all seq points starting bbs.
+ */
+ l = g_slist_last (bb->seq_points);
+ g_assert (l);
+ endfinally_seq_point = l->data;
+
+ for (bb2 = cfg->bb_entry; bb2; bb2 = bb2->next_bb) {
+ GSList *l = g_slist_last (bb2->seq_points);
+
+ if (l) {
+ MonoInst *ins = l->data;
+
+ if (!(ins->inst_imm == METHOD_ENTRY_IL_OFFSET || ins->inst_imm == METHOD_EXIT_IL_OFFSET) && ins != endfinally_seq_point)
+ next [endfinally_seq_point->backend.size] = g_slist_append (next [endfinally_seq_point->backend.size], GUINT_TO_POINTER (ins->backend.size));
+ }
+ }
+ }
}
if (cfg->verbose_level > 2) {
sp->next = g_new (int, sp->next_len);
j = 0;
if (cfg->verbose_level > 2 && next [i]) {
- printf ("\t0x%x ->", sp->il_offset);
+ printf ("\tIL0x%x ->", sp->il_offset);
for (l = next [i]; l; l = l->next) {
next_index = GPOINTER_TO_UINT (l->data);
- printf (" 0x%x", info->seq_points [next_index].il_offset);
+ printf (" IL0x%x", info->seq_points [next_index].il_offset);
}
printf ("\n");
}
MonoJitInfo *jinfo;
int num_clauses;
int generic_info_size, arch_eh_info_size = 0;
- int holes_size = 0, num_holes = 0;
+ int holes_size = 0, num_holes = 0, cas_size = 0;
guint32 stack_size = 0;
g_assert (method_to_compile == cfg->method);
* mono_arch_get_argument_info () is not signal safe.
*/
arg_info = g_newa (MonoJitArgumentInfo, sig->param_count + 1);
- stack_size = mono_arch_get_argument_info (sig, sig->param_count, arg_info);
+ stack_size = mono_arch_get_argument_info (cfg->generic_sharing_context, sig, sig->param_count, arg_info);
if (stack_size)
arch_eh_info_size = sizeof (MonoArchEHJitInfo);
printf ("Number of try block holes %d\n", num_holes);
}
+ if (mono_method_has_declsec (cfg->method_to_register)) {
+ cas_size = sizeof (MonoMethodCasInfo);
+ }
+
if (COMPILE_LLVM (cfg))
num_clauses = cfg->llvm_ex_info_len;
else
if (cfg->method->dynamic) {
jinfo = g_malloc0 (MONO_SIZEOF_JIT_INFO + (num_clauses * sizeof (MonoJitExceptionInfo)) +
- generic_info_size + holes_size + arch_eh_info_size);
+ generic_info_size + holes_size + arch_eh_info_size + cas_size);
} else {
jinfo = mono_domain_alloc0 (cfg->domain, MONO_SIZEOF_JIT_INFO +
(num_clauses * sizeof (MonoJitExceptionInfo)) +
- generic_info_size + holes_size + arch_eh_info_size);
+ generic_info_size + holes_size + arch_eh_info_size + cas_size);
}
jinfo->method = cfg->method_to_register;
jinfo->code_size = cfg->code_len;
jinfo->used_regs = cfg->used_int_regs;
jinfo->domain_neutral = (cfg->opt & MONO_OPT_SHARED) != 0;
- jinfo->cas_inited = FALSE; /* initialization delayed at the first stalk walk using this method */
jinfo->num_clauses = num_clauses;
+
if (COMPILE_LLVM (cfg))
jinfo->from_llvm = TRUE;
if (cfg->generic_sharing_context) {
MonoInst *inst;
MonoGenericJitInfo *gi;
+ GSList *loclist = NULL;
jinfo->has_generic_jit_info = 1;
inst = cfg->rgctx_var;
if (!COMPILE_LLVM (cfg))
g_assert (inst->opcode == OP_REGOFFSET);
+ loclist = cfg->rgctx_loclist;
} else {
inst = cfg->args [0];
+ loclist = cfg->this_loclist;
+ }
+
+ if (loclist) {
+ /* Needed to handle async exceptions */
+ GSList *l;
+ int i;
+
+ gi->nlocs = g_slist_length (loclist);
+ if (cfg->method->dynamic)
+ gi->locations = g_malloc0 (gi->nlocs * sizeof (MonoDwarfLocListEntry));
+ else
+ gi->locations = mono_domain_alloc0 (cfg->domain, gi->nlocs * sizeof (MonoDwarfLocListEntry));
+ i = 0;
+ for (l = loclist; l; l = l->next) {
+ memcpy (&(gi->locations [i]), l->data, sizeof (MonoDwarfLocListEntry));
+ i ++;
+ }
}
if (COMPILE_LLVM (cfg)) {
info->stack_size = stack_size;
}
+ if (cas_size) {
+ jinfo->has_cas_info = 1;
+ }
+
if (COMPILE_LLVM (cfg)) {
if (num_clauses)
memcpy (&jinfo->clauses [0], &cfg->llvm_ex_info [0], num_clauses * sizeof (MonoJitExceptionInfo));
InterlockedIncrement (&mono_jit_stats.methods_compiled);
if (mono_profiler_get_events () & MONO_PROFILE_JIT_COMPILATION)
mono_profiler_method_jit (method);
- if (MONO_PROBE_METHOD_COMPILE_BEGIN_ENABLED ())
+ if (MONO_METHOD_COMPILE_BEGIN_ENABLED ())
MONO_PROBE_METHOD_COMPILE_BEGIN (method);
if (compile_aot)
cfg->exception_type = MONO_EXCEPTION_TYPE_LOAD;
cfg->exception_message = g_strdup (mono_error_get_message (&err));
mono_error_cleanup (&err);
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, FALSE);
return cfg;
}
cfg->exception_type = MONO_EXCEPTION_INVALID_PROGRAM;
cfg->exception_message = g_strdup_printf ("Missing or incorrect header for method %s", cfg->method->name);
}
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, FALSE);
return cfg;
}
/* Temporarily disable this when running in the debugger until we have support
* for this in the debugger. */
- cfg->disable_omit_fp = TRUE;
+ /* This is no longer needed with sdb */
+ //cfg->disable_omit_fp = TRUE;
/* The debugger needs all locals to be on the stack or in a global register */
cfg->disable_vreg_to_lvreg = TRUE;
cfg->opt &= ~MONO_OPT_INLINE;
cfg->opt &= ~MONO_OPT_COPYPROP;
cfg->opt &= ~MONO_OPT_CONSPROP;
- cfg->opt &= ~MONO_OPT_GSHARED;
+ /* This is no longer needed with sdb */
+ //cfg->opt &= ~MONO_OPT_GSHARED;
/* This is needed for the soft debugger, which doesn't like code after the epilog */
cfg->disable_out_of_line_bblocks = TRUE;
if (i < 0) {
if (try_generic_shared && cfg->exception_type == MONO_EXCEPTION_GENERIC_SHARING_FAILED) {
if (compile_aot) {
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, FALSE);
return cfg;
}
}
g_assert (cfg->exception_type != MONO_EXCEPTION_GENERIC_SHARING_FAILED);
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, FALSE);
/* cfg contains the details of the failure, so let the caller cleanup */
return cfg;
/* after method_to_ir */
if (parts == 1) {
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, TRUE);
return cfg;
}
/* after SSA translation */
if (parts == 2) {
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, TRUE);
return cfg;
}
/* after SSA removal */
if (parts == 3) {
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, TRUE);
return cfg;
}
}
/* collect statistics */
+#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters->jit_methods++;
mono_perfcounters->jit_bytes += header->code_size;
+#endif
mono_jit_stats.allocated_code_size += cfg->code_len;
code_size_ratio = cfg->code_len;
if (code_size_ratio > mono_jit_stats.biggest_method_size && mono_jit_stats.enabled) {
}
mono_jit_stats.native_code_size += cfg->code_len;
- if (MONO_PROBE_METHOD_COMPILE_END_ENABLED ())
+ if (MONO_METHOD_COMPILE_END_ENABLED ())
MONO_PROBE_METHOD_COMPILE_END (method, TRUE);
return cfg;
return mono_get_addr_from_ftnptr ((gpointer)mono_icall_get_wrapper_full (mi, TRUE));
} else if (*name == 'I' && (strcmp (name, "Invoke") == 0)) {
#ifdef MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
- return mono_create_delegate_trampoline (method->klass);
+ return mono_create_delegate_trampoline (target_domain, method->klass);
#else
nm = mono_marshal_get_delegate_invoke (method, NULL);
return mono_get_addr_from_ftnptr (mono_compile_method (nm));
if (mono_aot_only) {
char *fullname = mono_method_full_name (method, TRUE);
- char *msg = g_strdup_printf ("Attempting to JIT compile method '%s' while running with --aot-only.\n", fullname);
+ char *msg = g_strdup_printf ("Attempting to JIT compile method '%s' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.\n", fullname);
*jit_ex = mono_get_exception_execution_engine (msg);
g_free (fullname);
opt |= MONO_OPT_SHARED;
}
+ if (method->dynamic)
+ opt &= ~MONO_OPT_SHARED;
+
+ /* These methods can become invalid when a domain is unloaded */
+ if (method->klass->image != mono_get_corlib () || method->is_inflated)
+ opt &= ~MONO_OPT_SHARED;
+
if (opt & MONO_OPT_SHARED)
target_domain = mono_get_root_domain ();
else
target_domain = domain;
+ if (method->wrapper_type == MONO_WRAPPER_UNKNOWN) {
+ WrapperInfo *info = mono_marshal_get_wrapper_info (method);
+
+ g_assert (info);
+ if (info->subtype == WRAPPER_SUBTYPE_SYNCHRONIZED_INNER)
+ method = info->d.synchronized_inner.method;
+ }
+
info = lookup_method (target_domain, method);
if (info) {
/* We can't use a domain specific method in another domain */
invalidated_delegate_trampoline (char *desc)
{
g_error ("Unmanaged code called delegate of type %s which was already garbage collected.\n"
- "See http://www.go-mono.com/delegate.html for an explanation and ways to fix this.",
+ "See http://www.mono-project.com/Diagnostic:Delegate for an explanation and ways to fix this.",
desc);
}
#endif
MonoRuntimeCallbacks callbacks;
MonoThreadInfoRuntimeCallbacks ticallbacks;
- MONO_PROBE_VES_INIT_BEGIN ();
+ MONO_VES_INIT_BEGIN ();
#if defined(__linux__) && !defined(__native_client__)
if (access ("/proc/self/maps", F_OK) != 0) {
g_thread_init (NULL);
mono_native_tls_alloc (&mono_jit_tls_id, NULL);
- setup_jit_tls_data ((gpointer)-1, mono_thread_abort);
if (default_opt & MONO_OPT_AOT)
mono_aot_init ();
if (mono_aot_only) {
/* This helps catch code allocation requests */
mono_code_manager_set_read_only (domain->code_mp);
+ mono_marshal_use_aot_wrappers (TRUE);
}
#ifdef MONO_ARCH_HAVE_IMT
mono_install_imt_thunk_builder (mono_arch_build_imt_thunk);
}
#endif
+ /*Init arch tls information only after the metadata side is inited to make sure we see dynamic appdomain tls keys*/
+ mono_arch_finish_init ();
+
/* This must come after mono_init () in the aot-only case */
mono_exceptions_init ();
mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers",
mono_runtime_install_handlers);
+#ifdef PLATFORM_ANDROID
+ mono_add_internal_call ("System.Diagnostics.Debugger::Mono_UnhandledException_internal",
+ mono_debugger_agent_unhandled_exception);
+#endif
+
mono_create_helper_signatures ();
register_jit_stats ();
register_icall (mono_trace_enter_method, "mono_trace_enter_method", NULL, TRUE);
register_icall (mono_trace_leave_method, "mono_trace_leave_method", NULL, TRUE);
register_icall (mono_get_lmf_addr, "mono_get_lmf_addr", "ptr", TRUE);
- register_icall (mono_jit_thread_attach, "mono_jit_thread_attach", "void", TRUE);
+ register_icall (mono_jit_thread_attach, "mono_jit_thread_attach", "ptr ptr", TRUE);
+ register_icall (mono_jit_set_domain, "mono_jit_set_domain", "void ptr", TRUE);
register_icall (mono_domain_get, "mono_domain_get", "ptr", TRUE);
register_icall (mono_get_throw_exception (), "mono_arch_throw_exception", "void object", TRUE);
mono_profiler_runtime_initialized ();
- MONO_PROBE_VES_INIT_END ();
+ MONO_VES_INIT_END ();
return domain;
}
g_print ("JIT info table lookups: %ld\n", mono_stats.jit_info_table_lookup_count);
g_print ("Hazardous pointers: %ld\n", mono_stats.hazardous_pointer_count);
- g_print ("Minor GC collections: %ld\n", mono_stats.minor_gc_count);
- g_print ("Major GC collections: %ld\n", mono_stats.major_gc_count);
- g_print ("Minor GC time in msecs: %lf\n", (double)mono_stats.minor_gc_time_usecs / 1000.0);
- g_print ("Major GC time in msecs: %lf\n", (double)mono_stats.major_gc_time_usecs / 1000.0);
if (mono_security_get_mode () == MONO_SECURITY_MODE_CAS) {
g_print ("\nDecl security check : %ld\n", mono_jit_stats.cas_declsec_check);
g_print ("LinkDemand (user) : %ld\n", mono_jit_stats.cas_linkdemand);
default_opt &= ~opts;
}
-/*
+void
+mono_set_optimizations (guint32 opts)
+{
+ default_opt = opts;
+ default_opt_set = TRUE;
+}
+
+void
+mono_set_verbose_level (guint32 level)
+{
+ mini_verbose = level;
+}
+
+/**
* mono_get_runtime_build_info:
*
- * Return the runtime version + build date in string format.
- * The returned string is owned by the caller.
+ * Return the runtime version + build date in string format.
+ * The returned string is owned by the caller. The returned string
+ * format is "VERSION (FULL_VERSION BUILD_DATE)" and build date is optional.
*/
char*
mono_get_runtime_build_info (void)