Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] Use the same coop gc macro names as mono master does. #1

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d4d652
SIGPIPE FIXME: this should probably be fixed inside mono.
rolfbjarne Feb 15, 2016
1bd844e
[runtime] Make xamarin_[create|release]_managed_ref icalls.
rolfbjarne Feb 15, 2016
5f0234a
[runtime] Remove debug printf I haven't figured out how to fix.
rolfbjarne Feb 15, 2016
30ed6c8
[runtime] Replace xamarin_try_get_nsobject with xamarin_has_nsobject.
rolfbjarne Feb 17, 2016
b0ab6e2
[builds] Enable checked builds for watchOS for now, to make it easier…
rolfbjarne May 13, 2016
3643e02
Initial review pass for COOP for watchOS.
rolfbjarne Feb 15, 2016
fbb2f38
[builds] Use the right configure flag to enable checked builds.
rolfbjarne May 13, 2016
02a9f86
[runtime] Use xamarin_process_nsexception instead of xamarin_throw_ns…
rolfbjarne May 16, 2016
3273778
[runtime] mono_set_pending_exception expects to be in GC Unsafe mode.
rolfbjarne May 16, 2016
b5ddc1a
[runtime] Add a MONO_ASSERT_GC_SAFE_OR_DETACHED.
rolfbjarne May 16, 2016
74eb356
[runtime] Attach the current thread in xamarin_invoke_trampoline.
rolfbjarne May 16, 2016
db8e962
[msbuild] Import the F# targets before our AppExtension overrides, so…
rolfbjarne May 16, 2016
0530535
[registrar] Remove debug spew.
rolfbjarne May 17, 2016
07d1090
[runtime] Make sure to switch to GC SAFE before calling xamarin_switc…
rolfbjarne May 18, 2016
d075e5e
Bump maccore to get sln generation fixes.
rolfbjarne May 18, 2016
6befc20
Bump mono to get watchbcl fix.
rolfbjarne May 18, 2016
fa0da10
Bump maccore to get fix for watchOS test solutions.
rolfbjarne May 18, 2016
fd06968
[builds] Use the mono from watch-mono repo for bwatch-mono.
rolfbjarne May 18, 2016
b16a867
Bump maccore to get fix for watchOS BCL test project.
rolfbjarne May 19, 2016
452178d
[msbuild] Make sure CFBundleShortVersionString is set to something.
rolfbjarne May 19, 2016
2107654
Bump maccore to get a few fixes for the generation of watchOS test pr…
rolfbjarne May 19, 2016
4cc413c
[runtime] Use the same coop gc macro names as mono master does.
vargaz May 20, 2016
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
6 changes: 5 additions & 1 deletion builds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ $(PREFIX)/lib/mono/Xamarin.TVOS/%.mdb: $(BUILD_DESTDIR)/tvos/bcl/%.mdb | $(PREFI
$(PREFIX)/bin/btv-mono: $(BUILD_DESTDIR)/tools64/bin/mono | $(PREFIX)/bin
$(Q) install -s -m 0755 $< $@

$(PREFIX)/bin/bwatch-mono: $(BUILD_DESTDIR)/tools64/bin/mono | $(PREFIX)/bin
$(PREFIX)/bin/bwatch-mono: $(BUILD_DESTDIR)/watchbcl/bin/mono | $(PREFIX)/bin
$(Q) install -s -m 0755 $< $@

# copy to temporary directory before signing / mdb-rebasing,
Expand Down Expand Up @@ -961,6 +961,10 @@ WATCHSIMULATOR_CONFIGURE_FLAGS = \
--enable-native-types \
$(XAMARIN_CONFIGURE_FLAGS) \

# FIXME: remove --with-checked-build=yes when we've stabilized a bit.
WATCHSIMULATOR_CONFIGURE_FLAGS += \
--enable-checked-build=gc \

WATCHSIMULATOR_ACVARS = \
ac_cv_func_system=no \
ac_cv_func_pthread_kill=no \
Expand Down
2 changes: 1 addition & 1 deletion external/watch-mono
Submodule watch-mono updated 254 files
2 changes: 1 addition & 1 deletion mk/xamarin.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ifdef ENABLE_XAMARIN
NEEDED_MACCORE_VERSION := 53cb35859d3a645290a6cd879df574c52c3ba7f2
NEEDED_MACCORE_VERSION := eac2ab6b69ca5deed896997353ca4f0729fa85d6
NEEDED_MACCORE_BRANCH := master

MACCORE_DIRECTORY := maccore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ bool Compile (PDictionary plist)
if (!plist.ContainsKey (ManifestKeys.CFBundleSupportedPlatforms))
plist[ManifestKeys.CFBundleSupportedPlatforms] = new PArray { SdkPlatform };
plist.SetIfNotPresent (ManifestKeys.CFBundleVersion, "1.0");
plist.SetIfNotPresent (ManifestKeys.CFBundleShortVersionString, plist.GetCFBundleVersion ());

if (!SdkIsSimulator) {
SetValue (plist, "DTCompiler", sdkSettings.DTCompiler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved.

<DefineConstants>__UNIFIED__;__MOBILE__;__WATCHOS__;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<Import Project="Xamarin.WatchOS.AppExtension.Common.targets" />
<Import Project="$(FSharpTargets)" />
<Import Project="Xamarin.WatchOS.AppExtension.Common.targets" />

<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>
Expand Down
132 changes: 132 additions & 0 deletions runtime/COOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
LINKDUMP
*******

https://bugzilla.xamarin.com/show_bug.cgi?id=35727
https://gist.githubusercontent.com/ludovic-henry/2ab3dc14c1640ea47ba5/raw/01533181f3f03aa264a39b67757058b5a1766ca4/mono.diff
https://github.com/mono/mono/pull/2593
https://github.com/ludovic-henry/mono/commit/12a4f74287b471a9a4e823ba043fbbdb8630570e

Coop GC
=======

WatchOS requires a cooperative GC, which means our runtime
needs to use the proper API for the cooperative GC to work
properly.

http://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#gc-unsafe-mode
https://docs.google.com/presentation/d/1Sa361Ru8ccRRZCm4BN2NUXPf2k5VYYrjqpGKsV1cPnI/edit#slide=id.p


Rules
=====

1. When touching (reading or writing) managed memory, we must
be in GC UNSAFE mode.

2. When calling code we don't have control over (that can take
an unbound amount of time), we must switch to GC SAFE mode.
This includes calling any ObjC selector on any object.

Review
======

* bindings-generated.m [DONE]
* bindings.m [DONE]
* extension-main.m [DONE]
* launcher.m [MAC ONLY; NOT DONE]
* mono-runtime.m [PASS-THROUGH ONLY]
* monotouch-debug.m [DONE]
* monotouch-main.m [COMPLETE-ISH]
* nsstring-localization.m [DONE]
* runtime.m [FIRST PASS]
* shared.m [DONE]
* trampolines-i386.m [DONE]
* trampolines-invoke.m [FIRST PASS DONE; SEE PENDING NOTE BELOW]
* trampolines-x86_64.m [DONE]
* trampolines.m [FIRST PASS DONE]
* xamarin-support.m [DONE]
* zlib-helper.c [NO MANAGED CODE AT ALL]

StaticRegistrar.cs [FIRST PASS DONE; SEE PENDING NOTE BELOW]

Pending
=======

Exceptions
----------

Exceptions must be caught when returning from managed code.

* Provide a **exc to mono_runtime_invoke. Then we can either:

1. Convert to NSException, and throw that.
2. Abort.

* Somehow handle exceptions when calling into our delegates
(look at mono_method_get_unmanaged_thunk)

* Review all usages of mono_raise_exception. We have the same
choice as before: either convert to NSException, or abort.

* See also mono_method_get_unmanaged_thunk for when invoking delegates.

* Add support for catching ObjC exceptions just before
returning to managed code. Installing an unhandled
ObjC exception hook is not possible, because we can't
throw managed exceptions in native code (we can set
a flag that a managed exception should be thrown
when returning from native to managed code (on the
n2m boundary), and to do that we need to handle ObjC
exceptions in that n2m boundary).

xamarin_invoke_trampoline
-------------------------

Looks like we need a handle API to properly construct the
parameters to the managed function while at the same time
being able to switch to safe mode when we call code we
don't control (we have an array of data that can be pointers
to managed objects, and need a way to register those pointers
with managed code).

Static registrar
----------------

This has the same problem as xamarin_invoke_trampoline,
having to construct parameters to a managed function
while at the same time being able to switch to safe mode.

ObjectWrapper
-------------

This is not safe, and must be replaced with safe alternatives:

* icall
* GCHandle

mono_jit_thread_attach
----------------------

If a thread is not attached, it will change the state from
STARTING to RUNNING. If the thread is attached, it will do nothing.
The caller needs to know when this happens, to be able to react
accordingly.

Debugging tips
==============

* Tell lldb to attach when the watch extension launches:

process attach --waitfor --name "com.xamarin.monotouch-test.watchkitapp.watchkitextension"

* Something went wrong in a thread, and now that thread is doing something very different.

1. Put a breakpoint on pthread_setname_np, and check the assigned name: `p (char *) *(void **) ($esp + 4)`
2. Once you've located the thread you're debugging, set a thread-specific breakpoint:

break set -n mono_threads_reset_blocking_start -t 0x42b005
break set -n mono_threads_reset_blocking_end -t 0x42b005

* Display the current thread state:

display (void *) mono_thread_info_current ()->thread_state
5 changes: 5 additions & 0 deletions runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Native runtime

This directory contains the native runtime for Xamarin.iOS and Xamarin.Mac.

Cooperative GC
==============

See COOP.md

Generated code
==============

Expand Down
8 changes: 4 additions & 4 deletions runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ static void Write_objc_msgSend (StringWriter writer, FunctionData func)
// @catch
if (func.MarshalExceptions) {
writer.WriteLine ("\t} @catch (NSException *e) {");
writer.WriteLine ("\t\txamarin_throw_ns_exception (e);");
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
writer.WriteLine ("\t}");
}

Expand Down Expand Up @@ -1579,7 +1579,7 @@ static void Write_objc_msgSendSuper (StringWriter writer, FunctionData func)
// @catch
if (func.MarshalExceptions) {
writer.WriteLine ("\t} @catch (NSException *e) {");
writer.WriteLine ("\t\txamarin_throw_ns_exception (e);");
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
writer.WriteLine ("\t}");
}

Expand Down Expand Up @@ -1653,7 +1653,7 @@ static void Write_objc_msgSend_stret (StringWriter writer, FunctionData func)
// @catch
if (func.MarshalExceptions) {
writer.WriteLine ("\t} @catch (NSException *e) {");
writer.WriteLine ("\t\txamarin_throw_ns_exception (e);");
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
writer.WriteLine ("\t}");
}

Expand Down Expand Up @@ -1727,7 +1727,7 @@ static void Write_objc_msgSendSuper_stret (StringWriter writer, FunctionData fun
// @catch
if (func.MarshalExceptions) {
writer.WriteLine ("\t} @catch (NSException *e) {");
writer.WriteLine ("\t\txamarin_throw_ns_exception (e);");
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
writer.WriteLine ("\t}");
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/bindings.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
return ((float_send) objc_msgSend) (self, sel);
#endif
} @catch (NSException *e) {
xamarin_throw_ns_exception (e);
xamarin_process_nsexception (e);
}
}

Expand All @@ -40,7 +40,7 @@
// there is no objc_msgSendSuper_fpret: http://lists.apple.com/archives/objc-language/2006/Jun/msg00012.html
return ((float_sendsuper) objc_msgSendSuper) (super, sel);
} @catch (NSException *e) {
xamarin_throw_ns_exception (e);
xamarin_process_nsexception (e);
}
}

