Skip to content

Commit 0044761

Browse files
committed
[WIP] Replace MAM with JniRemapping, fix a JI test
1 parent b7c65dd commit 0044761

21 files changed

+561
-583
lines changed

src/Mono.Android/Android.Runtime/AndroidRuntime.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public override void DeleteWeakGlobalReference (ref JniObjectReference value)
243243
}
244244

245245
class AndroidTypeManager : JniRuntime.JniTypeManager {
246-
struct MAMReplacementMethod
246+
struct JniRemappingReplacementMethod
247247
{
248248
public string target_type;
249249
public string target_name;
@@ -329,7 +329,7 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
329329

330330
protected override string? GetReplacementTypeCore (string jniSimpleReference)
331331
{
332-
if (!JNIEnv.mamInUse) {
332+
if (!JNIEnv.jniRemappingInUse) {
333333
return null;
334334
}
335335

@@ -346,7 +346,7 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
346346

347347
protected override JniRuntime.ReplacementMethodInfo? GetReplacementMethodInfoCore (string jniSourceType, string jniMethodName, string jniMethodSignature)
348348
{
349-
if (!JNIEnv.mamInUse) {
349+
if (!JNIEnv.jniRemappingInUse) {
350350
return null;
351351
}
352352

@@ -355,8 +355,8 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
355355
return null;
356356
}
357357

358-
var method = new MAMReplacementMethod ();
359-
method = Marshal.PtrToStructure<MAMReplacementMethod>(retInfo);
358+
var method = new JniRemappingReplacementMethod ();
359+
method = Marshal.PtrToStructure<JniRemappingReplacementMethod>(retInfo);
360360

361361
int? paramCount = null;
362362
if (method.is_static) {

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct JnienvInitializeArgs {
3535
public int packageNamingPolicy;
3636
public byte ioExceptionType;
3737
public int jniAddNativeMethodRegistrationAttributePresent;
38-
public bool mamInUse;
38+
public bool jniRemappingInUse;
3939
}
4040
#pragma warning restore 0649
4141

@@ -49,7 +49,7 @@ public static partial class JNIEnv {
4949
static int androidSdkVersion;
5050

5151
static bool AllocObjectSupported;
52-
internal static bool mamInUse;
52+
internal static bool jniRemappingInUse;
5353

5454
static IntPtr grefIGCUserPeer_class;
5555

@@ -157,7 +157,7 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)
157157

158158
gref_gc_threshold = args->grefGcThreshold;
159159

160-
mamInUse = args->mamInUse;
160+
jniRemappingInUse = args->jniRemappingInUse;
161161
java_vm = args->javaVm;
162162

163163
version = args->version;

src/Xamarin.Android.Build.Tasks/Tasks/GenerateMamNativeCode.cs renamed to src/Xamarin.Android.Build.Tasks/Tasks/GenerateJniRemappingNativeCode.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99

1010
namespace Xamarin.Android.Tasks
1111
{
12-
public class GenerateMamNativeCode : AndroidTask
12+
public class GenerateJniRemappingNativeCode : AndroidTask
1313
{
14-
internal const string MamNativeCodeInfoKey = ".:!MamNativeCodeInfo!:.";
15-
internal sealed class MamNativeCodeInfo
14+
internal const string JniRemappingNativeCodeInfoKey = ".:!JniRemappingNativeCodeInfo!:.";
15+
16+
internal sealed class JniRemappingNativeCodeInfo
1617
{
1718
public int ReplacementTypeCount { get; }
1819
public int ReplacementMethodIndexEntryCount { get; }
1920

20-
public MamNativeCodeInfo (int replacementTypeCount, int replacementMethodIndexEntryCount)
21+
public JniRemappingNativeCodeInfo (int replacementTypeCount, int replacementMethodIndexEntryCount)
2122
{
2223
ReplacementTypeCount = replacementTypeCount;
2324
ReplacementMethodIndexEntryCount = replacementMethodIndexEntryCount;
2425
}
2526
}
2627

27-
public override string TaskPrefix => "GMAMNC";
28+
public override string TaskPrefix => "GJRNC";
2829

2930
public ITaskItem RemappingXmlFilePath { get; set; }
3031

@@ -53,13 +54,13 @@ public override bool RunTask ()
5354

5455
void GenerateEmpty ()
5556
{
56-
Generate (new MamRemappingAssemblyGenerator (), typeReplacementsCount: 0);
57+
Generate (new JniRemappingAssemblyGenerator (), typeReplacementsCount: 0);
5758
}
5859

5960
void Generate ()
6061
{
61-
var typeReplacements = new List<MamTypeReplacement> ();
62-
var methodReplacements = new List<MamMethodReplacement> ();
62+
var typeReplacements = new List<JniRemappingTypeReplacement> ();
63+
var methodReplacements = new List<JniRemappingMethodReplacement> ();
6364

6465
var readerSettings = new XmlReaderSettings {
6566
XmlResolver = null,
@@ -73,32 +74,32 @@ void Generate ()
7374
}
7475
}
7576

76-
Generate (new MamRemappingAssemblyGenerator (typeReplacements, methodReplacements), typeReplacements.Count);
77+
Generate (new JniRemappingAssemblyGenerator (typeReplacements, methodReplacements), typeReplacements.Count);
7778
}
7879

79-
void Generate (MamRemappingAssemblyGenerator mamGenerator, int typeReplacementsCount)
80+
void Generate (JniRemappingAssemblyGenerator jniRemappingGenerator, int typeReplacementsCount)
8081
{
81-
mamGenerator.Init ();
82+
jniRemappingGenerator.Init ();
8283

8384
foreach (string abi in SupportedAbis) {
84-
string baseAsmFilePath = Path.Combine (OutputDirectory, $"mam_remap.{abi.ToLowerInvariant ()}");
85+
string baseAsmFilePath = Path.Combine (OutputDirectory, $"jni_remap.{abi.ToLowerInvariant ()}");
8586
string llFilePath = $"{baseAsmFilePath}.ll";
8687

8788
using (var sw = MemoryStreamPool.Shared.CreateStreamWriter ()) {
88-
mamGenerator.Write (GeneratePackageManagerJava.GetAndroidTargetArchForAbi (abi), sw, llFilePath);
89+
jniRemappingGenerator.Write (GeneratePackageManagerJava.GetAndroidTargetArchForAbi (abi), sw, llFilePath);
8990
sw.Flush ();
9091
Files.CopyIfStreamChanged (sw.BaseStream, llFilePath);
9192
}
9293
}
9394

9495
BuildEngine4.RegisterTaskObjectAssemblyLocal (
95-
MamNativeCodeInfoKey,
96-
new MamNativeCodeInfo (typeReplacementsCount, mamGenerator.ReplacementMethodIndexEntryCount),
96+
JniRemappingNativeCodeInfoKey,
97+
new JniRemappingNativeCodeInfo (typeReplacementsCount, jniRemappingGenerator.ReplacementMethodIndexEntryCount),
9798
RegisteredTaskObjectLifetime.Build
9899
);
99100
}
100101

101-
void ReadXml (XmlReader reader, List<MamTypeReplacement> typeReplacements, List<MamMethodReplacement> methodReplacements)
102+
void ReadXml (XmlReader reader, List<JniRemappingTypeReplacement> typeReplacements, List<JniRemappingMethodReplacement> methodReplacements)
102103
{
103104
bool haveAllAttributes;
104105

@@ -115,7 +116,7 @@ void ReadXml (XmlReader reader, List<MamTypeReplacement> typeReplacements, List<
115116
continue;
116117
}
117118

118-
typeReplacements.Add (new MamTypeReplacement (from, to));
119+
typeReplacements.Add (new JniRemappingTypeReplacement (from, to));
119120
} else if (String.Compare ("replace-method", reader.LocalName, StringComparison.Ordinal) == 0) {
120121
haveAllAttributes &= GetRequiredAttribute ("source-type", out string sourceType);
121122
haveAllAttributes &= GetRequiredAttribute ("source-method-name", out string sourceMethodName);
@@ -134,7 +135,7 @@ void ReadXml (XmlReader reader, List<MamTypeReplacement> typeReplacements, List<
134135

135136
string sourceMethodSignature = reader.GetAttribute ("source-method-signature");
136137
methodReplacements.Add (
137-
new MamMethodReplacement (
138+
new JniRemappingMethodReplacement (
138139
sourceType, sourceMethodName, sourceMethodSignature,
139140
targetType, targetMethodName, isStatic
140141
)

src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void AddEnvironment ()
403403

404404
bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
405405
var appConfState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ApplicationConfigTaskState> (ApplicationConfigTaskState.RegisterTaskObjectKey, RegisteredTaskObjectLifetime.Build);
406-
var mamNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateMamNativeCode.MamNativeCodeInfo> (GenerateMamNativeCode.MamNativeCodeInfoKey, RegisteredTaskObjectLifetime.Build);
406+
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey, RegisteredTaskObjectLifetime.Build);
407407
var appConfigAsmGen = new ApplicationConfigNativeAssemblyGenerator (environmentVariables, systemProperties, Log) {
408408
IsBundledApp = IsBundledApplication,
409409
UsesMonoAOT = usesMonoAOT,
@@ -430,8 +430,8 @@ void AddEnvironment ()
430430
AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token,
431431
JNIEnvInitializeToken = jnienv_initialize_method_token,
432432
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
433-
MAMReplacementTypeCount = mamNativeCodeInfo == null ? 0 : mamNativeCodeInfo.ReplacementTypeCount,
434-
MAMReplacementMethodIndexEntryCount = mamNativeCodeInfo == null ? 0 : mamNativeCodeInfo.ReplacementMethodIndexEntryCount,
433+
JniRemappingReplacementTypeCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementTypeCount,
434+
JniRemappingReplacementMethodIndexEntryCount = jniRemappingNativeCodeInfo == null ? 0 : jniRemappingNativeCodeInfo.ReplacementMethodIndexEntryCount,
435435
};
436436
appConfigAsmGen.Init ();
437437

src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PrepareAbiItems : AndroidTask
1414
const string TypeMapBase = "typemaps";
1515
const string EnvBase = "environment";
1616
const string CompressedAssembliesBase = "compressed_assemblies";
17-
const string MamBase = "mam_remap";
17+
const string JniRemappingBase = "jni_remap";
1818

1919
public override string TaskPrefix => "PAI";
2020

@@ -51,8 +51,8 @@ public override bool RunTask ()
5151
baseName = EnvBase;
5252
} else if (String.Compare ("compressed", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
5353
baseName = CompressedAssembliesBase;
54-
} else if (String.Compare ("mamremap", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
55-
baseName = MamBase;
54+
} else if (String.Compare ("jniremap", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
55+
baseName = JniRemappingBase;
5656
} else {
5757
Log.LogError ($"Unknown mode: {Mode}");
5858
return false;

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public sealed class ApplicationConfig
6060
public uint android_runtime_jnienv_class_token;
6161
public uint jnienv_initialize_method_token;
6262
public uint jnienv_registerjninatives_method_token;
63-
public uint mam_replacement_type_count;
64-
public uint mam_replacement_method_index_entry_count;
63+
public uint jni_remapping_replacement_type_count;
64+
public uint jni_remapping_replacement_method_index_entry_count;
6565
public uint mono_components_mask;
6666
public string android_package_name = String.Empty;
6767
}
@@ -310,14 +310,14 @@ static ApplicationConfig ReadApplicationConfig (EnvironmentFile envFile)
310310
ret.number_of_dso_cache_entries = ConvertFieldToUInt32 ("jnienv_registerjninatives_method_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
311311
break;
312312

313-
case 21: // mam_replacement_type_count: uint32_t / .word | .long
313+
case 21: // jni_remapping_replacement_type_count: uint32_t / .word | .long
314314
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
315-
ret.mam_replacement_type_count = ConvertFieldToUInt32 ("mam_replacement_type_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
315+
ret.jni_remapping_replacement_type_count = ConvertFieldToUInt32 ("jni_remapping_replacement_type_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
316316
break;
317317

318-
case 22: // mam_replacement_method_index_entry_count: uint32_t / .word | .long
318+
case 22: // jni_remapping_replacement_method_index_entry_count: uint32_t / .word | .long
319319
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
320-
ret.mam_replacement_method_index_entry_count = ConvertFieldToUInt32 ("mam_replacement_method_index_entry_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
320+
ret.jni_remapping_replacement_method_index_entry_count = ConvertFieldToUInt32 ("jni_remapping_replacement_method_index_entry_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
321321
break;
322322

323323
case 23: // mono_components_mask: uint32_t / .word | .long

src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ sealed class ApplicationConfig
4545
public uint android_runtime_jnienv_class_token;
4646
public uint jnienv_initialize_method_token;
4747
public uint jnienv_registerjninatives_method_token;
48-
public uint mam_replacement_type_count;
49-
public uint mam_replacement_method_index_entry_count;
48+
public uint jni_remapping_replacement_type_count;
49+
public uint jni_remapping_replacement_method_index_entry_count;
5050
public uint mono_components_mask;
5151
public string android_package_name = String.Empty;
5252
}

src/Xamarin.Android.Build.Tasks/Utilities/ApplicationConfigNativeAssemblyGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ sealed class XamarinAndroidBundledAssembly
170170
public int AndroidRuntimeJNIEnvToken { get; set; }
171171
public int JNIEnvInitializeToken { get; set; }
172172
public int JNIEnvRegisterJniNativesToken { get; set; }
173-
public int MAMReplacementTypeCount { get; set; }
174-
public int MAMReplacementMethodIndexEntryCount { get; set; }
173+
public int JniRemappingReplacementTypeCount { get; set; }
174+
public int JniRemappingReplacementMethodIndexEntryCount { get; set; }
175175
public MonoComponent MonoComponents { get; set; }
176176
public PackageNamingPolicy PackageNamingPolicy { get; set; }
177177
public List<ITaskItem> NativeLibraries { get; set; }
@@ -214,8 +214,8 @@ public override void Init ()
214214
android_runtime_jnienv_class_token = (uint)AndroidRuntimeJNIEnvToken,
215215
jnienv_initialize_method_token = (uint)JNIEnvInitializeToken,
216216
jnienv_registerjninatives_method_token = (uint)JNIEnvRegisterJniNativesToken,
217-
mam_replacement_type_count = (uint)MAMReplacementTypeCount,
218-
mam_replacement_method_index_entry_count = (uint)MAMReplacementMethodIndexEntryCount,
217+
jni_remapping_replacement_type_count = (uint)JniRemappingReplacementTypeCount,
218+
jni_remapping_replacement_method_index_entry_count = (uint)JniRemappingReplacementMethodIndexEntryCount,
219219
mono_components_mask = (uint)MonoComponents,
220220
android_package_name = AndroidPackageName,
221221
};

0 commit comments

Comments
 (0)