Skip to content

Commit

Permalink
Bring in changes from PR #8478
Browse files Browse the repository at this point in the history
Context: #8478

This PR serves to make #8478 smaller and easier to review
  • Loading branch information
grendello committed Feb 15, 2024
1 parent 3b5fa9d commit 3070fbf
Show file tree
Hide file tree
Showing 13 changed files with 679 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ sealed class ApplicationConfig
public uint bundled_assembly_name_width;
public uint number_of_assembly_store_files;
public uint number_of_dso_cache_entries;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint android_runtime_jnienv_class_token;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint jnienv_initialize_method_token;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint jnienv_registerjninatives_method_token;
public uint jni_remapping_replacement_type_count;
public uint jni_remapping_replacement_method_index_entry_count;

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint mono_components_mask;
public string android_package_name = String.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string GetComment (object data, string fieldName)
{
var dso_entry = EnsureType<DSOCacheEntry> (data);
if (String.Compare ("hash", fieldName, StringComparison.Ordinal) == 0) {
return $" hash 0x{dso_entry.hash:x}, from name: {dso_entry.HashedName}";
return $" from name: {dso_entry.HashedName}";
}

if (String.Compare ("name", fieldName, StringComparison.Ordinal) == 0) {
Expand All @@ -49,7 +49,7 @@ sealed class DSOCacheEntry
[NativeAssembler (Ignore = true)]
public string HashedName;

[NativeAssembler (UsesDataProvider = true)]
[NativeAssembler (UsesDataProvider = true, NumberFormat = LlvmIrVariableNumberFormat.Hexadecimal)]
public ulong hash;
public bool ignore;

Expand Down Expand Up @@ -93,11 +93,11 @@ sealed class AssemblyStoreSingleAssemblyRuntimeData
// src/monodroid/jni/xamarin-app.hh AssemblyStoreRuntimeData structure
sealed class AssemblyStoreRuntimeData
{
[NativePointer]
[NativePointer (IsNull = true)]
public byte data_start;
public uint assembly_count;

[NativePointer]
[NativePointer (IsNull = true)]
public AssemblyStoreAssemblyDescriptor assemblies;
}

Expand Down Expand Up @@ -299,7 +299,7 @@ void HashAndSortDSOCache (LlvmIrVariable variable, LlvmIrModuleTarget target, ob
throw new InvalidOperationException ($"Internal error: DSO cache entry has unexpected type {instance.Obj.GetType ()}");
}

entry.hash = GetXxHash (entry.HashedName, is64Bit);
entry.hash = MonoAndroidHelper.GetXxHash (entry.HashedName, is64Bit);
}

cache.Sort ((StructureInstance<DSOCacheEntry> a, StructureInstance<DSOCacheEntry> b) => a.Instance.hash.CompareTo (b.Instance.hash));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static CompressionResult Compress (AssemblyData data, string outputDirect
}

destBytes = bytePool.Rent (LZ4Codec.MaximumOutputSize (sourceBytes.Length));
int encodedLength = LZ4Codec.Encode (sourceBytes, 0, checked((int)fi.Length), destBytes, 0, destBytes.Length, LZ4Level.L09_HC);
int encodedLength = LZ4Codec.Encode (sourceBytes, 0, checked((int)fi.Length), destBytes, 0, destBytes.Length, LZ4Level.L12_MAX);
if (encodedLength < 0)
return CompressionResult.EncodingFailed;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.IO;
using System.IO.Hashing;
using System.Text;

using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -41,18 +39,13 @@ public void Generate (LlvmIrModule module, AndroidTargetArch arch, StreamWriter
LlvmIrGenerator generator = LlvmIrGenerator.Create (arch, fileName);
generator.Generate (output, module);
output.Flush ();
}

public static ulong GetXxHash (string str, bool is64Bit)
{
byte[] stringBytes = Encoding.UTF8.GetBytes (str);
if (is64Bit) {
return XxHash64.HashToUInt64 (stringBytes);
}

return (ulong)XxHash32.HashToUInt32 (stringBytes);
CleanupAfterGeneration (arch);
}

protected virtual void CleanupAfterGeneration (AndroidTargetArch arch)
{}

protected LlvmIrGlobalVariable EnsureGlobalVariable (LlvmIrVariable variable)
{
var gv = variable as LlvmIrGlobalVariable;
Expand Down
Loading

0 comments on commit 3070fbf

Please sign in to comment.