[runtime] Use condvars instead of events for notifying the finalizer thread.
[mono.git] / mono / metadata / loader.c
index 5e89e649de17c62e9bec663cf1950c637e8b1cf5..05cc3f7f83358d9caa035fb1985d7caf4a648938 100644 (file)
@@ -103,6 +103,7 @@ mono_loader_init ()
                mono_native_tls_alloc (&loader_error_thread_id, NULL);
                mono_native_tls_alloc (&loader_lock_nest_id, NULL);
 
+               mono_counters_init ();
                mono_counters_register ("Inflated signatures size",
                                                                MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &inflated_signatures_size);
                mono_counters_register ("Memberref signature cache size",
@@ -447,7 +448,7 @@ field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass,
        MonoTableInfo *tables = image->tables;
        MonoType *sig_type;
        guint32 cols[6];
-       guint32 nindex, class, class_table;
+       guint32 nindex, class;
        const char *fname;
        const char *ptr;
        guint32 idx = mono_metadata_token_index (token);
@@ -467,15 +468,12 @@ field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass,
 
        switch (class) {
        case MONO_MEMBERREF_PARENT_TYPEDEF:
-               class_table = MONO_TOKEN_TYPE_DEF;
                klass = mono_class_get_checked (image, MONO_TOKEN_TYPE_DEF | nindex, error);
                break;
        case MONO_MEMBERREF_PARENT_TYPEREF:
-               class_table = MONO_TOKEN_TYPE_REF;
                klass = mono_class_from_typeref_checked (image, MONO_TOKEN_TYPE_REF | nindex, error);
                break;
        case MONO_MEMBERREF_PARENT_TYPESPEC:
-               class_table = MONO_TOKEN_TYPE_SPEC;
                klass = mono_class_get_and_inflate_typespec_checked (image, MONO_TOKEN_TYPE_SPEC | nindex, context, error);
                break;
        default:
@@ -950,17 +948,11 @@ mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32
 
                        ptr = mono_metadata_blob_heap (image, sig_idx);
                        mono_metadata_decode_blob_size (ptr, &ptr);
-                       /* FIXME make type/signature parsing not produce loader errors */
-                       sig = mono_metadata_parse_method_signature (image, 0, ptr, NULL);
-                       g_assert (!mono_loader_get_last_error ());
 
-                       if (!sig) {
-                               guint32 class = cols [MONO_MEMBERREF_CLASS] & MONO_MEMBERREF_PARENT_MASK;
-                               const char *fname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
-                               //FIXME include the decoding error
-                               mono_error_set_bad_image (error, image, "Bad method signature class token 0x%08x field name %s token 0x%08x", class, fname, token);
+                       sig = mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, error);
+                       if (!sig)
                                return NULL;
-                       }
+
                        sig = cache_memberref_sig (image, sig_idx, sig);
                }
                /* FIXME: we probably should verify signature compat in the dynamic case too*/
@@ -1101,15 +1093,9 @@ method_from_memberref (MonoImage *image, guint32 idx, MonoGenericContext *typesp
 
        sig = find_cached_memberref_sig (image, sig_idx);
        if (!sig) {
-               sig = mono_metadata_parse_method_signature (image, 0, ptr, NULL);
-               if (sig == NULL) {
-                       /* FIXME don't swallow parsing error */
-                       if (mono_loader_get_last_error ()) /* FIXME mono_metadata_parse_method_signature leak a loader error */
-                               mono_error_set_from_loader_error (error);
-                       else
-                               mono_error_set_method_load (error, klass, mname, "Could not parse method signature");
+               sig = mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, error);
+               if (sig == NULL)
                        goto fail;
-               }
 
                sig = cache_memberref_sig (image, sig_idx, sig);
        }
@@ -1209,13 +1195,9 @@ method_from_methodspec (MonoImage *image, MonoGenericContext *context, guint32 i
        }
 
        if ((token & MONO_METHODDEFORREF_MASK) == MONO_METHODDEFORREF_METHODDEF) {
-               method = mono_get_method_full (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, context);
-               if (!method) {
-                       if (mono_loader_get_last_error ())
-                               mono_error_set_from_loader_error (error);
-                       else
-                               mono_error_set_bad_image (error, image, "Could not resolve methodspec 0x%08x methoddef token 0x%08x", idx, MONO_TOKEN_METHOD_DEF | nindex);
-               }
+               method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, context, error);
+               if (!method)
+                       return NULL;
        } else {
                method = method_from_memberref (image, nindex, context, NULL, error);
        }
@@ -1750,12 +1732,16 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
                                                                "Probing '%s'.", mangled_name2);
 
                                        error_msg = mono_dl_symbol (module, mangled_name2, &piinfo->addr);
-                                       g_free (error_msg);
-                                       error_msg = NULL;
 
                                        if (piinfo->addr)
                                                mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
                                                                        "Found as '%s'.", mangled_name2);
+                                       else
+                                               mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
+                                                                       "Could not find '%s' due to '%s'.", mangled_name2, error_msg);
+
+                                       g_free (error_msg);
+                                       error_msg = NULL;
 
                                        if (mangled_name != mangled_name2)
                                                g_free (mangled_name2);
@@ -1790,7 +1776,6 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
        MonoTableInfo *tables = image->tables;
        MonoGenericContainer *generic_container = NULL, *container = NULL;
        const char *sig = NULL;
-       int size;
        guint32 cols [MONO_TYPEDEF_SIZE];
 
        mono_error_init (error);
@@ -1860,7 +1845,7 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
 
        if (!sig) /* already taken from the methodref */
                sig = mono_metadata_blob_heap (image, cols [4]);
-       size = mono_metadata_decode_blob_size (sig, &sig);
+       /* size = */ mono_metadata_decode_blob_size (sig, &sig);
 
        container = klass->generic_container;
 
@@ -2470,7 +2455,10 @@ static gboolean loader_lock_track_ownership = FALSE;
 void
 mono_loader_lock (void)
 {
+       MONO_TRY_BLOCKING
        mono_locks_acquire (&loader_mutex, LoaderLock);
+       MONO_FINISH_TRY_BLOCKING
+               
        if (G_UNLIKELY (loader_lock_track_ownership)) {
                mono_native_tls_set_value (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (mono_native_tls_get_value (loader_lock_nest_id)) + 1));
        }
@@ -2541,7 +2529,6 @@ MonoMethodSignature*
 mono_method_signature_checked (MonoMethod *m, MonoError *error)
 {
        int idx;
-       int size;
        MonoImage* img;
        const char *sig;
        gboolean can_cache_signature;
@@ -2609,7 +2596,7 @@ mono_method_signature_checked (MonoMethod *m, MonoError *error)
                if (!mono_verifier_verify_method_signature (img, sig_offset, error))
                        return NULL;
 
-               size = mono_metadata_decode_blob_size (sig, &sig_body);
+               /* size = */ mono_metadata_decode_blob_size (sig, &sig_body);
 
                signature = mono_metadata_parse_method_signature_full (img, container, idx, sig_body, NULL, error);
                if (!signature)