X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fjit-info.c;h=6ffff1a6b7328511743975d2b247935fe7aa9d6d;hb=79283363f0f551d2b2d435d09bbec69f0b643675;hp=33dd5471c5fc713016ed172149a0b0642720d9bb;hpb=e137ff6f7e2594d3ce96b4c74b528d26cc80e11d;p=mono.git diff --git a/mono/metadata/jit-info.c b/mono/metadata/jit-info.c index 33dd5471c5f..6ffff1a6b73 100644 --- a/mono/metadata/jit-info.c +++ b/mono/metadata/jit-info.c @@ -8,6 +8,7 @@ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com) * Copyright 2004-2009 Novell, Inc (http://www.novell.com) * Copyright 2011-2012 Xamarin, Inc (http://www.xamarin.com) + * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include @@ -125,18 +126,15 @@ mono_jit_info_table_free (MonoJitInfoTable *table) for (i = 0; i < num_chunks; ++i) { MonoJitInfoTableChunk *chunk = table->chunks [i]; - int num_elements; - int j; + MonoJitInfo *tombstone; if (--chunk->refcount > 0) continue; - num_elements = chunk->num_elements; - for (j = 0; j < num_elements; ++j) { - MonoJitInfo *ji = chunk->data [j]; - - if (IS_JIT_INFO_TOMBSTONE (ji)) - g_free (ji); + for (tombstone = chunk->next_tombstone; tombstone; ) { + MonoJitInfo *next = tombstone->n.next_tombstone; + g_free (tombstone); + tombstone = next; } g_free (chunk); @@ -197,7 +195,7 @@ jit_info_table_chunk_index (MonoJitInfoTableChunk *chunk, MonoThreadHazardPointe while (left < right) { int pos = (left + right) / 2; - MonoJitInfo *ji = (MonoJitInfo *)get_hazardous_pointer((gpointer volatile*)&chunk->data [pos], hp, JIT_INFO_HAZARD_INDEX); + MonoJitInfo *ji = (MonoJitInfo *)mono_get_hazardous_pointer((gpointer volatile*)&chunk->data [pos], hp, JIT_INFO_HAZARD_INDEX); gint8 *code_end = (gint8*)ji->code_start + ji->code_size; if (addr < code_end) @@ -230,7 +228,7 @@ jit_info_table_find (MonoJitInfoTable *table, MonoThreadHazardPointers *hp, gint MonoJitInfoTableChunk *chunk = table->chunks [chunk_pos]; while (pos < chunk->num_elements) { - ji = (MonoJitInfo *)get_hazardous_pointer ((gpointer volatile*)&chunk->data [pos], hp, JIT_INFO_HAZARD_INDEX); + ji = (MonoJitInfo *)mono_get_hazardous_pointer ((gpointer volatile*)&chunk->data [pos], hp, JIT_INFO_HAZARD_INDEX); ++pos; @@ -288,7 +286,7 @@ mono_jit_info_table_find_internal (MonoDomain *domain, char *addr, gboolean try_ table by a hazard pointer and make sure that the pointer is still there after we've made it hazardous, we don't have to worry about the writer freeing the table. */ - table = (MonoJitInfoTable *)get_hazardous_pointer ((gpointer volatile*)&domain->jit_info_table, hp, JIT_INFO_TABLE_HAZARD_INDEX); + table = (MonoJitInfoTable *)mono_get_hazardous_pointer ((gpointer volatile*)&domain->jit_info_table, hp, JIT_INFO_TABLE_HAZARD_INDEX); ji = jit_info_table_find (table, hp, (gint8*)addr); if (hp) @@ -300,7 +298,7 @@ mono_jit_info_table_find_internal (MonoDomain *domain, char *addr, gboolean try_ /* Maybe its an AOT module */ if (try_aot && mono_get_root_domain () && mono_get_root_domain ()->aot_modules) { - table = (MonoJitInfoTable *)get_hazardous_pointer ((gpointer volatile*)&mono_get_root_domain ()->aot_modules, hp, JIT_INFO_TABLE_HAZARD_INDEX); + table = (MonoJitInfoTable *)mono_get_hazardous_pointer ((gpointer volatile*)&mono_get_root_domain ()->aot_modules, hp, JIT_INFO_TABLE_HAZARD_INDEX); module_ji = jit_info_table_find (table, hp, (gint8*)addr); if (module_ji) ji = jit_info_find_in_aot_func (domain, module_ji->d.image, addr); @@ -314,6 +312,21 @@ mono_jit_info_table_find_internal (MonoDomain *domain, char *addr, gboolean try_ return ji; } +/** + * mono_jit_info_table_find: + * @domain: Domain that you want to look up + * @addr: Points to an address with JITed code. + * + * Use this function to obtain a `MonoJitInfo*` object that can be used to get + * some statistics. You should provide both the @domain on which you will be + * performing the probe, and an address. Since application domains can share code + * the same address can be in use by multiple domains at once. + * + * This does not return any results for trampolines. + * + * Returns: NULL if the address does not belong to JITed code (it might be native + * code or a trampoline) or a valid pointer to a `MonoJitInfo*`. + */ MonoJitInfo* mono_jit_info_table_find (MonoDomain *domain, char *addr) { @@ -601,7 +614,7 @@ jit_info_table_add (MonoDomain *domain, MonoJitInfoTable *volatile *table_ptr, M *table_ptr = new_table; mono_memory_barrier (); domain->num_jit_info_tables++; - mono_thread_hazardous_free_or_queue (table, (MonoHazardousFreeFunc)mono_jit_info_table_free, TRUE, FALSE); + mono_thread_hazardous_try_free (table, (MonoHazardousFreeFunc)mono_jit_info_table_free); table = new_table; goto restart; @@ -657,13 +670,15 @@ mono_jit_info_table_add (MonoDomain *domain, MonoJitInfo *ji) } static MonoJitInfo* -mono_jit_info_make_tombstone (MonoJitInfo *ji) +mono_jit_info_make_tombstone (MonoJitInfoTableChunk *chunk, MonoJitInfo *ji) { MonoJitInfo *tombstone = g_new0 (MonoJitInfo, 1); tombstone->code_start = ji->code_start; tombstone->code_size = ji->code_size; tombstone->d.method = JIT_INFO_TOMBSTONE_MARKER; + tombstone->n.next_tombstone = chunk->next_tombstone; + chunk->next_tombstone = tombstone; return tombstone; } @@ -677,7 +692,7 @@ mono_jit_info_free_or_queue (MonoDomain *domain, MonoJitInfo *ji) if (domain->num_jit_info_tables <= 1) { /* Can it actually happen that we only have one table but ji is still hazardous? */ - mono_thread_hazardous_free_or_queue (ji, g_free, TRUE, FALSE); + mono_thread_hazardous_try_free (ji, g_free); } else { domain->jit_info_free_queue = g_slist_prepend (domain->jit_info_free_queue, ji); } @@ -716,7 +731,7 @@ jit_info_table_remove (MonoJitInfoTable *table, MonoJitInfo *ji) found: g_assert (chunk->data [pos] == ji); - chunk->data [pos] = mono_jit_info_make_tombstone (ji); + chunk->data [pos] = mono_jit_info_make_tombstone (chunk, ji); /* Debugging code, should be removed. */ //jit_info_table_check (table); @@ -807,18 +822,48 @@ mono_jit_info_init (MonoJitInfo *ji, MonoMethod *method, guint8 *code, int code_ ji->has_thunk_info = 1; } +/** + * mono_jit_info_get_code_start: + * @ji: the JIT information handle + * + * Use this function to get the starting address for the method described by + * the @ji object. You can use this plus the `mono_jit_info_get_code_size` + * to determine the start and end of the native code. + * + * Returns: Starting address with the native code. + */ gpointer mono_jit_info_get_code_start (MonoJitInfo* ji) { return ji->code_start; } +/** + * mono_jit_info_get_code_size: + * @ji: the JIT information handle + * + * Use this function to get the code size for the method described by + * the @ji object. You can use this plus the `mono_jit_info_get_code_start` + * to determine the start and end of the native code. + * + * Returns: Starting address with the native code. + */ int mono_jit_info_get_code_size (MonoJitInfo* ji) { return ji->code_size; } +/** + * mono_jit_info_get_method: + * @ji: the JIT information handle + * + * Use this function to get the `MonoMethod *` that backs + * the @ji object. + * + * Returns: The MonoMethod that represents the code tracked + * by @ji. + */ MonoMethod* mono_jit_info_get_method (MonoJitInfo* ji) { @@ -840,7 +885,7 @@ jit_info_next_value (gpointer value) { MonoJitInfo *info = (MonoJitInfo*)value; - return (gpointer*)&info->next_jit_code_hash; + return (gpointer*)&info->n.next_jit_code_hash; } void