Skip to content
Browse files

Add a cache for virtual generic thunks to avoid freeing those created…

… by AOT.
  • Loading branch information...
1 parent 4197f5e commit 03c1afc8385aef5c9f630846cfc1e9ca03b347ae @vargaz vargaz committed Mar 16, 2011
Showing with 23 additions and 0 deletions.
  1. +2 −0 mono/metadata/domain-internals.h
  2. +4 −0 mono/metadata/domain.c
  3. +17 −0 mono/metadata/object.c
View
2 mono/metadata/domain-internals.h
@@ -252,6 +252,8 @@ struct _MonoDomain {
GHashTable *generic_virtual_cases;
MonoThunkFreeList **thunk_free_lists;
+ GHashTable *generic_virtual_thunks;
+
/* Information maintained by the JIT engine */
gpointer runtime_info;
View
4 mono/metadata/domain.c
@@ -1998,6 +1998,10 @@ mono_domain_free (MonoDomain *domain, gboolean force)
g_hash_table_destroy (domain->generic_virtual_cases);
domain->generic_virtual_cases = NULL;
}
+ if (domain->generic_virtual_thunks) {
+ g_hash_table_destroy (domain->generic_virtual_thunks);
+ domain->generic_virtual_thunks = NULL;
+ }
DeleteCriticalSection (&domain->finalizable_objects_hash_lock);
DeleteCriticalSection (&domain->assemblies_lock);
View
17 mono/metadata/object.c
@@ -1499,6 +1499,12 @@ mono_method_alloc_generic_virtual_thunk (MonoDomain *domain, int size)
p = mono_domain_code_reserve (domain, size);
*p = size;
+ mono_domain_lock (domain);
+ if (!domain->generic_virtual_thunks)
+ domain->generic_virtual_thunks = g_hash_table_new (NULL, NULL);
+ g_hash_table_insert (domain->generic_virtual_thunks, p, p);
+ mono_domain_unlock (domain);
+
return p + 1;
}
@@ -1510,7 +1516,18 @@ invalidate_generic_virtual_thunk (MonoDomain *domain, gpointer code)
{
guint32 *p = code;
MonoThunkFreeList *l = (MonoThunkFreeList*)(p - 1);
+ gboolean found = FALSE;
+ mono_domain_lock (domain);
+ if (!domain->generic_virtual_thunks)
+ domain->generic_virtual_thunks = g_hash_table_new (NULL, NULL);
+ if (g_hash_table_lookup (domain->generic_virtual_thunks, l))
+ found = TRUE;
+ mono_domain_unlock (domain);
+
+ if (!found)
+ /* Not allocated by mono_method_alloc_generic_virtual_thunk (), i.e. AOT */
+ return;
init_thunk_free_lists (domain);
while (domain->thunk_free_lists [0] && domain->thunk_free_lists [0]->length >= MAX_WAIT_LENGTH) {

0 comments on commit 03c1afc

Please sign in to comment.
Something went wrong with that request. Please try again.