Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions mono/metadata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,13 @@ common_sources = \
w32handle-namespace.c \
w32handle.h \
w32handle.c \
w32error.h
w32error.h \
reflection.c \
dynamic-image.c \
sre.c \
sre-encode.c \
sre-save.c \
custom-attrs.c

# These source files have compile time dependencies on GC code
gc_dependent_sources = \
Expand All @@ -285,14 +291,7 @@ gc_dependent_sources = \
monitor.c \
mono-hash.c \
mono-conc-hash.c \
object.c \
dynamic-image.c \
sre.c \
sre-encode.c \
sre-save.c \
custom-attrs.c \
reflection.c

object.c

boehm_sources = \
boehm-gc.c
Expand Down
29 changes: 17 additions & 12 deletions mono/metadata/reflection-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ reflected_equal (gconstpointer a, gconstpointer b);
guint
reflected_hash (gconstpointer a);

#ifdef HAVE_BOEHM_GC
/* ReflectedEntry doesn't need to be GC tracked */
#define ALLOC_REFENTRY g_new0 (ReflectedEntry, 1)
#define FREE_REFENTRY(entry) g_free ((entry))
#define REFENTRY_REQUIRES_CLEANUP
#else
#define ALLOC_REFENTRY (ReflectedEntry *)mono_mempool_alloc (domain->mp, sizeof (ReflectedEntry))
/* FIXME: */
#define FREE_REFENTRY(entry)
#endif
static inline ReflectedEntry*
alloc_reflected_entry (MonoDomain *domain)
{
if (!mono_gc_is_moving ())
return g_new0 (ReflectedEntry, 1);
else
return (ReflectedEntry *)mono_mempool_alloc (domain->mp, sizeof (ReflectedEntry));
}
Copy link
Contributor Author

@vargaz vargaz Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the old code did, but I have no idea why. Its probably a leftover. Allocating from the mempool should work on boehm too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree mempool should work on Boehm as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to use malloc, so we can free the memory for dynamic methods, i.e. from mono_method_clear_object ().


static void
free_reflected_entry (ReflectedEntry *entry)
{
if (!mono_gc_is_moving ())
g_free (entry);
}

static inline MonoObject*
cache_object (MonoDomain *domain, MonoClass *klass, gpointer item, MonoObject* o)
Expand All @@ -55,7 +60,7 @@ cache_object (MonoDomain *domain, MonoClass *klass, gpointer item, MonoObject* o

obj = (MonoObject*) mono_conc_g_hash_table_lookup (domain->refobject_hash, &pe);
if (obj == NULL) {
ReflectedEntry *e = ALLOC_REFENTRY;
ReflectedEntry *e = alloc_reflected_entry (domain);
e->item = item;
e->refclass = klass;
mono_conc_g_hash_table_insert (domain->refobject_hash, e, o);
Expand All @@ -79,7 +84,7 @@ cache_object_handle (MonoDomain *domain, MonoClass *klass, gpointer item, MonoOb

MonoObjectHandle obj = MONO_HANDLE_NEW (MonoObject, mono_conc_g_hash_table_lookup (domain->refobject_hash, &pe));
if (MONO_HANDLE_IS_NULL (obj)) {
ReflectedEntry *e = ALLOC_REFENTRY;
ReflectedEntry *e = alloc_reflected_entry (domain);
e->item = item;
e->refclass = klass;
mono_conc_g_hash_table_insert (domain->refobject_hash, e, MONO_HANDLE_RAW (o));
Expand Down
13 changes: 2 additions & 11 deletions mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ mono_class_free_ref_info (MonoClass *klass)
}
}


/**
* mono_custom_attrs_free:
*/
Expand All @@ -156,7 +155,6 @@ mono_custom_attrs_free (MonoCustomAttrInfo *ainfo)
g_free (ainfo);
}


gboolean
reflected_equal (gconstpointer a, gconstpointer b)
{
Expand All @@ -175,7 +173,6 @@ reflected_hash (gconstpointer a) {
return seed;
}


static void
clear_cached_object (MonoDomain *domain, gpointer o, MonoClass *klass)
{
Expand All @@ -189,34 +186,28 @@ clear_cached_object (MonoDomain *domain, gpointer o, MonoClass *klass)

if (mono_conc_g_hash_table_lookup_extended (domain->refobject_hash, &pe, &orig_pe, &orig_value)) {
mono_conc_g_hash_table_remove (domain->refobject_hash, &pe);
FREE_REFENTRY (orig_pe);
free_reflected_entry (orig_pe);
}
}
mono_domain_unlock (domain);
}

#ifdef REFENTRY_REQUIRES_CLEANUP
static void
cleanup_refobject_hash (gpointer key, gpointer value, gpointer user_data)
{
FREE_REFENTRY (key);
free_reflected_entry (key);
}
#endif

void
mono_reflection_cleanup_domain (MonoDomain *domain)
{
if (domain->refobject_hash) {
/*let's avoid scanning the whole hashtable if not needed*/
#ifdef REFENTRY_REQUIRES_CLEANUP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joncham Is this bit okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay

mono_conc_g_hash_table_foreach (domain->refobject_hash, cleanup_refobject_hash, NULL);
#endif
mono_conc_g_hash_table_destroy (domain->refobject_hash);
domain->refobject_hash = NULL;
}
}


/**
* mono_assembly_get_object:
* \param domain an app domain
Expand Down