Skip to content

Commit

Permalink
Merge branch 'mm-runtime' into mm-cleanup-and-enable
Browse files Browse the repository at this point in the history
* mm-runtime:
  Implement some requested changes
  Bump r8 from 3.3.28 to 3.3.75 (dotnet#7292)
  [Xamarin.Android.Build.Tasks] Pass `hybrid` to AOT, if enabled (dotnet#7263)
  Bump to lz4/lz4@5ff83968 [v1.9.4] (dotnet#7262)
  [Mono.Android] add "built-in" delegate for MAUI+non-Shell (dotnet#7267)
  • Loading branch information
grendello committed Aug 23, 2022
2 parents 3530c39 + c8a2d9f commit e8f3215
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 15 deletions.
4 changes: 0 additions & 4 deletions Documentation/release-notes/r8-3.3.28.md

This file was deleted.

4 changes: 4 additions & 0 deletions Documentation/release-notes/r8-3.3.75.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### D8/R8 version update to 3.3.75

The version of the [D8 dexer and R8 shrinker](https://r8.googlesource.com/r8)
included in Xamarin.Android has been updated from 3.3.28 to 3.3.75.
2 changes: 1 addition & 1 deletion external/lz4
Submodule lz4 updated 116 files
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<!-- Workaround for https://github.com/xamarin/xamarin-android/issues/6626, remove once https://github.com/dotnet/runtime/pull/68265 lands -->
<assembly fullname="System.Runtime.InteropServices">
<type fullname="System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute" />
</assembly>
Expand Down
10 changes: 4 additions & 6 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,14 @@ public override void RegisterNativeMembers (JniType nativeClass, Type type, stri
RegisterNativeMembers (nativeClass, type, methods.AsSpan ());

// Temporary hack, see comments in RegisterNativeMembers below
static readonly Dictionary<string, List<string>> dynamicRegistrationMethods = new Dictionary<string, List<string>> (StringComparer.Ordinal) {
{"Android.Views.View+IOnLayoutChangeListenerImplementor", new List<string> { "GetOnLayoutChange_Landroid_view_View_IIIIIIIIHandler" }},
{"Android.Views.View+IOnLayoutChangeListenerInvoker", new List<string> { "GetOnLayoutChange_Landroid_view_View_IIIIIIIIHandler" }},
{"Java.Interop.TypeManager+JavaTypeManager", new List<string> { "GetActivateHandler" }},
static readonly Dictionary<string, string[]> dynamicRegistrationMethods = new Dictionary<string, string[]> (StringComparer.Ordinal) {
{"Android.Views.View+IOnLayoutChangeListenerImplementor", new string[] { "GetOnLayoutChange_Landroid_view_View_IIIIIIIIHandler" }},
{"Android.Views.View+IOnLayoutChangeListenerInvoker", new string[] { "GetOnLayoutChange_Landroid_view_View_IIIIIIIIHandler" }},
{"Java.Interop.TypeManager+JavaTypeManager", new string[] { "GetActivateHandler" }},
};

public void RegisterNativeMembers (JniType nativeClass, Type type, ReadOnlySpan<char> methods)
{
Logger.Log (LogLevel.Debug, "monodroid-mm", $"RegisterNativeMembers ('{nativeClass?.Name}', '{type?.FullName}', '{methods.ToString ()}')");

if (methods.IsEmpty) {
Logger.Log (LogLevel.Info, "monodroid-mm", "No methods to register, returning");
return;
Expand Down
13 changes: 13 additions & 0 deletions src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ internal static bool Wrap_JniMarshal_PPLLL_Z (this _JniMarshal_PPLLL_Z callback,
}
}

internal static IntPtr Wrap_JniMarshal_PPIZI_L (this _JniMarshal_PPIZI_L callback, IntPtr jnienv, IntPtr klazz, int p0, bool p1, int p2)
{
JNIEnv.WaitForBridgeProcessing ();
try {
return callback (jnienv, klazz, p0, p1, p2);
} catch (Exception e) when (_unhandled_exception (e)) {
AndroidEnvironment.UnhandledException (e);
return default;
}
}

internal static void Wrap_JniMarshal_PPIIII_V (this _JniMarshal_PPIIII_V callback, IntPtr jnienv, IntPtr klazz, int p0, int p1, int p2, int p3)
{
JNIEnv.WaitForBridgeProcessing ();
Expand Down Expand Up @@ -500,6 +511,8 @@ private static Delegate CreateBuiltInDelegate (Delegate dlg, Type delegateType)
return new _JniMarshal_PPLLL_L (Unsafe.As<_JniMarshal_PPLLL_L> (dlg).Wrap_JniMarshal_PPLLL_L);
case nameof (_JniMarshal_PPLLL_Z):
return new _JniMarshal_PPLLL_Z (Unsafe.As<_JniMarshal_PPLLL_Z> (dlg).Wrap_JniMarshal_PPLLL_Z);
case nameof (_JniMarshal_PPIZI_L):
return new _JniMarshal_PPIZI_L (Unsafe.As<_JniMarshal_PPIZI_L> (dlg).Wrap_JniMarshal_PPIZI_L);
case nameof (_JniMarshal_PPIIII_V):
return new _JniMarshal_PPIIII_V (Unsafe.As<_JniMarshal_PPIIII_V> (dlg).Wrap_JniMarshal_PPIIII_V);
case nameof (_JniMarshal_PPLLLL_V):
Expand Down
6 changes: 6 additions & 0 deletions src/Mono.Android/Android.Runtime/JNINativeWrapper.g.tt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ var delegateTypes = new [] {
Return = "bool",
Invoke = "jnienv, klazz, p0, p1, p2",
},
new {
Type = "_JniMarshal_PPIZI_L",
Signature = "IntPtr jnienv, IntPtr klazz, int p0, bool p1, int p2",
Return = "IntPtr",
Invoke = "jnienv, klazz, p0, p1, p2",
},
new {
Type = "_JniMarshal_PPIIII_V",
Signature = "IntPtr jnienv, IntPtr klazz, int p0, int p1, int p2, int p3",
Expand Down
13 changes: 13 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ IEnumerable<Config> GetAotConfigs (NdkTools ndk)
aotOptions.Add ($"ld-flags={LdFlags}");
}

// We don't check whether any mode option was added via `AotAdditionalArguments`, the `AndroidAotMode` property should always win here.
// Modes not supported by us directly can be set by setting `AndroidAotMode` to "normal" and adding the desired mode name to the
// `AotAdditionalArguments` property.
switch (AotMode) {
case AotMode.Full:
aotOptions.Add ("full");
break;

case AotMode.Hybrid:
aotOptions.Add ("hybrid");
break;
}

// we need to quote the entire --aot arguments here to make sure it is parsed
// on windows as one argument. Otherwise it will be split up into multiple
// values, which wont work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ void MoveFile (string source, string target)
Files.CopyIfChanged (source, target);
try {
File.Delete (source);
} catch (Exception) {
} catch (Exception ex) {
log.LogWarning ($"Unable to delete source file '{source}' when moving it to '{target}'");
log.LogDebugMessage (ex.ToString ());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ bool IsStandardHandler (TypeDefinition topType, ConnectorInfo connector, MethodD
return false;
}

// TODO: if we can't native callback and/or delegate field using `callbackNameCore`, fall back to `jniName` (which is the first argument to the `[Register]`
// TODO: if we can't find native callback and/or delegate field using `callbackNameCore`, fall back to `jniName` (which is the first argument to the `[Register]`
// attribute). Or simply use `jniName` at once - needs testing.

string callbackNameCore = connectorName.Substring (HandlerNameStart.Length, connectorName.Length - HandlerNameStart.Length - HandlerNameEnd.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ public override void Init ()
// names and similar signatures) will actually share the same **short** native symbol name. In this case we must
// ensure that they all use long symbol names. This has to be done as a post-processing step, after we
// have already iterated over the entire method collection.
//
// A handful of examples from the Hello World MAUI app:
//
// Overloaded MM: Java_crc64e1fb321c08285b90_CellAdapter_n_1onActionItemClicked
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean Android.Views.ActionMode/ICallback::OnActionItemClicked(Android.Views.ActionMode,Android.Views.IMenuItem))
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean AndroidX.AppCompat.View.ActionMode/ICallback::OnActionItemClicked(AndroidX.AppCompat.View.ActionMode,Android.Views.IMenuItem))
// new native symbol name: Java_crc64e1fb321c08285b90_CellAdapter_n_1onActionItemClicked__Landroidx_appcompat_view_ActionMode_2Landroid_view_MenuItem_2
//
// Overloaded MM: Java_crc64e1fb321c08285b90_CellAdapter_n_1onCreateActionMode
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean Android.Views.ActionMode/ICallback::OnCreateActionMode(Android.Views.ActionMode,Android.Views.IMenu))
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean AndroidX.AppCompat.View.ActionMode/ICallback::OnCreateActionMode(AndroidX.AppCompat.View.ActionMode,Android.Views.IMenu))
// new native symbol name: Java_crc64e1fb321c08285b90_CellAdapter_n_1onCreateActionMode__Landroidx_appcompat_view_ActionMode_2Landroid_view_Menu_2
//
// Overloaded MM: Java_crc64e1fb321c08285b90_CellAdapter_n_1onDestroyActionMode
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Void Android.Views.ActionMode/ICallback::OnDestroyActionMode(Android.Views.ActionMode))
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Void AndroidX.AppCompat.View.ActionMode/ICallback::OnDestroyActionMode(AndroidX.AppCompat.View.ActionMode))
// new native symbol name: Java_crc64e1fb321c08285b90_CellAdapter_n_1onDestroyActionMode__Landroidx_appcompat_view_ActionMode_2
//
// Overloaded MM: Java_crc64e1fb321c08285b90_CellAdapter_n_1onPrepareActionMode
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean Android.Views.ActionMode/ICallback::OnPrepareActionMode(Android.Views.ActionMode,Android.Views.IMenu))
// implemented in: Microsoft.Maui.Controls.Handlers.Compatibility.CellAdapter (System.Boolean AndroidX.AppCompat.View.ActionMode/ICallback::OnPrepareActionMode(AndroidX.AppCompat.View.ActionMode,Android.Views.IMenu))
// new native symbol name: Java_crc64e1fb321c08285b90_CellAdapter_n_1onPrepareActionMode__Landroidx_appcompat_view_ActionMode_2Landroid_view_Menu_2
//
var overloadedNativeSymbolNames = new Dictionary<string, List<MarshalMethodInfo>> (StringComparer.Ordinal);
foreach (IList<MarshalMethodEntry> entryList in marshalMethods.Values) {
bool useFullNativeSignature = entryList.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion src/r8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
}

dependencies {
compile group: 'com.android.tools', name: 'r8', version: '3.3.28'
compile group: 'com.android.tools', name: 'r8', version: '3.3.75'
}

jar {
Expand Down

0 comments on commit e8f3215

Please sign in to comment.