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

[llvm] Define a separate symbol for the aot method info for every method. Pass this symbol to the init functions instead of the method index. #34009

Merged
merged 1 commit into from
Apr 6, 2020
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
29 changes: 25 additions & 4 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6865,7 +6865,10 @@ emit_method_info (MonoAotCompile *acfg, MonoCompile *cfg)
flags |= MONO_AOT_METHOD_FLAG_HAS_PATCHES;
if (needs_ctx && ctx)
flags |= MONO_AOT_METHOD_FLAG_HAS_CTX;
encode_value (flags, p, &p);
/* Saved into another table so it can be accessed without having access to this data */
cfg->aot_method_flags = flags;

encode_int (cfg->method_index, p, &p);
if (flags & MONO_AOT_METHOD_FLAG_HAS_CCTOR)
encode_klass_ref (acfg, method->klass, p, &p);
if (needs_ctx && ctx)
Expand All @@ -6884,7 +6887,15 @@ emit_method_info (MonoAotCompile *acfg, MonoCompile *cfg)

g_assert (p - buf < buf_size);

cfg->method_info_offset = add_to_blob (acfg, buf, p - buf);
if (cfg->compile_llvm) {
char *symbol = g_strdup_printf ("info_%s", cfg->llvm_method_name);
cfg->llvm_info_var = mono_llvm_emit_aot_data_aligned (symbol, buf, p - buf, 1);
g_free (symbol);
/* aot-runtime.c will use this to check whenever this is an llvm method */
cfg->method_info_offset = 0;
} else {
cfg->method_info_offset = add_to_blob (acfg, buf, p - buf);
}
g_free (buf);
}

Expand Down Expand Up @@ -10356,10 +10367,11 @@ emit_code (MonoAotCompile *acfg)
}

static void
emit_info (MonoAotCompile *acfg)
emit_method_info_table (MonoAotCompile *acfg)
{
int oindex, i;
gint32 *offsets;
guint8 *method_flags;

offsets = g_new0 (gint32, acfg->nmethods);

Expand All @@ -10377,6 +10389,14 @@ emit_info (MonoAotCompile *acfg)
acfg->stats.offsets_size += emit_offset_table (acfg, "method_info_offsets", MONO_AOT_TABLE_METHOD_INFO_OFFSETS, acfg->nmethods, 10, offsets);

g_free (offsets);

/* Emit a separate table for method flags, its needed at runtime */
method_flags = g_new0 (guint8, acfg->nmethods);
for (i = 0; i < acfg->nmethods; ++i) {
if (acfg->cfgs [i])
method_flags [acfg->cfgs [i]->method_index] = acfg->cfgs [i]->aot_method_flags;
}
emit_aot_data (acfg, MONO_AOT_TABLE_FLAGS_TABLE, "method_flags_table", method_flags, acfg->nmethods);
}

#endif /* #if !defined(DISABLE_AOT) && !defined(DISABLE_JIT) */
Expand Down Expand Up @@ -11397,6 +11417,7 @@ emit_aot_file_info (MonoAotCompile *acfg, MonoAotFileInfo *info)
symbols [sindex ++] = NULL;
symbols [sindex ++] = "image_table";
symbols [sindex ++] = "weak_field_indexes";
symbols [sindex ++] = "method_flags_table";
}

symbols [sindex ++] = "mem_end";
Expand Down Expand Up @@ -14161,7 +14182,7 @@ emit_aot_image (MonoAotCompile *acfg)

emit_code (acfg);

emit_info (acfg);
emit_method_info_table (acfg);

emit_extra_methods (acfg);

Expand Down
47 changes: 27 additions & 20 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static void
compute_llvm_code_range (MonoAotModule *amodule, guint8 **code_start, guint8 **code_end);

static gboolean
init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, MonoClass *init_class, MonoError *error);
init_method (MonoAotModule *amodule, gpointer info, guint32 method_index, MonoMethod *method, MonoClass *init_class, MonoError *error);

static MonoJumpInfo*
decode_patches (MonoAotModule *amodule, MonoMemPool *mp, int n_patches, gboolean llvm, guint32 *got_offsets);
Expand Down Expand Up @@ -4321,9 +4321,12 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM

if (!(is_llvm_code (amodule, code) && (amodule->info.flags & MONO_AOT_FILE_FLAG_LLVM_ONLY)) ||
(mono_llvm_only && method && method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED)) {
res = init_method (amodule, method_index, method, NULL, error);
if (!res)
goto cleanup;
/* offset == 0 means its llvm code */
if (mono_aot_get_offset (amodule->method_info_offsets, method_index) != 0) {
res = init_method (amodule, NULL, method_index, method, NULL, error);
if (!res)
goto cleanup;
}
}

if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) {
Expand All @@ -4345,11 +4348,7 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM
}

if (mono_llvm_only) {
guint8 *info, *p;

info = &amodule->blob [mono_aot_get_offset (amodule->method_info_offsets, method_index)];
p = info;
guint8 flags = decode_value (p, &p);
guint8 flags = amodule->info.method_flags_table [method_index];
/* The caller needs to looks this up, but its hard to do without constructing the full MonoJitInfo, so save it here */
if (flags & MONO_AOT_METHOD_FLAG_GSHAREDVT_VARIABLE) {
mono_aot_lock ();
Expand Down Expand Up @@ -4600,7 +4599,7 @@ mono_aot_find_method_index (MonoMethod *method)
}

static gboolean
init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, MonoClass *init_class, MonoError *error)
init_method (MonoAotModule *amodule, gpointer info, guint32 method_index, MonoMethod *method, MonoClass *init_class, MonoError *error)
{
MonoDomain *domain = mono_domain_get ();
MonoMemPool *mp;
Expand All @@ -4609,7 +4608,7 @@ init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, M
int pindex, n_patches;
guint8 *p;
MonoJitInfo *jinfo = NULL;
guint8 *code, *info;
guint8 *code;
MonoGenericContext *context;
MonoGenericContext ctx;

Expand All @@ -4621,12 +4620,21 @@ init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, M

error_init (error);

code = (guint8 *)amodule->methods [method_index];
info = &amodule->blob [mono_aot_get_offset (amodule->method_info_offsets, method_index)];
if (!info)
info = &amodule->blob [mono_aot_get_offset (amodule->method_info_offsets, method_index)];

p = info;
p = (guint8*)info;

// FIXME: Is this aligned ?
guint32 encoded_method_index = *(guint32*)p;
if (method_index)
g_assert (method_index == encoded_method_index);
method_index = encoded_method_index;
p += 4;

code = (guint8 *)amodule->methods [method_index];
guint8 flags = amodule->info.method_flags_table [method_index];

guint8 flags = decode_value (p, &p);
if (flags & MONO_AOT_METHOD_FLAG_HAS_CCTOR)
klass_to_run_ctor = decode_klass_ref (amodule, p, &p, error);
if (!is_ok (error))
Expand Down Expand Up @@ -4756,17 +4764,16 @@ init_method (MonoAotModule *amodule, guint32 method_index, MonoMethod *method, M
}

/*
* mono_aot_init_llvmonly_method:
* mono_aot_init_llvm_method:
*
* Initialize the method identified by METHOD_INDEX in llvmonly mode.
* Initialize the LLVM method identified by METHOD_INFO.
*/
gboolean
mono_aot_init_llvmonly_method (gpointer aot_module, guint32 method_index, MonoClass *init_class, MonoError *error)
mono_aot_init_llvm_method (gpointer aot_module, gpointer method_info, MonoClass *init_class, MonoError *error)
{
MonoAotModule *amodule = (MonoAotModule*)aot_module;
MonoMethod *method = NULL;

return init_method (amodule, method_index, method, init_class, error);
return init_method (amodule, method_info, 0, NULL, init_class, error);
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/mono/mono/mini/aot-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef enum {
MONO_AOT_TABLE_EXTRA_METHOD_INFO_OFFSETS,
MONO_AOT_TABLE_EXTRA_METHOD_TABLE,
MONO_AOT_TABLE_WEAK_FIELD_INDEXES,
MONO_AOT_TABLE_FLAGS_TABLE,
MONO_AOT_TABLE_NUM
} MonoAotFileTable;

Expand Down Expand Up @@ -144,6 +145,7 @@ typedef struct MonoAotFileInfo
gpointer image_table;
/* Points to an array of weak field indexes */
gpointer weak_field_indexes;
guint8 *method_flags_table;

gpointer mem_end;
/* The GUID of the assembly which the AOT image was generated from */
Expand Down Expand Up @@ -271,7 +273,7 @@ gboolean mono_aot_is_pagefault (void *ptr);
void mono_aot_handle_pagefault (void *ptr);

guint32 mono_aot_find_method_index (MonoMethod *method);
gboolean mono_aot_init_llvmonly_method (gpointer amodule, guint32 method_index, MonoClass *init_class, MonoError *error);
gboolean mono_aot_init_llvm_method (gpointer aot_module, gpointer method_info, MonoClass *init_class, MonoError *error);
GHashTable *mono_aot_get_weak_field_indexes (MonoImage *image);
MonoAotMethodFlags mono_aot_get_method_flags (guint8 *code);

Expand Down
20 changes: 7 additions & 13 deletions src/mono/mono/mini/llvmonly-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,16 @@ mini_llvmonly_resolve_iface_call_gsharedvt (MonoObject *this_obj, int imt_slot,
return res;
}

static void
init_llvmonly_method (MonoAotModule *amodule, guint32 method_index, MonoClass *init_class)
/* Called from LLVM code to initialize a method */
// FIXME: This should be somewhere else
void
mini_llvm_init_method (MonoAotFileInfo *info, gpointer aot_module, gpointer method_info, MonoVTable *vtable)
{
ERROR_DECL (error);
gboolean res;
MonoAotModule *amodule = (MonoAotModule *)aot_module;
ERROR_DECL (error);

res = mono_aot_init_llvmonly_method (amodule, method_index, init_class, error);
res = mono_aot_init_llvm_method (amodule, method_info, vtable ? vtable->klass : NULL, error);
if (!res || !is_ok (error)) {
MonoException *ex = mono_error_convert_to_exception (error);
if (ex) {
Expand All @@ -788,15 +791,6 @@ init_llvmonly_method (MonoAotModule *amodule, guint32 method_index, MonoClass *i
}
}

/* Called from generated code to initialize a method */
void
mini_llvm_init_method (MonoAotFileInfo *info, gpointer aot_module, guint32 method_index, MonoVTable *vtable)
{
MonoAotModule *amodule = (MonoAotModule *)aot_module;

init_llvmonly_method (amodule, method_index, vtable ? vtable->klass : NULL);
}

static GENERATE_GET_CLASS_WITH_CACHE (nullref, "System", "NullReferenceException")

void
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/llvmonly-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ G_EXTERN_C void mini_llvmonly_init_delegate (MonoDelegate *del);
G_EXTERN_C void mini_llvmonly_init_delegate_virtual (MonoDelegate *del, MonoObject *target, MonoMethod *method);

/* Used for regular llvm as well */
G_EXTERN_C void mini_llvm_init_method (MonoAotFileInfo *info, gpointer aot_module, guint32 method_index, MonoVTable *vtable);
G_EXTERN_C void mini_llvm_init_method (MonoAotFileInfo *info, gpointer aot_module, gpointer method_info, MonoVTable *vtable);

G_EXTERN_C void mini_llvmonly_throw_nullref_exception (void);

Expand Down
Loading