Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono] Add mono hot reload support for updating parameter name #85796

Merged
merged 15 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions src/mono/mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -5103,17 +5103,17 @@ mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index)
/* FIXME: Index translation */

gboolean found = tdef->base && mono_binary_search (&loc, tdef->base, table_info_get_rows (tdef), tdef->row_size, table_locator) != NULL;
if (!found && !meta->has_updates)
return 0;

if (G_UNLIKELY (meta->has_updates)) {
if (!found && (mono_metadata_table_num_rows (meta, MONO_TABLE_CUSTOMATTRIBUTE) > table_info_get_rows (tdef))) {
if (!mono_metadata_update_metadata_linear_search (meta, tdef, &loc, table_locator))
return 0;
} else {
if (!found)
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
if (G_UNLIKELY (!meta->has_updates))
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
return 0;
else {
if ((mono_metadata_table_num_rows (meta, MONO_TABLE_CUSTOMATTRIBUTE) > table_info_get_rows (tdef))) {
if (!mono_metadata_update_metadata_linear_search (meta, tdef, &loc, table_locator))
return 0;
} else {
return 0;
}
}
}

/* Find the first entry by searching backwards */
while ((loc.result > 0) && (mono_metadata_decode_row_col (tdef, loc.result - 1, MONO_CUSTOM_ATTR_PARENT) == index))
Expand Down
31 changes: 18 additions & 13 deletions src/mono/mono/metadata/reflection-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ typedef struct {
uint32_t generation; /* 0 is normal; hot reload may change it */
} ReflectedEntry;

enum {
MONO_REFL_CACHE_DEFAULT = 0,
MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE = 1,
};

gboolean
mono_reflected_equal (gconstpointer a, gconstpointer b);

Expand All @@ -48,7 +53,7 @@ free_reflected_entry (ReflectedEntry *entry)
}

static inline MonoObject*
cache_object (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, MonoObject* o)
cache_object (MonoMemoryManager *mem_manager, int flags, MonoClass *klass, gpointer item, MonoObject* o)
{
MonoObject *obj;
ReflectedEntry pe;
Expand All @@ -61,7 +66,7 @@ cache_object (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, M
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
if (G_UNLIKELY(mono_metadata_has_updates()))
if (G_UNLIKELY(mono_metadata_has_updates()) && ((flags & MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE) == 0))
e->generation = mono_metadata_update_get_thread_generation();
else
e->generation = 0;
Expand All @@ -73,7 +78,7 @@ cache_object (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, M
}

static inline MonoObjectHandle
cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, MonoObjectHandle o)
cache_object_handle (MonoMemoryManager *mem_manager, int flags, MonoClass *klass, gpointer item, MonoObjectHandle o)
{
MonoObjectHandle obj;
ReflectedEntry pe;
Expand All @@ -89,7 +94,7 @@ cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
if (G_UNLIKELY(mono_metadata_has_updates()))
if (G_UNLIKELY(mono_metadata_has_updates()) && ((flags & MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE) == 0))
e->generation = mono_metadata_update_get_thread_generation();
else
e->generation = 0;
Expand All @@ -102,7 +107,7 @@ cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
if (G_UNLIKELY(mono_metadata_has_updates()))
if (G_UNLIKELY(mono_metadata_has_updates()) && ((flags & MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE) == 0))
e->generation = mono_metadata_update_get_thread_generation();
else
e->generation = 0;
Expand All @@ -114,11 +119,11 @@ cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
return obj;
}

#define CACHE_OBJECT(t,mem_manager,p,o,k) ((t) (cache_object ((mem_manager), (k), (p), (o))))
#define CACHE_OBJECT_HANDLE(t,mem_manager,p,o,k) (MONO_HANDLE_CAST (t, cache_object_handle ((mem_manager), (k), (p), (o))))
#define CACHE_OBJECT(t,mem_manager,flags,p,o,k) ((t) (cache_object ((mem_manager), (flags), (k), (p), (o))))
#define CACHE_OBJECT_HANDLE(t,mem_manager,flags,p,o,k) (MONO_HANDLE_CAST (t, cache_object_handle ((mem_manager), (flags), (k), (p), (o))))

static inline MonoObjectHandle
check_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item)
check_object_handle (MonoMemoryManager *mem_manager, int flags, MonoClass *klass, gpointer item)
{
MonoObjectHandle obj_handle;
gpointer orig_e, orig_value;
Expand Down Expand Up @@ -164,22 +169,22 @@ check_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
typedef MonoObjectHandle (*ReflectionCacheConstructFunc_handle) (MonoClass*, gpointer, gpointer, MonoError *);

static inline MonoObjectHandle
check_or_construct_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, gpointer user_data, MonoError *error, ReflectionCacheConstructFunc_handle construct)
check_or_construct_handle (MonoMemoryManager *mem_manager, int flags, MonoClass *klass, gpointer item, gpointer user_data, MonoError *error, ReflectionCacheConstructFunc_handle construct)
{
error_init (error);
MonoObjectHandle obj = check_object_handle (mem_manager, klass, item);
MonoObjectHandle obj = check_object_handle (mem_manager, flags, klass, item);
if (!MONO_HANDLE_IS_NULL (obj))
return obj;
MONO_HANDLE_ASSIGN (obj, construct (klass, item, user_data, error));
return_val_if_nok (error, NULL_HANDLE);
if (MONO_HANDLE_IS_NULL (obj))
return obj;
/* note no caching if there was an error in construction */
return cache_object_handle (mem_manager, klass, item, obj);
return cache_object_handle (mem_manager, flags, klass, item, obj);
}

