[profiler] Fix finding methods in other domains than the current one.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Thu, 19 Mar 2015 00:34:08 +0000 (01:34 +0100)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Thu, 19 Mar 2015 00:34:08 +0000 (01:34 +0100)
In certain cross-domain scenarios, the method we're executing
is not necessarily emitted in the current domain. So we need
to scan all domains for it.

mono/profiler/proflog.c

index 3dcb3a2d0b4a2300d8686d2c7787a52a33d73bac..211813d8abdbed914f1fde3a57b4af3bd4f76414 100644 (file)
@@ -592,6 +592,33 @@ emit_method_inner (LogBuffer *logbuffer, void *method)
        assert (logbuffer->data <= logbuffer->data_end);
 }
 
+typedef struct {
+       MonoMethod *method;
+       MonoJitInfo *found;
+} MethodSearch;
+
+static void
+find_method (MonoDomain *domain, void *user_data)
+{
+       MethodSearch *search = user_data;
+
+       if (search->found)
+               return;
+
+       MonoJitInfo *ji = mono_get_jit_info_from_method (domain, search->method);
+
+       // It could be AOT'd, so we need to force it to be loaded.
+       if (!ji) {
+               // Loads the method as a side effect.
+               mono_aot_get_method (domain, search->method);
+
+               ji = mono_get_jit_info_from_method (domain, search->method);
+       }
+
+       if (ji)
+               search->found = ji;
+}
+
 static void
 register_method_local (MonoProfiler *prof, MonoDomain *domain, MonoMethod *method, MonoJitInfo *ji)
 {
@@ -599,15 +626,12 @@ register_method_local (MonoProfiler *prof, MonoDomain *domain, MonoMethod *metho
                g_assert (ji);
 
        if (!mono_conc_hashtable_lookup (prof->method_table, method)) {
-               if (!ji)
-                       ji = mono_get_jit_info_from_method (domain, method);
-
-               // It could be AOT'd, so we need to force it to be loaded.
                if (!ji) {
-                       // Loads the method as a side effect.
-                       mono_aot_get_method (domain, method);
+                       MethodSearch search = { method, NULL };
+
+                       mono_domain_foreach (find_method, &search);
 
-                       ji = mono_get_jit_info_from_method (domain, method);
+                       ji = search.found;
                }
 
                g_assert (ji);