Expand All @@ -54,7 +54,7 @@
return ((nfloat_send) objc_msgSend) (self, sel);
#endif
} @catch (NSException *e) {
xamarin_throw_ns_exception (e);
xamarin_process_nsexception (e);
}
}

Expand All @@ -65,7 +65,7 @@
// there is no objc_msgSendSuper_fpret: http://lists.apple.com/archives/objc-language/2006/Jun/msg00012.html
return ((nfloat_sendsuper) objc_msgSendSuper) (super, sel);
} @catch (NSException *e) {
xamarin_throw_ns_exception (e);
xamarin_process_nsexception (e);
}
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
"SEL", "IntPtr", "sel"
) { WrappedManagedFunction = "GetMethodForSelector" },

new XDelegate ("MonoObject *", "IntPtr", "xamarin_try_get_nsobject",
"id", "IntPtr", "obj"
) { WrappedManagedFunction = "TryGetNSObjectWrapped" },

new XDelegate ("MonoObject *", "IntPtr", "xamarin_get_nsobject",
"id", "IntPtr", "obj"
) { WrappedManagedFunction = "GetNSObjectWrapped" },

new XDelegate ("bool", "bool", "xamarin_has_nsobject",
"id", "IntPtr", "obj"
) { WrappedManagedFunction = "HasNSObject" },

