-
-/*
- * mini-runtime.c: Runtime code for the JIT
+/**
+ * \file
+ * Runtime code for the JIT
*
* Authors:
* Paolo Molaro (lupus@ximian.com)
#include <mono/utils/mono-threads-coop.h>
#include <mono/utils/checked-build.h>
#include <mono/metadata/w32handle.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/metadata/threadpool.h>
#include "mini.h"
#include "seq-points.h"
#include "mini-gc.h"
#include "mini-llvm.h"
#include "debugger-agent.h"
+#include "lldb.h"
#ifdef MONO_ARCH_LLVM_SUPPORTED
#ifdef ENABLE_LLVM
#endif
#endif
+#ifdef ENABLE_INTERPRETER
+#include "interp/interp.h"
+#endif
+
static guint32 default_opt = 0;
static gboolean default_opt_set = FALSE;
*/
gboolean mono_use_llvm = FALSE;
+gboolean mono_use_interpreter = FALSE;
+
#define mono_jit_lock() mono_os_mutex_lock (&jit_mutex)
#define mono_jit_unlock() mono_os_mutex_unlock (&jit_mutex)
static mono_mutex_t jit_mutex;
#ifdef VALGRIND_JIT_REGISTER_MAP
int valgrind_register;
#endif
+GList* mono_aot_paths;
+
+static gboolean mini_enable_profiler = FALSE;
+static char* mini_profiler_options = NULL;
static GSList *tramp_infos;
static void register_icalls (void);
+static gboolean mini_profiler_enabled (void) { return mini_enable_profiler; }
+static const char* mini_profiler_get_options (void) { return mini_profiler_options; }
+
gboolean
mono_running_on_valgrind (void)
{
/**
* mono_pmip:
- * @ip: an instruction pointer address
+ * \param ip an instruction pointer address
*
* This method is used from a debugger to get the name of the
- * method at address @ip. This routine is typically invoked from
+ * method at address \p ip. This routine is typically invoked from
* a debugger like this:
*
* (gdb) print mono_pmip ($pc)
*
- * Returns: the name of the method at address @ip.
+ * \returns the name of the method at address \p ip.
*/
G_GNUC_UNUSED char *
mono_pmip (void *ip)
}
/**
- * mono_print_method_from_ip
- * @ip: an instruction pointer address
+ * mono_print_method_from_ip:
+ * \param ip an instruction pointer address
*
* This method is used from a debugger to get the name of the
- * method at address @ip.
+ * method at address \p ip.
*
- * This prints the name of the method at address @ip in the standard
- * output. Unlike mono_pmip which returns a string, this routine
+ * This prints the name of the method at address \p ip in the standard
+ * output. Unlike \c mono_pmip which returns a string, this routine
* prints the value on the standard output.
*/
-#ifdef __GNUC__
-/* Prevent the linker from optimizing this away in embedding setups to help debugging */
- __attribute__((used))
-#endif
-void
+MONO_ATTR_USED void
mono_print_method_from_ip (void *ip)
{
MonoJitInfo *ji;
}
}
+/* The callback shouldn't take any locks */
+void
+mono_global_codeman_foreach (MonoCodeManagerFunc func, void *user_data)
+{
+ mono_jit_lock ();
+ mono_code_manager_foreach (global_codeman, func, user_data);
+ mono_jit_unlock ();
+}
+
#if defined(__native_client_codegen__) && defined(__native_client__)
void
mono_nacl_gc()
* INFO can be NULL.
* Frees INFO.
*/
-void
-mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain)
+static void
+mono_tramp_info_register_internal (MonoTrampInfo *info, MonoDomain *domain, gboolean aot)
{
MonoTrampInfo *copy;
mono_jit_unlock ();
mono_save_trampoline_xdebug_info (info);
+ mono_lldb_save_trampoline_info (info);
+
+#ifdef MONO_ARCH_HAVE_UNWIND_TABLE
+ if (!aot)
+ mono_arch_unwindinfo_install_tramp_unwind_info (info->unwind_ops, info->code, info->code_size);
+#endif
/* Only register trampolines that have unwind infos */
if (mono_get_root_domain () && copy->uw_info)
mono_tramp_info_free (info);
}
+void
+mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain)
+{
+ mono_tramp_info_register_internal (info, domain, FALSE);
+}
+
+void
+mono_aot_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain)
+{
+ mono_tramp_info_register_internal (info, domain, TRUE);
+}
+
static void
mono_tramp_info_cleanup (void)
{
{
static int count = 0;
static gboolean inited;
- static const char *value;
+ static char *value;
count ++;
if (!value)
return TRUE;
- if (count == atoi (value))
+ int int_val = atoi (value);
+ g_free (value);
+
+ if (count == int_val)
break_count ();
- if (count > atoi (value))
+ if (count > int_val)
return FALSE;
return TRUE;
MonoLMF *
mono_get_lmf (void)
{
-#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR)
- return (MonoLMF *)mono_tls_get_lmf ();
-#else
MonoJitTlsData *jit_tls;
if ((jit_tls = mono_tls_get_jit_tls ()))
* (the thread object allocation can trigger a collection).
*/
return NULL;
-#endif
}
MonoLMF **
void
mono_set_lmf (MonoLMF *lmf)
{
-#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR)
- mono_tls_set_lmf (lmf);
-#else
(*mono_get_lmf_addr ()) = lmf;
-#endif
}
MonoJitTlsData*
/**
* mono_thread_abort:
- * @obj: exception object
- *
- * abort the thread, print exception information and stack trace
+ * \param obj exception object
+ * Abort the thread, print exception information and stack trace
*/
static void
mono_thread_abort (MonoObject *obj)
jit_tls->first_lmf = lmf;
- /*
- * We can have 2 configurations for accessing lmf.
- * We can use only the tls_lmf_addr variable, which will store the address of
- * jit_tls->lmf, or, if we have MONO_ARCH_ENABLE_MONO_LMF_VAR enabled, we can
- * use both tls_lmf_addr and tls_lmf variables (in this case we need to have
- * means of getting the address of a tls variable; this can be done always
- * when using __thread or, on osx, even when using pthread)
- */
-#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR)
- /* jit_tls->lmf is unused */
- mono_tls_set_lmf (lmf);
- mono_set_lmf_addr (mono_tls_get_tls_addr (TLS_KEY_LMF));
-#else
mono_set_lmf_addr (&jit_tls->lmf);
jit_tls->lmf = lmf;
-#endif
#ifdef MONO_ARCH_HAVE_TLS_INIT
mono_arch_tls_init ();
unsigned char *ip = patch_info->ip.i + code;
gconstpointer target = NULL;
- mono_error_init (error);
+ error_init (error);
switch (patch_info->type) {
case MONO_PATCH_INFO_BB:
}
static gpointer
-mono_jit_compile_method_with_opt (MonoMethod *method, guint32 opt, MonoError *error)
+mono_jit_compile_method_with_opt (MonoMethod *method, guint32 opt, gboolean jit_only, MonoError *error)
{
MonoDomain *target_domain, *domain = mono_domain_get ();
MonoJitInfo *info;
MonoJitICallInfo *callinfo = NULL;
WrapperInfo *winfo = NULL;
- mono_error_init (error);
+ error_init (error);
+
+#ifdef ENABLE_INTERPRETER
+ if (mono_use_interpreter && !jit_only) {
+ code = mono_interp_create_method_pointer (method, error);
+ if (code)
+ return code;
+ }
+#endif
if (mono_llvm_only)
/* Should be handled by the caller */
{
gpointer code;
- code = mono_jit_compile_method_with_opt (method, mono_get_optimizations_for_method (method, default_opt), error);
+ code = mono_jit_compile_method_with_opt (method, mono_get_optimizations_for_method (method, default_opt), FALSE, error);
+ return code;
+}
+
+/*
+ * mono_jit_compile_method_jit_only:
+ *
+ * Compile METHOD using the JIT/AOT, even in interpreted mode.
+ */
+gpointer
+mono_jit_compile_method_jit_only (MonoMethod *method, MonoError *error)
+{
+ gpointer code;
+
+ code = mono_jit_compile_method_with_opt (method, mono_get_optimizations_for_method (method, default_opt), TRUE, error);
return code;
}
return;
mono_debug_remove_method (method, domain);
+ mono_lldb_remove_method (domain, method, ji);
mono_domain_lock (domain);
g_hash_table_remove (domain_jit_info (domain)->dynamic_code_hash, method);
gpointer *param_refs;
int i, pindex;
- mono_error_init (error);
+ error_init (error);
g_assert (info->gsharedvt_invoke);
/**
* mono_jit_runtime_invoke:
- * @method: the method to invoke
- * @obj: this pointer
- * @params: array of parameter values.
- * @exc: Set to the exception raised in the managed method. If NULL, error is thrown instead.
- * If coop is enabled, this argument is ignored - all exceptoins are caught and propagated
- * through @error
- * @error: error or caught exception object
+ * \param method: the method to invoke
+ * \param obj: this pointer
+ * \param params: array of parameter values.
+ * \param exc: Set to the exception raised in the managed method.
+ * \param error: error or caught exception object
+ * If \p exc is NULL, \p error is thrown instead.
+ * If coop is enabled, \p exc argument is ignored -
+ * all exceptions are caught and propagated through \p error
*/
static MonoObject*
mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
MonoJitInfo *ji = NULL;
gboolean callee_gsharedvt = FALSE;
- mono_error_init (error);
+#ifdef ENABLE_INTERPRETER
+ if (mono_use_interpreter)
+ return mono_interp_runtime_invoke (method, obj, params, exc, error);
+#endif
+
+ error_init (error);
if (obj == NULL && !(method->flags & METHOD_ATTRIBUTE_STATIC) && !method->string_ctor && (method->wrapper_type == 0)) {
g_warning ("Ignoring invocation of an instance method on a NULL instance.\n");
}
if (callee) {
- compiled_method = mono_jit_compile_method_with_opt (callee, mono_get_optimizations_for_method (callee, default_opt), error);
+ compiled_method = mono_jit_compile_method (callee, error);
if (!compiled_method) {
g_assert (!mono_error_ok (error));
return NULL;
ji = mono_jit_info_table_find_internal (mono_domain_get (), (char *)mono_arch_ip_from_context (ctx), TRUE, TRUE);
+ MONO_ENTER_GC_UNSAFE_UNBALANCED;
+
#if defined(MONO_ARCH_HAVE_IS_INT_OVERFLOW)
if (mono_arch_is_int_overflow (ctx, info))
/*
if (!ji) {
if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
- return;
+ goto exit;
mono_handle_native_crash ("SIGFPE", ctx, info);
if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
- return;
+ goto exit;
}
}
mono_arch_handle_exception (ctx, exc);
+
+exit:
+ MONO_EXIT_GC_UNSAFE_UNBALANCED;
}
MONO_SIG_HANDLER_FUNC (, mono_sigill_signal_handler)
MonoException *exc;
MONO_SIG_HANDLER_GET_CONTEXT;
+ MONO_ENTER_GC_UNSAFE_UNBALANCED;
+
exc = mono_get_exception_execution_engine ("Interrupted (SIGINT).");
mono_arch_handle_exception (ctx, exc);
+
+ MONO_EXIT_GC_UNSAFE_UNBALANCED;
}
#ifndef DISABLE_REMOTING
MonoMethod *nm;
guint8 *addr = NULL;
- mono_error_init (error);
+ error_init (error);
if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) && mono_method_signature (method)->generic_param_count) {
return mono_create_specific_trampoline (method, MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING,
{
if (mono_llvm_only)
del->extra_arg = mini_get_delegate_arg (del->method, del->method_ptr);
+#ifdef ENABLE_INTERPRETER
+ if (mono_use_interpreter)
+ mono_interp_init_delegate (del);
+#endif
}
char*
debug_options.break_on_unverified = TRUE;
else if (!strcmp (option, "no-gdb-backtrace"))
debug_options.no_gdb_backtrace = TRUE;
- else if (!strcmp (option, "suspend-on-sigsegv"))
- debug_options.suspend_on_sigsegv = TRUE;
+ else if (!strcmp (option, "suspend-on-native-crash") || !strcmp (option, "suspend-on-sigsegv"))
+ debug_options.suspend_on_native_crash = TRUE;
else if (!strcmp (option, "suspend-on-exception"))
debug_options.suspend_on_exception = TRUE;
else if (!strcmp (option, "suspend-on-unhandled"))
debug_options.dyn_runtime_invoke = TRUE;
else if (!strcmp (option, "gdb"))
debug_options.gdb = TRUE;
+ else if (!strcmp (option, "lldb"))
+ debug_options.lldb = TRUE;
else if (!strcmp (option, "explicit-null-checks"))
debug_options.explicit_null_checks = TRUE;
else if (!strcmp (option, "gen-seq-points"))
static void
mini_parse_debug_options (void)
{
- const char *options = g_getenv ("MONO_DEBUG");
+ char *options = g_getenv ("MONO_DEBUG");
gchar **args, **ptr;
if (!options)
return;
args = g_strsplit (options, ",", -1);
+ g_free (options);
for (ptr = args; ptr && *ptr; ptr++) {
const char *arg = *ptr;
if (!mini_parse_debug_option (arg)) {
fprintf (stderr, "Invalid option for the MONO_DEBUG env variable: %s\n", arg);
- fprintf (stderr, "Available options: 'handle-sigint', 'keep-delegates', 'reverse-pinvoke-exceptions', 'collect-pagefault-stats', 'break-on-unverified', 'no-gdb-backtrace', 'suspend-on-sigsegv', 'suspend-on-exception', 'suspend-on-unhandled', 'dont-free-domains', 'dyn-runtime-invoke', 'gdb', 'explicit-null-checks', 'gen-seq-points', 'no-compact-seq-points', 'single-imm-size', 'init-stacks', 'casts', 'soft-breakpoints', 'check-pinvoke-callconv', 'use-fallback-tls', 'debug-domain-unload', 'partial-sharing', 'align-small-structs', 'native-debugger-break'\n");
+ fprintf (stderr, "Available options: 'handle-sigint', 'keep-delegates', 'reverse-pinvoke-exceptions', 'collect-pagefault-stats', 'break-on-unverified', 'no-gdb-backtrace', 'suspend-on-native-crash', 'suspend-on-sigsegv', 'suspend-on-exception', 'suspend-on-unhandled', 'dont-free-domains', 'dyn-runtime-invoke', 'gdb', 'explicit-null-checks', 'gen-seq-points', 'no-compact-seq-points', 'single-imm-size', 'init-stacks', 'casts', 'soft-breakpoints', 'check-pinvoke-callconv', 'use-fallback-tls', 'debug-domain-unload', 'partial-sharing', 'align-small-structs', 'native-debugger-break'\n");
exit (1);
}
}
info->seq_points = g_hash_table_new_full (mono_aligned_addr_hash, NULL, NULL, mono_seq_point_info_free);
info->arch_seq_points = g_hash_table_new (mono_aligned_addr_hash, NULL);
info->jump_target_hash = g_hash_table_new (NULL, NULL);
+ mono_jit_code_hash_init (&info->interp_code_hash);
domain->runtime_info = info;
}
domain->runtime_info = NULL;
}
+#ifdef MONO_ARCH_HAVE_CODE_CHUNK_TRACKING
+
+static void
+code_manager_chunk_new (void *chunk, int size)
+{
+ mono_arch_code_chunk_new (chunk, size);
+}
+
+static void
+code_manager_chunk_destroy (void *chunk)
+{
+ mono_arch_code_chunk_destroy (chunk);
+}
+
+#endif
+
#ifdef ENABLE_LLVM
static gboolean
llvm_init_inner (void)
#endif
}
+void
+mini_profiler_enable_with_options (const char* profile_options)
+{
+ mini_enable_profiler = TRUE;
+ mini_profiler_options = g_strdup (profile_options);
+}
+
MonoDomain *
mini_init (const char *filename, const char *runtime_version)
{
MonoDomain *domain;
MonoRuntimeCallbacks callbacks;
MonoThreadInfoRuntimeCallbacks ticallbacks;
+ MonoCodeManagerCallbacks code_manager_callbacks;
MONO_VES_INIT_BEGIN ();
mono_threads_runtime_init (&ticallbacks);
- if (g_getenv ("MONO_DEBUG") != NULL)
+ if (g_hasenv ("MONO_DEBUG")) {
mini_parse_debug_options ();
+ }
mono_code_manager_init ();
+ memset (&code_manager_callbacks, 0, sizeof (code_manager_callbacks));
+#ifdef MONO_ARCH_HAVE_CODE_CHUNK_TRACKING
+ code_manager_callbacks.chunk_new = code_manager_chunk_new;
+ code_manager_callbacks.chunk_destroy = code_manager_chunk_destroy;
+#endif
+ mono_code_manager_install_callbacks (&code_manager_callbacks);
+
mono_hwcap_init ();
mono_arch_cpu_init ();
mono_unwind_init ();
+ if (mini_get_debug_options ()->lldb || g_hasenv ("MONO_LLDB")) {
+ mono_lldb_init ("");
+ mono_dont_free_domains = TRUE;
+ }
+
#ifdef XDEBUG_ENABLED
- if (g_getenv ("MONO_XDEBUG")) {
- const char *xdebug_opts = g_getenv ("MONO_XDEBUG");
- mono_xdebug_init (xdebug_opts);
+ char *mono_xdebug = g_getenv ("MONO_XDEBUG");
+ if (mono_xdebug) {
+ mono_xdebug_init (mono_xdebug);
+ g_free (mono_xdebug);
/* So methods for multiple domains don't have the same address */
mono_dont_free_domains = TRUE;
mono_using_xdebug = TRUE;
mono_install_get_class_from_name (mono_aot_get_class_from_name);
mono_install_jit_info_find_in_aot (mono_aot_find_jit_info);
+ if (mini_profiler_enabled ()) {
+ mono_profiler_load (mini_profiler_get_options ());
+ mono_profiler_thread_name (MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ()), "Main");
+ }
+
if (debug_options.collect_pagefault_stats)
mono_aot_set_make_unreadable (TRUE);
register_icall (mono_threads_state_poll, "mono_threads_state_poll", "void", FALSE);
#ifndef MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
- register_opcode_emulation (OP_LMUL, "__emul_lmul", "long long long", mono_llmult, "mono_llmult", TRUE);
+ register_opcode_emulation (OP_LMUL, "__emul_lmul", "long long long", mono_llmult, "mono_llmult", FALSE);
register_opcode_emulation (OP_LDIV, "__emul_ldiv", "long long long", mono_lldiv, "mono_lldiv", FALSE);
register_opcode_emulation (OP_LDIV_UN, "__emul_ldiv_un", "long long long", mono_lldiv_un, "mono_lldiv_un", FALSE);
register_opcode_emulation (OP_LREM, "__emul_lrem", "long long long", mono_llrem, "mono_llrem", FALSE);
register_icall_no_wrapper (mono_tls_get_thread, "mono_tls_get_thread", "ptr");
register_icall_no_wrapper (mono_tls_get_jit_tls, "mono_tls_get_jit_tls", "ptr");
register_icall_no_wrapper (mono_tls_get_domain, "mono_tls_get_domain", "ptr");
- register_icall_no_wrapper (mono_tls_get_lmf, "mono_tls_get_lmf", "ptr");
register_icall_no_wrapper (mono_tls_get_sgen_thread_info, "mono_tls_get_sgen_thread_info", "ptr");
register_icall_no_wrapper (mono_tls_get_lmf_addr, "mono_tls_get_lmf_addr", "ptr");
register_icall_no_wrapper (mono_tls_set_thread, "mono_tls_set_thread", "void ptr");
register_icall_no_wrapper (mono_tls_set_jit_tls, "mono_tls_set_jit_tls", "void ptr");
register_icall_no_wrapper (mono_tls_set_domain, "mono_tls_set_domain", "void ptr");
- register_icall_no_wrapper (mono_tls_set_lmf, "mono_tls_set_lmf", "void ptr");
register_icall_no_wrapper (mono_tls_set_sgen_thread_info, "mono_tls_set_sgen_thread_info", "void ptr");
register_icall_no_wrapper (mono_tls_set_lmf_addr, "mono_tls_set_lmf_addr", "void ptr");
}
mono_runtime_cleanup (domain);
#endif
+ mono_threadpool_cleanup ();
+
mono_profiler_shutdown ();
free_jit_tls_data ((MonoJitTlsData *)mono_tls_get_jit_tls ());
/**
* mono_get_runtime_build_info:
- *
- * 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.
+ * format is <code>VERSION (FULL_VERSION BUILD_DATE)</code> and build date is optional.
+ * \returns the runtime version + build date in string format.
*/
char*
mono_get_runtime_build_info (void)