#define CHECK_OR_CONSTRUCT_HANDLE(type,mem_manager, item,klass,construct,user_data) \
#define CHECK_OR_CONSTRUCT_HANDLE(type,mem_manager,flags,item,klass,construct,user_data) \
(MONO_HANDLE_CAST (type, check_or_construct_handle ( \
(mem_manager), (klass), (item), (user_data), error, (ReflectionCacheConstructFunc_handle) (construct))))
(mem_manager), (flags), (klass), (item), (user_data), error, (ReflectionCacheConstructFunc_handle) (construct))))

#endif /*__MONO_METADATA_REFLECTION_CACHE_H__*/
16 changes: 8 additions & 8 deletions src/mono/mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ MonoReflectionAssemblyHandle
mono_assembly_get_object_handle (MonoAssembly *assembly, MonoError *error)
{
error_init (error);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionAssembly, m_image_get_mem_manager (assembly->image), assembly, NULL, assembly_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionAssembly, m_image_get_mem_manager (assembly->image), MONO_REFL_CACHE_DEFAULT, assembly, NULL, assembly_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -311,7 +311,7 @@ MonoReflectionModuleHandle
mono_module_get_object_handle (MonoImage *image, MonoError *error)
{
error_init (error);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionModule, m_image_get_mem_manager (image), image, NULL, module_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionModule, m_image_get_mem_manager (image), MONO_REFL_CACHE_DEFAULT, image, NULL, module_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -670,7 +670,7 @@ mono_method_get_object_handle (MonoMethod *method, MonoClass *refclass, MonoErro
refclass = method->klass;

// FIXME: For methods/params etc., use the mem manager for refclass or a merged one ?
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionMethod, m_method_get_mem_manager (method), method, refclass, method_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionMethod, m_method_get_mem_manager (method), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, method, refclass, method_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}
/*
* mono_method_get_object_checked:
Expand Down Expand Up @@ -776,7 +776,7 @@ MonoReflectionFieldHandle
mono_field_get_object_handle (MonoClass *klass, MonoClassField *field, MonoError *error)
{
error_init (error);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionField, m_class_get_mem_manager (m_field_get_parent (field)), field, klass, field_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionField, m_class_get_mem_manager (m_field_get_parent (field)), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, field, klass, field_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

/*
Expand Down Expand Up @@ -844,7 +844,7 @@ property_object_construct (MonoClass *klass, MonoProperty *property, gpointer us
MonoReflectionPropertyHandle
mono_property_get_object_handle (MonoClass *klass, MonoProperty *property, MonoError *error)
{
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionProperty, m_class_get_mem_manager (property->parent), property, klass, property_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionProperty, m_class_get_mem_manager (property->parent), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, property, klass, property_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -909,7 +909,7 @@ MonoReflectionEventHandle
mono_event_get_object_handle (MonoClass *klass, MonoEvent *event, MonoError *error)
{
error_init (error);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionEvent, m_class_get_mem_manager (event->parent), event, klass, event_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionEvent, m_class_get_mem_manager (event->parent), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, event, klass, event_object_construct, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down Expand Up @@ -1167,7 +1167,7 @@ mono_param_get_objects_internal (MonoMethod *method, MonoClass *refclass, MonoEr
/* Note: the cache is based on the address of the signature into the method
* since we already cache MethodInfos with the method as keys.
*/
return CHECK_OR_CONSTRUCT_HANDLE (MonoArray, m_method_get_mem_manager (method), &method->signature, refclass, param_objects_construct, method);
return CHECK_OR_CONSTRUCT_HANDLE (MonoArray, m_method_get_mem_manager (method), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, &method->signature, refclass, param_objects_construct, method);
fail:
return MONO_HANDLE_NEW (MonoArray, NULL);
}
Expand Down Expand Up @@ -1392,7 +1392,7 @@ MonoReflectionMethodBodyHandle
mono_method_body_get_object_handle (MonoMethod *method, MonoError *error)
{
error_init (error);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionMethodBody, m_method_get_mem_manager (method), method, NULL, method_body_object_construct, NULL);
return CHECK_OR_CONSTRUCT_HANDLE (MonoReflectionMethodBody, m_method_get_mem_manager (method), MONO_REFL_CACHE_NO_HOT_RELOAD_INVALIDATE, method, NULL, method_body_object_construct, NULL);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,13 +1188,13 @@ mono_image_create_token (MonoDynamicImage *assembly, MonoObjectHandle obj,
static gpointer
register_assembly (MonoReflectionAssembly *res, MonoAssembly *assembly)
{
return CACHE_OBJECT (MonoReflectionAssembly *, mono_mem_manager_get_ambient (), assembly, &res->object, NULL);
return CACHE_OBJECT (MonoReflectionAssembly *, mono_mem_manager_get_ambient (), MONO_REFL_CACHE_DEFAULT, assembly, &res->object, NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

static MonoReflectionModuleBuilderHandle
register_module (MonoReflectionModuleBuilderHandle res, MonoDynamicImage *module)
{
return CACHE_OBJECT_HANDLE (MonoReflectionModuleBuilder, mono_mem_manager_get_ambient (), module, MONO_HANDLE_CAST (MonoObject, res), NULL);
return CACHE_OBJECT_HANDLE (MonoReflectionModuleBuilder, mono_mem_manager_get_ambient (), MONO_REFL_CACHE_DEFAULT, module, MONO_HANDLE_CAST (MonoObject, res), NULL);
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
}

/*
Expand Down