Initialize the counters support before registering new ones.
authorJoão Matos <joao@tritao.eu>
Mon, 9 Feb 2015 17:37:22 +0000 (17:37 +0000)
committerJoão Matos <joao@tritao.eu>
Mon, 9 Feb 2015 17:40:04 +0000 (17:40 +0000)
This bug manifests itself in mkbundle'd programs that use the machine config support. Under this case, we can end up registering counters before initializing the counter support in the runtime:

```
* thread #1: tid = 0x141dec, 0x003ebdff mtouch-32`mono_counters_register(name=0x0042f7e3, type=2048, addr=0x00b81288) + 31 at mono-counters.c:218, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x003ebdff mtouch-32`mono_counters_register(name=0x0042f7e3, type=2048, addr=0x00b81288) + 31 at mono-counters.c:218
    frame #1: 0x0025c3f6 mtouch-32`mono_loader_init + 198 at loader.c:106
    frame #2: 0x0025f005 mtouch-32`mono_dllmap_insert(assembly=0x00000000, dll=0x00d0a0c0, func=0x00000000, tdll=0x00d0a0d0, tfunc=0x00000000) + 53 at loader.c:1321
    frame #3: 0x002c28ca mtouch-32`dllmap_start(user_data=0x00d0a0b0, element_name=0x00d0a0a0, attribute_names=0x00d0a030, attribute_values=0x00d0a040) + 698 at mono-config.c:290
    frame #4: 0x002c2010 mtouch-32`start_element(context=0x00d09fa0, element_name=0x00d0a0a0, attribute_names=0x00d0a030, attribute_values=0x00d0a040, user_data=0xbffffb68, error=0x00000000) + 240 at mono-config.c:176
    frame #5: 0x0040ba6d mtouch-32`monoeg_g_markup_parse_context_parse(context=0x00d09fa0, text=0x00b72f30, text_len=240, error=0x00000000) + 1965 at gmarkup.c:351
    frame #6: 0x002c0a93 mtouch-32`mono_config_parse_xml_with_context(state=0xbffffb68, text=0x00b72f30, len=240) + 147 at mono-config.c:440
    frame #7: 0x002c09eb mtouch-32`mono_config_parse_memory(buffer=0x00b72f30) + 123 at mono-config.c:482
    frame #8: 0x00001e6d mtouch-32`install_dll_config_files + 29
    frame #9: 0x00001c86 mtouch-32`mono_mkbundle_init + 22
    frame #10: 0x000029db mtouch-32`main + 331
    frame #11: 0x00001c65 mtouch-32`start + 53
```

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=24605.

mono/metadata/loader.c

index ded71d9789869cb85b74b96a2a6cf42d8001be1e..d0ea4441087dc30c8b43e5227d5354a366fee64c 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",