Skip to content
New issue

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

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

Already on GitHub? # to your account

[mono][aot] Remove method body for inlined methods #82907

Closed
Tracked by #80938
kotlarmilos opened this issue Mar 2, 2023 · 7 comments
Closed
Tracked by #80938

[mono][aot] Remove method body for inlined methods #82907

kotlarmilos opened this issue Mar 2, 2023 · 7 comments
Assignees
Labels
area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads
Milestone

Comments

@kotlarmilos
Copy link
Member

When a method is inlined, its implicit reference still exists in a method_addresses table and native linker can't remove its body. For example, if _HelloWorld_MyGen_Bar is inlined and not called indirectly, then its method body is not needed during the runtime.

_mono_aot_HelloWorldmethod_addresses:
0000000000003938    bl    _HelloWorld_Program_Foo_string__
000000000000393c    bl    _HelloWorld_Program__ctor
0000000000003940    bl    _HelloWorld_MyGen_Bar
...
_HelloWorld_MyGen_Bar:
0000000000003970    adrp    x16, 5 ; 0x8000
0000000000003974    add    x16, x16, #0x2a8
0000000000003978    ldr    x16, [x16, #0xb8]
...

/cc: @ivanpovazan

@kotlarmilos kotlarmilos added area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads labels Mar 2, 2023
@kotlarmilos kotlarmilos added this to the 8.0.0 milestone Mar 2, 2023
@kotlarmilos kotlarmilos self-assigned this Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

When a method is inlined, its implicit reference still exists in a method_addresses table and native linker can't remove its body. For example, if _HelloWorld_MyGen_Bar is inlined and not called indirectly, then its method body is not needed during the runtime.

_mono_aot_HelloWorldmethod_addresses:
0000000000003938    bl    _HelloWorld_Program_Foo_string__
000000000000393c    bl    _HelloWorld_Program__ctor
0000000000003940    bl    _HelloWorld_MyGen_Bar
...
_HelloWorld_MyGen_Bar:
0000000000003970    adrp    x16, 5 ; 0x8000
0000000000003974    add    x16, x16, #0x2a8
0000000000003978    ldr    x16, [x16, #0xb8]
...

/cc: @ivanpovazan

Author: kotlarmilos
Assignees: kotlarmilos
Labels:

area-Codegen-AOT-mono, size-reduction

Milestone: 8.0.0

@kotlarmilos
Copy link
Member Author

@ivanpovazan According to your experiment, does the following code snipped in emit_code method populate method_addresses table?

for (guint32 i = 0; i < acfg->nmethods; ++i) {
#ifdef MONO_ARCH_AOT_SUPPORTED
if (acfg->flags & MONO_AOT_FILE_FLAG_CODE_EXEC_ONLY) {
if (acfg->cfgs [i])
emit_pointer (acfg, acfg->cfgs [i]->asm_symbol);
else
emit_pointer (acfg, NULL);
} else {
if (acfg->cfgs [i])
arch_emit_label_address (acfg, acfg->cfgs [i]->asm_symbol, FALSE, acfg->thumb_mixed && acfg->cfgs [i]->compile_llvm, NULL, &acfg->call_table_entry_size);
else
arch_emit_label_address (acfg, symbol, FALSE, FALSE, NULL, &acfg->call_table_entry_size);
}
#endif
}
sprintf (symbol, "method_addresses_end");

@ivanpovazan
Copy link
Member

@kotlarmilos, yes here is the change from the experiment:

https://github.com/ivanpovazan/runtime/blob/38eabec1a6320287f754a2e05b19787664c55df5/src/mono/mono/mini/aot-compiler.c#L10782-L10787

@kotlarmilos
Copy link
Member Author

To enable the optimization, the AOT compiler should check if a method isn't called through reflection in can_specialize (as done in the experiment) and if all call sites inline the method, as inline_info property indicates that it could be done, but it might or might not happen.

can_specialize depends on the linker adding annotations to methods, which needs to be implemented/fixed. @ivanpovazan Do you perhaps know what is the status of --explicit-reflection flag in the linker?

@ivanpovazan
Copy link
Member

can_specialize depends on the linker adding annotations to methods, which needs to be implemented/fixed. @ivanpovazan Do you perhaps know what is the status of --explicit-reflection flag in the linker?

I have provided more details in the Prerequisites section in my comment. The requirement 2. is necessary to enable this optimization as well, so it can be treated as a common prerequisite. Afaik --explicit-reflection is a legacy feature which is currently unused.

@kotlarmilos
Copy link
Member Author

Thanks! As you outlined, the idea is to estimate potential improvements (size savings and better performance) before proceeding with the concrete implementation.

@kotlarmilos kotlarmilos modified the milestones: 8.0.0, Future Apr 24, 2023
@kotlarmilos kotlarmilos modified the milestones: Future, 9.0.0 Jul 13, 2023
@kotlarmilos kotlarmilos modified the milestones: 9.0.0, Future Feb 9, 2024
@kotlarmilos
Copy link
Member Author

Obsolete, lower priority compared to other tasks.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads
Projects
None yet
Development

No branches or pull requests

2 participants