Skip to content
Closed
Changes from 2 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
7 changes: 2 additions & 5 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6588,12 +6588,10 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
direct_call_target = symbol;
patch_info->type = MONO_PATCH_INFO_NONE;
} else if ((m_class_get_image (patch_info->data.method->klass) == acfg->image) && !got_only && is_direct_callable (acfg, method, patch_info)) {
#if 0
// FIXME: Currently not used. It fails as some callees require initialization.
MonoCompile *callee_cfg = (MonoCompile *)g_hash_table_lookup (acfg->method_to_cfg, cmethod);

// Don't compile inflated methods if we're doing dedup
if (acfg->aot_opts.dedup && !mono_aot_can_dedup (cmethod)) {
// Enable direct call transformation where caller's class requires no initialization and callee can specialize
if (!m_class_has_static_refs (method->klass) && mono_aot_can_specialize (cmethod)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

has_static_refs () means the class has static reference fields, not that it has an initializer.

Copy link
Member Author

Choose a reason for hiding this comment

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

The assumption is that if a caller method has static reference fields it requires initialization. Is there a better way to check if the caller method has to be initialized?

Copy link
Contributor

Choose a reason for hiding this comment

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

m_class_has_cctor (method->klass) will return whenever the class has a static ctor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this condition required ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR enables direct call transformation for MONO_PATCH_INFO_METHOD. If a caller requires initialization but got transformed, it fails with SIGSEGV as static fields are null. If a called method is invoked by reflection or can be invoked externally, it can't be transformed. m_class_has_cctor checks if the caller requires no initialization, while mono_aot_can_specialize checks if the called method isn't called externally or by using reflection.

Does that make sense?

Copy link
Member Author

@kotlarmilos kotlarmilos Mar 1, 2023

Choose a reason for hiding this comment

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

Actually it might be good to add it to is_direct_callable.

char *name = mono_aot_get_mangled_method_name (cmethod);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looked into why this was not enabled before, and i don't think this is going to work. The callee method might use GOT slots etc. which are not initialized if the method is directly called. So before this can be enabled, the AOTed code needs to be changed to init itself, the same way the llvm compiled code does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! Let's first try to enable method initialization during the invocation before proceeding with this and other direct call transformations.

mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "DIRECT CALL: %s by %s", name, method ? mono_method_full_name (method, TRUE) : "");
g_free (name);
Expand All @@ -6603,7 +6601,6 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui
patch_info->type = MONO_PATCH_INFO_NONE;
acfg->stats.direct_calls ++;
}
#endif
}

acfg->stats.all_calls ++;
Expand Down