new XDelegate ("id", "IntPtr", "xamarin_get_handle_for_inativeobject",
"MonoObject *", "IntPtr", "obj"
) { WrappedManagedFunction = "GetHandleForINativeObject" },
Expand Down
44 changes: 41 additions & 3 deletions runtime/exports.t4
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,14 @@

#region mini/mini.h

new Export ("MonoDomain *", "mono_jit_thread_attach",
"MonoDomain *", "domain"
new Export ("void*", "mono_jit_thread_attach",
"MonoDomain *", "domain",
"void *", "dummy"
),

new Export ("void", "mono_jit_thread_detach",
"void *", "cookie",
"void *", "dummy"
),

new Export ("gboolean", "mono_exception_walk_trace",
Expand Down Expand Up @@ -560,8 +566,40 @@

new Export ("void", "mono_trace_set_printerr_handler",
"MonoPrintCallback", "callback"
)
),

#endregion

#region utils/mono-threads-api.h

new Export ("void*", "mono_threads_enter_gc_unsafe_region",
"void **", "stackdata"
),

new Export ("void", "mono_threads_exit_gc_unsafe_region",
"void *", "cookie",
"void **", "stackdata"
),

new Export ("void*", "mono_threads_enter_gc_safe_region",
"void **", "stackdata"
),

new Export ("void", "mono_threads_exit_gc_safe_region",
"void *", "cookie",
"void **", "stackdata"
),

new Export ("void", "mono_threads_assert_gc_safe_region" ),

new Export ("void", "mono_threads_assert_gc_unsafe_region" ),

new Export ("void", "mono_threads_assert_gc_starting_region" ),

#endregion

#region utils/mono-threads.h
new Export ("void*", "mono_thread_info_current_unchecked" ),
#endregion
};
#><#+
Expand Down
Loading