New test.
[mono.git] / mono / metadata / loader.c
index 1fe54a207fdad96daab4e25142ed9a7edcbe0bde..7737080a2e12244358ea07b7e9bfc7a898520d2c 100644 (file)
@@ -7,6 +7,7 @@
  *   Patrik Torstensson (patrik.torstensson@labs2.com)
  *
  * (C) 2001 Ximian, Inc.
+ * Copyright (C) 2002-2006 Novell, Inc.
  *
  * This file is used by the interpreter and the JIT engine to locate
  * assemblies.  Used to load AssemblyRef and later to resolve various
@@ -33,6 +34,7 @@
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/debug-helpers.h>
 #include <mono/metadata/reflection.h>
+#include <mono/metadata/profiler.h>
 #include <mono/utils/mono-logger.h>
 #include <mono/metadata/exception.h>
 
@@ -63,7 +65,7 @@ mono_loader_cleanup (void)
 {
        TlsFree (loader_error_thread_id);
 
-       DeleteCriticalSection (&loader_mutex);
+       /*DeleteCriticalSection (&loader_mutex);*/
 }
 
 /*
@@ -284,8 +286,8 @@ mono_loader_error_prepare_exception (MonoLoaderError *error)
                else
                        msg = g_strdup_printf ("Could not load file or assembly '%s' or one of its dependencies.", error->assembly_name);
 
-               mono_loader_clear_error ();
                ex = mono_get_exception_file_not_found2 (msg, mono_string_new (mono_domain_get (), error->assembly_name));
+               mono_loader_clear_error ();
                g_free (msg);
                break;
        }
@@ -1309,6 +1311,8 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
        else
                result = (MonoMethod *)mono_mempool_alloc0 (image->mempool, sizeof (MonoMethodNormal));
 
+       mono_stats.method_count ++;
+
        if (!klass) {
                guint32 type = mono_metadata_typedef_from_method (image, token);
                klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | type);
@@ -1408,10 +1412,14 @@ mono_get_method_full (MonoImage *image, guint32 token, MonoClass *klass,
  * mono_get_method_constrained:
  *
  * This is used when JITing the `constrained.' opcode.
+ *
+ * This returns two values: the contrained method, which has been inflated
+ * as the function return value;   And the original CIL-stream method as
+ * declared in cil_method.  The later is used for verification.
  */
 MonoMethod *
 mono_get_method_constrained (MonoImage *image, guint32 token, MonoClass *constrained_class,
-                            MonoGenericContext *context)
+                            MonoGenericContext *context, MonoMethod **cil_method)
 {
        MonoMethod *method, *result;
        MonoClass *ic = NULL;
@@ -1420,14 +1428,14 @@ mono_get_method_constrained (MonoImage *image, guint32 token, MonoClass *constra
 
        mono_loader_lock ();
 
-       method = mono_get_method_from_token (image, token, NULL, context);
-       if (!method) {
+       *cil_method = mono_get_method_from_token (image, token, NULL, context);
+       if (!*cil_method) {
                mono_loader_unlock ();
                return NULL;
        }
 
        mono_class_init (constrained_class);
-       method = mono_get_inflated_method (method);
+       method = mono_get_inflated_method (*cil_method);
        sig = mono_method_signature (method);
 
        if (method->is_inflated && sig->generic_param_count) {
@@ -1462,6 +1470,9 @@ mono_get_method_constrained (MonoImage *image, guint32 token, MonoClass *constra
 void
 mono_free_method  (MonoMethod *method)
 {
+       if (mono_profiler_get_events () != MONO_PROFILE_NONE)
+               return;
+       
        if (method->signature) {
                /* 
                 * FIXME: This causes crashes because the types inside signatures and