Skip to content

Commit

Permalink
Use mono_dangerous_add_raw_internal_call on watchOS for icall registr…
Browse files Browse the repository at this point in the history
…ation

Internal calls added with mono_dangerous_add_raw_internal_call run in GC Unsafe
mode under cooperative and hybrid suspend, whereas internal calls added with
mono_add_internal_call run in GC Safe mode since
mono/mono@5756ba4 in order for hybrid suspend
to be a transparent replacement for preemptive suspend (the old default).  The
icalls in GC Unsafe mode have a responsibility not to block indefinitely
without manually performing a thread state transition to GC Safe mode, and in
return they avoid a thread state transition when the icall is invoked from a
managed method.
  • Loading branch information
lambdageek committed Oct 23, 2018
1 parent da6602f commit 0ca749a
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@
uint8_t flags;
};

static void
xamarin_add_internal_call (const char *name, const void *method)
{
/* COOP: With cooperative GC, icalls will run, like manageed methods,
* in GC Unsafe mode, avoiding a thread state trandition. In return
* the icalls must guarantee that they won't block, or run indefinitely
* without a safepoint, by manually performing a transition to GC Safe
* mode. With backward-compatible hybrid GC, icalls run in GC Safe
* mode and the Mono API functions take care of thread state
* transitions, so don't need to perform GC thread state transitions
* themselves.
*
* Currently cooperative GC is only used by watchOS targets.
*/
#ifdef TARGET_OS_WATCH
mono_dangerous_add_raw_internal_call (name, method);
#else
mono_add_internal_call (name, method);
#endif
}

id
xamarin_get_nsobject_handle (MonoObject *obj)
{
Expand Down Expand Up @@ -881,7 +902,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;

mono_gc_toggleref_register_callback (gc_toggleref_callback);

mono_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::RegisterToggleRef" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::RegisterToggleRef", (const void *) gc_register_toggleref);
xamarin_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::RegisterToggleRef" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::RegisterToggleRef", (const void *) gc_register_toggleref);
mono_profiler_install ((MonoProfiler *) prof, NULL);
mono_profiler_install_gc (gc_event_callback, NULL);
}
Expand Down Expand Up @@ -1342,8 +1363,8 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
nsvalue_class = get_class_from_name (platform_image, foundation, "NSValue", true);
nsstring_class = get_class_from_name (platform_image, foundation, "NSString", true);

mono_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::xamarin_release_managed_ref" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::xamarin_release_managed_ref", (const void *) xamarin_release_managed_ref);
mono_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::xamarin_create_managed_ref" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::xamarin_create_managed_ref", (const void *) xamarin_create_managed_ref);
xamarin_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::xamarin_release_managed_ref" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::xamarin_release_managed_ref", (const void *) xamarin_release_managed_ref);
xamarin_add_internal_call (xamarin_use_new_assemblies ? "Foundation.NSObject::xamarin_create_managed_ref" : PRODUCT_COMPAT_NAMESPACE ".Foundation.NSObject::xamarin_create_managed_ref", (const void *) xamarin_create_managed_ref);

runtime_initialize = mono_class_get_method_from_name (runtime_class, "Initialize", 1);

Expand Down

0 comments on commit 0ca749a

Please sign in to comment.