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
24 changes: 1 addition & 23 deletions src/mono/mono/component/hot_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,29 +1600,7 @@ apply_enclog_pass1 (MonoImage *image_base, MonoImage *image_dmeta, DeltaInfo *de
}
case MONO_TABLE_PARAM: {
*should_invalidate_transformed_code = true;
if (!is_addition) {
/* We only allow modifications where the parameter name doesn't change. */
uint32_t base_param [MONO_PARAM_SIZE];
uint32_t upd_param [MONO_PARAM_SIZE];
int mapped_token = hot_reload_relative_delta_index (image_dmeta, delta_info, mono_metadata_make_token (token_table, token_index));
g_assert (mapped_token != -1);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "row[0x%02x]:0x%08x PARAM update. mapped index = 0x%08x\n", i, log_token, mapped_token);

mono_metadata_decode_row (&image_dmeta->tables [MONO_TABLE_PARAM], mapped_token - 1, upd_param, MONO_PARAM_SIZE);
mono_metadata_decode_row (&image_base->tables [MONO_TABLE_PARAM], token_index - 1, base_param, MONO_PARAM_SIZE);

const char *base_name = mono_metadata_string_heap (image_base, base_param [MONO_PARAM_NAME]);
const char *upd_name = mono_metadata_string_heap (image_base, upd_param [MONO_PARAM_NAME]);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_METADATA_UPDATE, "row[0x%02x: 0x%08x PARAM update: seq = %d (base = %d), name = '%s' (base = '%s')\n", i, log_token, upd_param [MONO_PARAM_SEQUENCE], base_param [MONO_PARAM_SEQUENCE], upd_name, base_name);
if (strcmp (base_name, upd_name) != 0 || base_param [MONO_PARAM_SEQUENCE] != upd_param [MONO_PARAM_SEQUENCE]) {
mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_METADATA_UPDATE, "row[0x%02x]:0x%08x we do not support patching of existing PARAM table cols.", i, log_token);
mono_error_set_type_load_name (error, NULL, image_base->name, "EnC: we do not support patching of existing PARAM table cols. token=0x%08x", log_token);
unsupported_edits = TRUE;
continue;
}
break;
} else
break; /* added a row. ok */
break;
}
case MONO_TABLE_TYPEDEF: {
*should_invalidate_transformed_code = true;
Expand Down
6 changes: 5 additions & 1 deletion src/mono/mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -5107,8 +5107,12 @@ mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index)
return 0;

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

/* Find the first entry by searching backwards */
Expand Down
24 changes: 24 additions & 0 deletions src/mono/mono/metadata/reflection-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mono/metadata/mono-hash.h>
#include <mono/metadata/mempool.h>
#include <mono/utils/mono-error-internals.h>
#include <mono/metadata/metadata-update.h>

/*
* We need to return always the same object for MethodInfo, FieldInfo etc..
Expand All @@ -22,6 +23,7 @@
typedef struct {
gpointer item;
MonoClass *refclass;
uint32_t generation; /* 0 is normal; hot reload may change it */
} ReflectedEntry;

gboolean
Expand Down Expand Up @@ -59,6 +61,7 @@ cache_object (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item, M
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
e->generation = mono_metadata_update_get_thread_generation();
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
mono_conc_g_hash_table_insert (mem_manager->refobject_hash, e, o);
obj = o;
}
Expand All @@ -83,6 +86,7 @@ cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
e->generation = mono_metadata_update_get_thread_generation();
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
mono_conc_g_hash_table_insert (mem_manager->refobject_hash, e, MONO_HANDLE_RAW (o));
MONO_HANDLE_ASSIGN (obj, o);
}
Expand All @@ -92,6 +96,7 @@ cache_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
ReflectedEntry *e = alloc_reflected_entry (mem_manager);
e->item = item;
e->refclass = klass;
e->generation = mono_metadata_update_get_thread_generation();
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
mono_weak_hash_table_insert (mem_manager->weak_refobject_hash, e, MONO_HANDLE_RAW (o));
MONO_HANDLE_ASSIGN (obj, o);
}
Expand All @@ -107,6 +112,7 @@ static inline MonoObjectHandle
check_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer item)
{
MonoObjectHandle obj_handle;
gpointer orig_e, orig_value;
ReflectedEntry e;
e.item = item;
e.refclass = klass;
Expand All @@ -123,6 +129,24 @@ check_object_handle (MonoMemoryManager *mem_manager, MonoClass *klass, gpointer
MonoWeakHashTable *hash = mem_manager->weak_refobject_hash;
obj_handle = MONO_HANDLE_NEW (MonoObject, (MonoObject *)mono_weak_hash_table_lookup (hash, &e));
}

if (!mem_manager->collectible) {
MonoConcGHashTable *hash = mem_manager->refobject_hash;
if (mono_conc_g_hash_table_lookup_extended (hash, &e, &orig_e, &orig_value))
if (((ReflectedEntry *)orig_e)->generation < mono_metadata_update_get_thread_generation()) {
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
mono_conc_g_hash_table_remove (hash, &e);
free_reflected_entry ((ReflectedEntry *)orig_e);
obj_handle = MONO_HANDLE_NEW (MonoObject, NULL);
} else {
obj_handle = MONO_HANDLE_NEW (MonoObject, (MonoObject *)orig_value);
}
else {
obj_handle = MONO_HANDLE_NEW (MonoObject, NULL);
}
} else {
MonoWeakHashTable *hash = mem_manager->weak_refobject_hash;
obj_handle = MONO_HANDLE_NEW (MonoObject, (MonoObject *)mono_weak_hash_table_lookup (hash, &e));
lambdageek marked this conversation as resolved.
Show resolved Hide resolved
}
mono_mem_manager_unlock (mem_manager);

return obj_handle;
Expand Down