Skip to content

Commit 2f93f76

Browse files
[monodroid] treat LocalRefsAreIndirect as always true (#9138)
There is an API < 14 code path, that seems like we can just *remove* and tread all local refs as indirect. This might speed up `IdentityHash.IdentityHash` a very small amount, as it no longer checks a `static bool` on each call.
1 parent ab412a5 commit 2f93f76

File tree

4 files changed

+4
-23
lines changed

4 files changed

+4
-23
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static Type MakeArrayType (Type type) =>
3939

4040
internal static IntPtr IdentityHash (IntPtr v)
4141
{
42-
return JNIEnvInit.LocalRefsAreIndirect ? RuntimeNativeMethods._monodroid_get_identity_hash_code (Handle, v) : v;
42+
return RuntimeNativeMethods._monodroid_get_identity_hash_code (Handle, v);
4343
}
4444

4545
public static void CheckHandle (IntPtr jnienv)

src/Mono.Android/Android.Runtime/JNIEnvInit.cs

-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ internal struct JnienvInitializeArgs {
2323
public uint logCategories;
2424
public int version; // TODO: remove, not needed anymore
2525
public int androidSdkVersion;
26-
public int localRefsAreIndirect;
2726
public int grefGcThreshold;
2827
public IntPtr grefIGCUserPeer;
2928
public int isRunningOnDesktop;
@@ -40,7 +39,6 @@ internal struct JnienvInitializeArgs {
4039
internal static bool AllocObjectSupported;
4140
internal static bool IsRunningOnDesktop;
4241
internal static bool jniRemappingInUse;
43-
internal static bool LocalRefsAreIndirect;
4442
internal static bool LogAssemblyCategory;
4543
internal static bool MarshalMethodsEnabled;
4644
internal static bool PropagateExceptions;
@@ -96,8 +94,6 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)
9694

9795
mid_Class_forName = new JniMethodInfo (args->Class_forName, isStatic: true);
9896

99-
LocalRefsAreIndirect = args->localRefsAreIndirect == 1;
100-
10197
bool androidNewerThan10 = args->androidSdkVersion > 10;
10298
BoundExceptionType = (BoundExceptionType)args->ioExceptionType;
10399
androidRuntime = new AndroidRuntime (args->env, args->javaVm, androidNewerThan10, args->grefLoader, args->Loader_loadClass, args->jniAddNativeMethodRegistrationAttributePresent != 0);

src/native/monodroid/monodroid-glue-internal.hh

-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ namespace xamarin::android::internal
9292
unsigned int logCategories;
9393
int version;
9494
int androidSdkVersion;
95-
int localRefsAreIndirect;
9695
int grefGcThreshold;
9796
jobject grefIGCUserPeer;
9897
int isRunningOnDesktop;
@@ -180,7 +179,6 @@ namespace xamarin::android::internal
180179
fnptr = reinterpret_cast<TFunc*>(symptr);
181180
}
182181

183-
int LocalRefsAreIndirect (JNIEnv *env, jclass runtimeClass, int version);
184182
void create_xdg_directory (jstring_wrapper& home, size_t home_len, std::string_view const& relative_path, std::string_view const& environment_variable_name) noexcept;
185183
void create_xdg_directories_and_environment (jstring_wrapper &homeDir);
186184
void lookup_bridge_info (MonoClass *klass, const OSBridge::MonoJavaGCBridgeType *type, OSBridge::MonoJavaGCBridgeInfo *info);

src/native/monodroid/monodroid-glue.cc

+3-16
Original file line numberDiff line numberDiff line change
@@ -772,21 +772,6 @@ MonodroidRuntime::create_domain (JNIEnv *env, jstring_array_wrapper &runtimeApks
772772
return domain;
773773
}
774774

775-
inline int
776-
MonodroidRuntime::LocalRefsAreIndirect (JNIEnv *env, jclass runtimeClass, int version)
777-
{
778-
if (version < 14) {
779-
java_System = nullptr;
780-
java_System_identityHashCode = 0;
781-
return 0;
782-
}
783-
784-
java_System = RuntimeUtil::get_class_from_runtime_field (env, runtimeClass, "java_lang_System", true);
785-
java_System_identityHashCode = env->GetStaticMethodID (java_System, "identityHashCode", "(Ljava/lang/Object;)I");
786-
787-
return 1;
788-
}
789-
790775
force_inline void
791776
MonodroidRuntime::lookup_bridge_info (MonoClass *klass, const OSBridge::MonoJavaGCBridgeType *type, OSBridge::MonoJavaGCBridgeInfo *info)
792777
{
@@ -851,7 +836,6 @@ MonodroidRuntime::init_android_runtime (JNIEnv *env, jclass runtimeClass, jobjec
851836
init.logCategories = log_categories;
852837
init.version = env->GetVersion ();
853838
init.androidSdkVersion = android_api_level;
854-
init.localRefsAreIndirect = LocalRefsAreIndirect (env, runtimeClass, init.androidSdkVersion);
855839
init.isRunningOnDesktop = is_running_on_desktop ? 1 : 0;
856840
init.brokenExceptionTransitions = application_config.broken_exception_transitions ? 1 : 0;
857841
init.packageNamingPolicy = static_cast<int>(application_config.package_naming_policy);
@@ -860,6 +844,9 @@ MonodroidRuntime::init_android_runtime (JNIEnv *env, jclass runtimeClass, jobjec
860844
init.jniRemappingInUse = application_config.jni_remapping_replacement_type_count > 0 || application_config.jni_remapping_replacement_method_index_entry_count > 0;
861845
init.marshalMethodsEnabled = application_config.marshal_methods_enabled;
862846

847+
java_System = RuntimeUtil::get_class_from_runtime_field (env, runtimeClass, "java_lang_System", true);
848+
java_System_identityHashCode = env->GetStaticMethodID (java_System, "identityHashCode", "(Ljava/lang/Object;)I");
849+
863850
// GC threshold is 90% of the max GREF count
864851
init.grefGcThreshold = static_cast<int>(AndroidSystem::get_gref_gc_threshold ());
865852

0 commit comments

Comments
 (0)