-
Notifications
You must be signed in to change notification settings - Fork 566
Move RewriteMarshalMethods to the inner (per-RID) build #11066
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,24 +68,50 @@ static NativeCodeGenStateObject CreateNativeCodeGenState (AndroidTargetArch arch | |
| obj.MarshalMethods.Add (group.Key, methods); | ||
| } | ||
|
|
||
| // Also include methods that were already rewritten in the inner build. | ||
| // After the inner build rewrites assemblies, the outer build's GenerateJavaStubs | ||
| // re-classifies them and puts already-rewritten methods (with _mm_wrapper + | ||
| // [UnmanagedCallersOnly]) into ConvertedMarshalMethods instead of MarshalMethods. | ||
| // We must include these so that GenerateNativeMarshalMethodSources produces | ||
| // correct native callback tables. | ||
| foreach (var group in state.Classifier.ConvertedMarshalMethods) { | ||
| if (!obj.MarshalMethods.TryGetValue (group.Key, out var methods)) { | ||
| methods = new List<MarshalMethodEntryObject> (group.Value.Count); | ||
| obj.MarshalMethods.Add (group.Key, methods); | ||
| } | ||
|
|
||
| foreach (var method in group.Value) { | ||
| var entry = CreateEntry (method, state.ManagedMarshalMethodsLookupInfo); | ||
| methods.Add (entry); | ||
| } | ||
| } | ||
|
Comment on lines
+71
to
+87
|
||
|
|
||
| return obj; | ||
| } | ||
|
|
||
| static MarshalMethodEntryObject CreateEntry (MarshalMethodEntry entry, ManagedMarshalMethodsLookupInfo? info) | ||
| { | ||
| // For converted entries, use the wrapper method (ConvertedNativeCallback) for native | ||
| // callback tables — it has the correct MetadataToken and [UnmanagedCallersOnly] attribute. | ||
| // For regular entries, NativeCallback already returns the wrapper after the rewriter sets | ||
| // NativeCallbackWrapper. | ||
| MethodDefinition nativeCallbackMethod = entry is ConvertedMarshalMethodEntry converted | ||
| ? converted.ConvertedNativeCallback | ||
| : entry.NativeCallback; | ||
|
|
||
| var obj = new MarshalMethodEntryObject ( | ||
| declaringType: CreateDeclaringType (entry.DeclaringType), | ||
| implementedMethod: CreateMethod (entry.ImplementedMethod), | ||
| isSpecial: entry.IsSpecial, | ||
| jniTypeName: entry.JniTypeName, | ||
| jniMethodName: entry.JniMethodName, | ||
| jniMethodSignature: entry.JniMethodSignature, | ||
| nativeCallback: CreateMethod (entry.NativeCallback), | ||
| nativeCallback: CreateMethod (nativeCallbackMethod), | ||
| registeredMethod: CreateMethodBase (entry.RegisteredMethod) | ||
| ); | ||
|
|
||
| if (info is not null) { | ||
| (uint assemblyIndex, uint classIndex, uint methodIndex) = info.GetIndex (entry.NativeCallback); | ||
| (uint assemblyIndex, uint classIndex, uint methodIndex) = info.GetIndex (nativeCallbackMethod); | ||
|
|
||
| obj.NativeCallback.AssemblyIndex = assemblyIndex; | ||
| obj.NativeCallback.ClassIndex = classIndex; | ||
|
|
||
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.
EnableManagedMarshalMethodsLookup currently builds a ManagedMarshalMethodsLookupInfo instance (managedLookupInfo) but it’s not persisted anywhere after rewriting. Downstream native codegen relies on NativeCodeGenState.ManagedMarshalMethodsLookupInfo to populate AssemblyIndex/ClassIndex/MethodIndex (and will throw if missing), so managed lookup builds can regress. Consider emitting the lookup info (or the computed indexes) as a task output/file and rehydrating it where NativeCodeGenStateObject is created (or recomputing it from the rewritten assemblies).