-
Notifications
You must be signed in to change notification settings - Fork 541
[XABT] Move scanning for ACW map JLOs to FindJavaObjectsStep
.
#9930
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
Conversation
dbaedaa
to
1abe342
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I wondered about this step... If you are building a Release
app with 4 RIDs, does this write a copy of the .xml
file 4 times? Is there logic that detects the first RID and skips the rest?
The Java objects found are identical between all 4 RIDs. The only thing that would differ, is the BCL sets different trimmer flags based on 32 or 64-bit, different hardware intrinsics, etc. System.Private.CoreLib.dll
and a few other System
assemblies will differ per RID, but no Android-libraries or user-assemblies would.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it will write the .jlo.xml
4 times, one beside each "arch" of the assembly. Initially this was because this would eventually be a linker step, and the linker has no concept of deduplicating assembly sets that are running in parallel.
If this is going to remain outside the linker, we might could avoid a few steps like this one and finding JLOs for generating java stub code in the future, however other steps we will migrate like marshal method rewriting and generating typemaps are "per-arch" and will still need to be run 4 times.
Note this duplication is simply for the JLO scanning, tasks such as GenerateJavaCallableWrappers
and GenerateAcwMap
only read in the "first" arch to generate their output, as they are not "per-arch":
android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaCallableWrappers.cs
Lines 47 to 50 in 9121bea
// Get the set of assemblies for the "first" ABI. JavaCallableWrappers are | |
// not ABI-specific, so we can use any ABI to generate the wrappers. | |
var allAssembliesPerArch = MonoAndroidHelper.GetPerArchAssemblies (ResolvedAssemblies, SupportedAbis, validate: true); | |
var singleArchAssemblies = allAssembliesPerArch.First ().Value.Values.ToList (); |
The good news is that the expensive part of the scan is the "first" scan, which has to deserialize the assemblies into Cecil structures. So adding additional scans on assemblies that have already been scanned for eg: FixAbstractMethod
is actually pretty cheap (<100 ms).
Today's GenerateJavaStubs
also scans 4 times, so this isn't a performance regression. However, the new way will have the benefit of supporting incremental builds. It will not need to rescan every assembly if 1 changes.
public static string GetJavaObjectsXmlFilePath (string assemblyPath) | ||
=> Path.ChangeExtension (assemblyPath, ".jlo.xml"); | ||
|
||
public static JavaObjectsXmlFile Import (string filename, JavaObjectsXmlFileReadType readType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API design question: why have the WasScanned
property at all? Why not instead have the return type of Import()
be (nullable) JavaObjectsXmlFile?
, with null
being the "not scanned" value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WasScanned
feels a little more self-documenting than null
. It seems odd to return null
for "not scanned" and return an empty JavaObjectsXmlFile
for "scanned, but no data".
Ultimately the issue is probably moot, as the "scanned" concept only exists to facilitate A/B testing between the "current" way and the "new" way ($(_AndroidJLOCheckedBuild)
). Once the migration is complete, the old way will be removed, as will the "scanned" concept.
enum JavaObjectsXmlFileReadType | ||
{ | ||
None = 0, | ||
ACW = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have "better" names? To my mind, ACW is "Android Callable Wrapper", JCW is "Java Callable Wrapper", and they're the same thing.
Except here.
"ACW" appears to be for the acw-map.txt
file (https://github.com/xamarin/monodroid/commit/a04b73b30e5bbd81b3773865c313a8084f0a21d1), which is used for Android resource fixup.
Perhaps rename "ACW" to "AndroidResourceFixups"?
var wrapper = CecilImporter.CreateType (type, Context, reader_options); | ||
wrappers.Add (wrapper); | ||
} | ||
foreach (var type in types) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change feels unnecessary, and will only complicate historical spelunking.
1abe342
to
98730a8
Compare
…1325) Context: bc44f08 Context: dotnet/android#9930 Make a few tweaks to JCW serialization for dotnet/android#9930: - We no longer need `was_scanned`, as we now write a zero byte file to indicate a file was not scanned. - Add an overload to import from an `XElement`, as the full `.jlo.xml` file now contains additional non-JCW data.
@jpobst: PR message states:
Why does it need to look for Why would |
I am not familiar with what Perhaps a future enhancement could be to remove unneeded information from the map. |
The handy example is
I don't think that these are usable, but they do exist, and thus we need to preserve them for now, in alignment with |
Context: #9893
Building on #9893, this moves the process of scanning for JLOs needed for the ACW map generation task to the
FindJavaObjectsStep
"linker step".This process needs
interface
JLOs, whichJavaCallableWrappers
doesn't support. Expanding the JCW serialization format to allow interfaces (and other ACW-needed data it didn't already support) resulted in a lot of extra processing and waste.Instead, we expand the
.jlo.xml
file to have 2 sections, one for JCW needed data and one for ACW needed data:Additionally, for assemblies that cannot contain JLOs that we do not need to scan, we no longer write an "empty" XML file like this:
<types was_scanned="False" />
. Instead, we now write an actual empty (0 byte) file to disk, which saves build time when deserializing.Like #9893, this temporarily leaves the old ACW map generation code in place, guarded behind the
$(_AndroidJLOCheckedBuild)
flag. This flag generates the ACW map both the new and old way, and errors the build if there are differences. (A consistent sort was added so that both maps are sorted the same.)Requires dotnet/java-interop#1325.