|
|
|
|
|
by pjmlp
871 days ago
|
|
Meanwhile .NET land requires writing reflection free specific code for AOT, while GraalVM can handle reflection just fine. ART also does PGO for free, as does OpenJ9. Both of which also handle reflection. The thing with Java ecosystem is choice of implementations, instead of Microsoft's single implementation, specially now since most of Xamarin's work has been consumed into modern .NET. |
|
With that said, trimming, also known as tree-shaking, which is required to not have massive binary size, has to know at compile-time which types, members and metadata tokens are reachable. This means that certain patterns of unbound reflection are by definition not statically analyzable and require the user to annotate (with [RequiresUnreferencedCode(params)]) the corresponding types with details of what they need the trimmer/linker to preserve (the entire assembly can also be rooted but, well, that's bad for size).
Other features like compiled expressions have received proper interpreter fallback which makes them just work(tm) without developer intervention.
You can also see that GraalVM Native Image is subject to very similar restrictions[1].
[0] Like pre-generating generic types/method bodies for Unity with special tooling. NativeAOT currently has (planned to be deprecated) rd.xml to manually instantiate certain generic methods and root specific types, replace their bodies, etc., it will probably be fully superseded by further expansion of attributes-style annotations API or obsoleted by improving compile-time analysis in the future.
[1] https://www.graalvm.org/22.1/reference-manual/native-image/L...
p.s.: quick search shows that Java Swing is plagued by similar issues with Native Image (not mentioning having to generate metadata annotations) to making .NET's GUI frameworks work with NativeAOT save for certain blessed templates/workloads introduced in .NET 8. Java AWT appears to be faring somewhat better on hello world examples but I suspect it experience the same fate as the templates for WinForms that the community has come up with so far (let me know if that's not the case).