Skip to content

Commit

Permalink
[2018-08][watchos] Use mono_dangerous_add_raw_internal_call for watch…
Browse files Browse the repository at this point in the history
…OS icalls (#5030)

* Add optional mono_dangerous_add_raw_internal_call to exports.t4

* Use mono_dangerous_add_raw_internal_call on watchOS for icall registration

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 authored and rolfbjarne committed Oct 26, 2018
1 parent 0b27eef commit 7449e51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions runtime/exports.t4
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@
"const void *", "method"
),

new Export (true, "void", "mono_dangerous_add_raw_internal_call",
"const char *", "name",
"const void *", "method"
),

new Export ("MonoMethodSignature *", "mono_method_signature",
"MonoMethod *", "method"
),
Expand Down
25 changes: 22 additions & 3 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@
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.
*
*/
if (xamarin_is_gc_coop)
mono_dangerous_add_raw_internal_call (name, method);
else
mono_add_internal_call (name, method);
}

id
xamarin_get_nsobject_handle (MonoObject *obj)
{
Expand Down Expand Up @@ -881,7 +900,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 @@ -1359,8 +1378,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 7449e51

Please sign in to comment.