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][aot] Enable direct call transformation for MONO_PATCH_INFO_METHOD #82711

Conversation

kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented Feb 27, 2023

This PR contributes to #82224 by enabling direct call transformation for MONO_PATCH_INFO_METHOD where caller requires no initialization.

// Enable direct call transformation where caller's class requires no initialization
if (!m_class_has_static_refs (method->klass)) {
// 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.

@kotlarmilos kotlarmilos changed the title [mono][aot] Enable direct call transformation where caller requires no initialization [mono][aot] Enable direct call transformation for MONO_PATCH_INFO_METHOD Mar 2, 2023
@kotlarmilos
Copy link
Member Author

Failures shouldn't be related.

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)) {
if (!m_class_has_cctor (method->klass) && mono_aot_can_specialize (callee_cfg->method)) {
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.

@kotlarmilos kotlarmilos added the blocked Issue/PR is blocked on something - see comments label Mar 3, 2023
@kotlarmilos
Copy link
Member Author

This issue is blocked by #83377. Closing it until the prolog method initialization is implemented.

@kotlarmilos kotlarmilos closed this Apr 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-AOT-mono blocked Issue/PR is blocked on something - see comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants