Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-tools/jnienv-gen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public string ApiName
public ParamInfo [] Parameters;

// If true, then we initialize the binding on the static ctor, we dont lazy-define it
public bool Prebind;
public bool Prebind = false;

// If there is a custom wrapper in JNIEnv (so an automatic one shouldn't be generated)
public bool CustomWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Mono.Android\Microsoft.Android.Runtime\RuntimeFeature.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop\Java.Interop.csproj" />
<ProjectReference Include="..\Mono.Android\Mono.Android.csproj" />
Expand Down
24 changes: 11 additions & 13 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Reflection;

Expand Down Expand Up @@ -126,7 +124,7 @@ public override JniObjectReference CreateLocalReference (JniObjectReference valu
{
var r = base.CreateLocalReference (value, ref localReferenceCount);

if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogLocalRef) {
var tname = Thread.CurrentThread.Name;
var tid = Thread.CurrentThread.ManagedThreadId;
Expand All @@ -140,7 +138,7 @@ public override JniObjectReference CreateLocalReference (JniObjectReference valu

public override void DeleteLocalReference (ref JniObjectReference value, ref int localReferenceCount)
{
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogLocalRef) {
var tname = Thread.CurrentThread.Name;
var tid = Thread.CurrentThread.ManagedThreadId;
Expand All @@ -154,7 +152,7 @@ public override void DeleteLocalReference (ref JniObjectReference value, ref int
public override void CreatedLocalReference (JniObjectReference value, ref int localReferenceCount)
{
base.CreatedLocalReference (value, ref localReferenceCount);
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogLocalRef) {
var tname = Thread.CurrentThread.Name;
var tid = Thread.CurrentThread.ManagedThreadId;
Expand All @@ -167,7 +165,7 @@ public override void CreatedLocalReference (JniObjectReference value, ref int lo
public override IntPtr ReleaseLocalReference (ref JniObjectReference value, ref int localReferenceCount)
{
var r = base.ReleaseLocalReference (ref value, ref localReferenceCount);
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogLocalRef) {
var tname = Thread.CurrentThread.Name;
var tid = Thread.CurrentThread.ManagedThreadId;
Expand All @@ -183,7 +181,7 @@ public override IntPtr ReleaseLocalReference (ref JniObjectReference value, ref

public override void WriteLocalReferenceLine (string format, params object?[] args)
{
if (!RuntimeFeature.ObjectReferenceLogging) {
if (!AndroidRuntimeFeature.ObjectReferenceLogging) {
return;
}
if (!Logger.LogLocalRef) {
Expand All @@ -196,7 +194,7 @@ public override void WriteLocalReferenceLine (string format, params object?[] ar

public override void WriteGlobalReferenceLine (string format, params object?[] args)
{
if (!RuntimeFeature.ObjectReferenceLogging) {
if (!AndroidRuntimeFeature.ObjectReferenceLogging) {
return;
}
if (!Logger.LogGlobalRef) {
Expand All @@ -212,7 +210,7 @@ public override JniObjectReference CreateGlobalReference (JniObjectReference val
var r = base.CreateGlobalReference (value);

int gc;
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogGlobalRef) {
var ctype = GetObjectRefType (value.Type);
var ntype = GetObjectRefType (r.Type);
Expand Down Expand Up @@ -251,7 +249,7 @@ static byte GetObjectRefType (JniObjectReferenceType type)

public override void DeleteGlobalReference (ref JniObjectReference value)
{
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogGlobalRef) {
var ctype = GetObjectRefType (value.Type);
var tname = Thread.CurrentThread.Name;
Expand All @@ -272,7 +270,7 @@ public override JniObjectReference CreateWeakGlobalReference (JniObjectReference
{
var r = base.CreateWeakGlobalReference (value);

if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogGlobalRef) {
var ctype = GetObjectRefType (value.Type);
var ntype = GetObjectRefType (r.Type);
Expand All @@ -292,7 +290,7 @@ public override JniObjectReference CreateWeakGlobalReference (JniObjectReference

public override void DeleteWeakGlobalReference (ref JniObjectReference value)
{
if (RuntimeFeature.ObjectReferenceLogging) {
if (AndroidRuntimeFeature.ObjectReferenceLogging) {
if (Logger.LogGlobalRef) {
var ctype = GetObjectRefType (value.Type);
var tname = Thread.CurrentThread.Name;
Expand Down Expand Up @@ -868,7 +866,7 @@ public override void FinalizePeer (IJavaPeerable value)
value.GetType ().ToString (),
value.PeerReference.ToString (),
value.JniIdentityHashCode,
RuntimeHelpers.GetHashCode (value)));
System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (value)));
}

// FIXME: need hash cleanup mechanism.
Expand Down
6 changes: 3 additions & 3 deletions src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public static class AndroidRuntimeInternal

static AndroidRuntimeInternal ()
{
if (RuntimeFeature.IsMonoRuntime) {
if (AndroidRuntimeFeature.IsMonoRuntime) {
mono_unhandled_exception = MonoUnhandledException;
} else if (RuntimeFeature.IsCoreClrRuntime) {
} else if (AndroidRuntimeFeature.IsCoreClrRuntime) {
mono_unhandled_exception = CoreClrUnhandledException;
} else if (RuntimeFeature.IsNativeAotRuntime) {
} else if (AndroidRuntimeFeature.IsNativeAotRuntime) {
mono_unhandled_exception = CoreClrUnhandledException;
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
Expand Down
20 changes: 10 additions & 10 deletions src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class JNIEnv {

static Array ArrayCreateInstance (Type elementType, int length)
{
if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
if (System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) {
// CoreCLR runtime type loader can construct any T[] dynamically.
// IsDynamicCodeSupported is a [FeatureGuard] so this branch is
Expand Down Expand Up @@ -134,11 +134,11 @@ internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPt
Logger.Log (LogLevel.Info, "MonoDroid", "UNHANDLED EXCEPTION:");
Logger.Log (LogLevel.Info, "MonoDroid", javaException.ToString ());

if (RuntimeFeature.IsMonoRuntime) {
if (AndroidRuntimeFeature.IsMonoRuntime) {
MonoDroidUnhandledException (innerException ?? javaException);
} else if (RuntimeFeature.IsCoreClrRuntime) {
} else if (AndroidRuntimeFeature.IsCoreClrRuntime) {
ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent (innerException ?? javaException);
} else if (RuntimeFeature.IsNativeAotRuntime) {
} else if (AndroidRuntimeFeature.IsNativeAotRuntime) {
ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent (innerException ?? javaException);
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
Expand Down Expand Up @@ -441,7 +441,7 @@ public static unsafe IntPtr NewObject (IntPtr jclass, IntPtr jmethod, params JVa
return NewObject (jclass, jmethod, p);
}

public static string GetClassNameFromInstance (IntPtr jobject)
public static string? GetClassNameFromInstance (IntPtr jobject)
{
return JniEnvironment.Types.GetJniTypeNameFromInstance (new JniObjectReference (jobject));
}
Expand Down Expand Up @@ -471,7 +471,7 @@ static unsafe IntPtr monovm_typemap_managed_to_java (Type type, byte* mvidptr)

internal static unsafe string? TypemapManagedToJava (Type type)
{
if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
// The trimmable typemap doesn't use the native typemap tables.
// Delegate to the managed TrimmableTypeMap instead.
return TrimmableTypeMap.Instance.TryGetJniNameForManagedType (type, out var jniName) ? jniName : null;
Expand All @@ -491,9 +491,9 @@ static unsafe IntPtr monovm_typemap_managed_to_java (Type type, byte* mvidptr)

IntPtr ret;
fixed (byte* mvidptr = mvid_data) {
if (RuntimeFeature.IsMonoRuntime) {
if (AndroidRuntimeFeature.IsMonoRuntime) {
ret = monovm_typemap_managed_to_java (type, mvidptr);
} else if (RuntimeFeature.IsCoreClrRuntime) {
} else if (AndroidRuntimeFeature.IsCoreClrRuntime) {
ret = RuntimeNativeMethods.clr_typemap_managed_to_java (type.FullName, (IntPtr)mvidptr);
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
Expand Down Expand Up @@ -696,7 +696,7 @@ public static void CopyArray (IntPtr src, string[] dest)
// FIXME: Since a Dictionary<Type, Func> is used here, the trimmer will not be able to properly analyze `Type t`
// error IL2111: Method 'lambda expression' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
[UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = "FIXME: https://github.com/xamarin/xamarin-android/issues/8724")]
static object? GetObject (IntPtr e, Type t) =>
static object? GetObject (IntPtr e, Type? t) =>
Java.Lang.Object.GetObject (e, JniHandleOwnership.TransferLocalRef, t);
} },
{ typeof (Array), (type, source, index) => {
Expand All @@ -718,7 +718,7 @@ static TValue GetConverter<TValue>(Dictionary<Type, TValue> dict, Type? elementT
}

if (array != IntPtr.Zero) {
string type = GetClassNameFromInstance (array);
string? type = GetClassNameFromInstance (array);
if (type == null || type.Length < 1 || type [0] != '[')
throw new InvalidOperationException ("Unsupported java array type: " + type);

Expand Down
31 changes: 15 additions & 16 deletions src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Java.Interop.Tools.TypeNameMappings;

using Microsoft.Android.Runtime;
using RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;

namespace Android.Runtime
{
Expand Down Expand Up @@ -108,10 +107,10 @@ internal static void InitializeBeforeRuntimeCreation (JnienvInitializeArgs args)
// Only used for NativeAOT after the runtime has been created. MonoVM and CoreCLR use Initialize().
internal static void InitializeNativeAotRuntime (JniRuntime runtime, JnienvInitializeArgs args)
{
if (!RuntimeFeature.IsNativeAotRuntime) {
if (!AndroidRuntimeFeature.IsNativeAotRuntime) {
throw new NotSupportedException ("JNIEnvInit.InitializeNativeAotRuntime can only be used to initialize NativeAOT.");
}
if (RuntimeFeature.IsMonoRuntime || RuntimeFeature.IsCoreClrRuntime) {
if (AndroidRuntimeFeature.IsMonoRuntime || AndroidRuntimeFeature.IsCoreClrRuntime) {
throw new NotSupportedException ("Internal error: NativeAOT cannot be enabled with MonoVM or CoreCLR.");
}

Expand All @@ -125,11 +124,11 @@ internal static void InitializeNativeAotRuntime (JniRuntime runtime, JnienvIniti
[UnmanagedCallersOnly]
internal static unsafe void Initialize (JnienvInitializeArgs* args)
{
if (RuntimeFeature.IsNativeAotRuntime) {
if (AndroidRuntimeFeature.IsNativeAotRuntime) {
throw new NotSupportedException ("JNIEnvInit.Initialize cannot be used to initialize NativeAOT.");
}
if (RuntimeFeature.IsMonoRuntime == RuntimeFeature.IsCoreClrRuntime) {
throw new NotSupportedException ("Internal error: exactly one of RuntimeFeature.IsMonoRuntime or RuntimeFeature.IsCoreClrRuntime must be enabled.");
if (AndroidRuntimeFeature.IsMonoRuntime == AndroidRuntimeFeature.IsCoreClrRuntime) {
throw new NotSupportedException ("Internal error: exactly one of AndroidRuntimeFeature.IsMonoRuntime or AndroidRuntimeFeature.IsCoreClrRuntime must be enabled.");
}

IntPtr total_timing_sequence = IntPtr.Zero;
Expand Down Expand Up @@ -157,7 +156,7 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)

args->propagateUncaughtExceptionFn = (IntPtr)(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void>)&PropagateUncaughtException;

if (!RuntimeFeature.TrimmableTypeMap) {
if (!AndroidRuntimeFeature.TrimmableTypeMap) {
args->registerJniNativesFn = (IntPtr)(delegate* unmanaged<IntPtr, int, IntPtr, IntPtr, int, void>)&RegisterJniNatives;
}
RunStartupHooksIfNeeded ();
Expand All @@ -170,11 +169,11 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)

internal static JniRuntime.JniTypeManager CreateTypeManager (JnienvInitializeArgs args)
{
if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
return new TrimmableTypeMapTypeManager ();
}

if (RuntimeFeature.IsNativeAotRuntime || RuntimeFeature.ManagedTypeMap) {
if (AndroidRuntimeFeature.IsNativeAotRuntime || AndroidRuntimeFeature.ManagedTypeMap) {
return new ManagedTypeManager ();
}

Expand All @@ -183,15 +182,15 @@ internal static JniRuntime.JniTypeManager CreateTypeManager (JnienvInitializeArg

internal static JniRuntime.JniValueManager CreateValueManager ()
{
if (RuntimeFeature.IsMonoRuntime) {
if (AndroidRuntimeFeature.IsMonoRuntime) {
return new AndroidValueManager ();
}

if (RuntimeFeature.IsCoreClrRuntime) {
if (AndroidRuntimeFeature.IsCoreClrRuntime) {
return new JavaMarshalValueManager ();
}

if (RuntimeFeature.IsNativeAotRuntime) {
if (AndroidRuntimeFeature.IsNativeAotRuntime) {
return new JavaMarshalValueManager ();
}

Expand All @@ -217,14 +216,14 @@ static void InitializeCommonState (JnienvInitializeArgs args)

static void InitializeTrimmableTypeMapDataIfNeeded ()
{
if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
InitializeTrimmableTypeMapData ();
}
}

static void RegisterTrimmableTypeMapNativeMethodsIfNeeded ()
{
if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
// TypeMapLoader.Initialize() only loads managed typemap data. Registering
// mono.android.Runtime natives requires JniRuntime.Current and its ClassLoader.
TrimmableTypeMap.RegisterNativeMethods ();
Expand All @@ -242,9 +241,9 @@ static void InitializeTrimmableTypeMapData ()
static void RunStartupHooksIfNeeded ()
{
// Return if startup hooks are disabled or not CoreCLR
if (!RuntimeFeature.IsCoreClrRuntime)
if (!AndroidRuntimeFeature.IsCoreClrRuntime)
return;
if (!RuntimeFeature.StartupHookSupport)
if (!AndroidRuntimeFeature.StartupHookSupport)
return;

RunStartupHooks ();
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal unsafe static partial class RuntimeNativeMethods

[LibraryImport (RuntimeConstants.InternalDllName, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv (CallConvs = new[] { typeof (CallConvCdecl) })]
internal static partial IntPtr clr_typemap_managed_to_java (string fullName, IntPtr mvid);
internal static partial IntPtr clr_typemap_managed_to_java (string? fullName, IntPtr mvid);

[LibraryImport (RuntimeConstants.InternalDllName, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv (CallConvs = new[] { typeof (CallConvCdecl) })]
Expand Down
6 changes: 3 additions & 3 deletions src/Mono.Android/Java.Interop/JavaConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ params Type [] typeArguments
if (target.IsArray)
return (h, t) => JNIEnv.GetArray (h, t, target.GetElementType ());

if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
var factoryConverter = TryGetFactoryBasedConverter (target);
if (factoryConverter != null)
return factoryConverter;
Expand Down Expand Up @@ -148,7 +148,7 @@ params Type [] typeArguments
if (!typeof (IJavaPeerable).IsAssignableFrom (elementType))
return null;

if (RuntimeFeature.TrimmableTypeMap) {
if (AndroidRuntimeFeature.TrimmableTypeMap) {
return TrimmableTypeMap.Instance?.GetContainerFactory (elementType);
}

Expand Down Expand Up @@ -198,7 +198,7 @@ public ArrayElementConverter (Array array)
return JNIEnv.GetArray (handle, transfer, elementType.GetElementType ());

if (elementType != null && typeof (IJavaPeerable).IsAssignableFrom (elementType)) {
if (RuntimeFeature.TrimmableTypeMap)
if (AndroidRuntimeFeature.TrimmableTypeMap)
return FromJniHandleWithTrimmableTypeMapping (handle, transfer, elementType);
return Java.Lang.Object.GetObject (handle, transfer, elementType);
}
Expand Down
Loading
Loading