#include <mono/metadata/class-internals.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/reflection.h>
-#include <mono/metadata/profiler.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/marshal.h>
static gboolean loader_lock_inited;
/* Statistics */
-static guint32 inflated_signatures_size;
-static guint32 memberref_sig_cache_size;
-static guint32 methods_size;
-static guint32 signatures_size;
+static gint32 inflated_signatures_size;
+static gint32 memberref_sig_cache_size;
+static gint32 methods_size;
+static gint32 signatures_size;
/*
* This TLS variable holds how many times the current thread has acquired the loader
MonoNativeTlsKey loader_lock_nest_id;
static void dllmap_cleanup (void);
-
+static void cached_module_cleanup(void);
static void
global_loader_data_lock (void)
mono_loader_cleanup (void)
{
dllmap_cleanup ();
+ cached_module_cleanup ();
mono_native_tls_free (loader_lock_nest_id);
else {
g_hash_table_insert (image->memberref_signatures, GUINT_TO_POINTER (sig_idx), sig);
/* An approximation based on glib 2.18 */
- memberref_sig_cache_size += sizeof (gpointer) * 4;
+ InterlockedAdd (&memberref_sig_cache_size, sizeof (gpointer) * 4);
}
mono_image_unlock (image);
mono_class_init (k);
if (retklass)
*retklass = k;
- field = mono_class_get_field (k, token);
- if (!field) {
- mono_error_set_bad_image (error, image, "Could not resolve field token 0x%08x", token);
+ if (mono_class_has_failure (k)) {
+ MonoError causedby_error;
+ error_init (&causedby_error);
+ mono_error_set_for_class_failure (&causedby_error, k);
+ mono_error_set_bad_image (error, image, "Could not resolve field token 0x%08x, due to: %s", token, mono_error_get_message (&causedby_error));
+ mono_error_cleanup (&causedby_error);
+ } else {
+ field = mono_class_get_field (k, token);
+ if (!field) {
+ mono_error_set_bad_image (error, image, "Could not resolve field token 0x%08x", token);
+ }
}
}
if (cached != sig)
mono_metadata_free_inflated_signature (sig);
else
- inflated_signatures_size += mono_metadata_signature_size (cached);
+ InterlockedAdd (&inflated_signatures_size, mono_metadata_signature_size (cached));
sig = cached;
}
g_hash_table_insert (global_module_map, g_strdup (name), module);
}
+static void
+remove_cached_module(gpointer key, gpointer value, gpointer user_data)
+{
+ mono_dl_close((MonoDl*)value);
+}
+
+static void
+cached_module_cleanup(void)
+{
+ if (global_module_map != NULL) {
+ g_hash_table_foreach(global_module_map, remove_cached_module, NULL);
+
+ g_hash_table_destroy(global_module_map);
+ global_module_map = NULL;
+ }
+}
+
static MonoDl *internal_module;
static gboolean
is_absolute_path (const char *path)
{
-#ifdef PLATFORM_MACOSX
+#ifdef HOST_DARWIN
if (!strncmp (path, "@executable_path/", 17) || !strncmp (path, "@loader_path/", 13) ||
!strncmp (path, "@rpath/", 7))
return TRUE;
result = (MonoMethod *)mono_image_alloc0 (image, sizeof (MonoMethodPInvoke));
} else {
result = (MonoMethod *)mono_image_alloc0 (image, sizeof (MonoMethod));
- methods_size += sizeof (MonoMethod);
+ InterlockedAdd (&methods_size, sizeof (MonoMethod));
}
- mono_stats.method_count ++;
+ InterlockedIncrement (&mono_stats.method_count);
result->slot = -1;
result->klass = klass;
{
error_init (error);
- *cil_method = mono_get_method_from_token (image, token, NULL, context, NULL, error);
+ *cil_method = mono_get_method_checked (image, token, NULL, context, error);
if (!*cil_method)
return NULL;
void
mono_free_method (MonoMethod *method)
{
- if (mono_profiler_get_events () & MONO_PROFILE_METHOD_EVENTS)
- mono_profiler_method_free (method);
+ MONO_PROFILER_RAISE (method_free, (method));
/* FIXME: This hack will go away when the profiler will support freeing methods */
- if (mono_profiler_get_events () != MONO_PROFILE_NONE)
+ if (G_UNLIKELY (mono_profiler_installed ()))
return;
if (method->signature) {
if (!mono_error_ok (error))
return NULL;
- inflated_signatures_size += mono_metadata_signature_size (signature);
+ InterlockedAdd (&inflated_signatures_size, mono_metadata_signature_size (signature));
mono_image_lock (img);
mono_image_unlock (img);
}
- signatures_size += mono_metadata_signature_size (signature);
+ InterlockedAdd (&signatures_size, mono_metadata_signature_size (signature));
}
/* Verify metadata consistency */