Граф коммитов

45 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 3ea9fddc7b [runtime] Check in container app's root directory for assemblies.
If an extension is sharing code with the container app, then assemblies may be
placed in:

* The container app's Framework directory (for assemblies whose code is
  shared, and the build action is 'framework'). We already handle this case.
* The container app's root directory (for assemblies whose code is shared, and
  the build action is not 'framework'). This case we didn't handle, and we're
  now fixing it.
* In the extension (for assemblies whose code is not shared). We already
  handle this case.
2017-02-10 16:39:13 +01:00
Rolf Bjarne Kvinge dea33a6770 [runtime] Lookup assembly-related resources from parent bundles as well.
Add support for finding assembly-related resources (debug files, config files,
satellite assemblies, aotdata files, etc) in multiple locations:

* The bundle's root directory.
* A pointer-size specific size directory (.monotouch-32|64)
* A framework's MonoBundle directory (and the framework may not be named after
  the assembly, which means it's not necessarily possible to deduce the
  framework's name at runtime).
* In a container bundle.

Some files may also have an arch-specific suffix.
2017-02-10 14:29:10 +01:00
Chris Hamons 2c835c5294 [XM] Add hybrid/standard AOT option and improve AOT code (#1650)
* [XM] Seperate parsing from compilation in AOT code

- Parsing command line options was too entangled with actually compiling
- Refactor test code to centralize Compile, reducing some complexity of tests
- Groundwork for hybrid vs non-hybrid AOT work

* Add hybrid/standard AOT support

* Add xammac_tests to makefile/jenkins

* Add flag to force AOT

* Disable MonoTouchFixtures.Contacts.ContactStoreTest.GetUnifiedContacts on XM due to prompts on Jenkins
2017-02-08 13:40:48 -06:00
Chris Hamons ffe142d0b5 [XM] AOT support in Xamarin.Mac (#1340) 2017-01-11 14:10:39 -06:00
Rolf Bjarne Kvinge c00dbbb30c [runtime] Assert instead of exiting with a printf. (#1222)
Asserting produces a potentially useful crash report, while just exiting doesn't.
2016-11-21 14:39:16 +01:00
Rolf Bjarne Kvinge 7728c4cd19 [registrar] Use metadata tokens instead of strings to find types and methods. (#1085)
Use metadata tokens instead of strings to find types and methods.

This makes the code to find methods more compact (a lot less strings in the
executable, and additionally in most cases a compact representation (32-bit
integer) of the corresponding metadata token and additional information can be
used, which results in less executable code (fewer parameters to methods,
etc)), resulting in smaller executables.

Size savings are around 200kb for dont link apps, and 20-60kb for linked apps
(this obviously varies a lot depending on how much has to registered by the
registrar).

|                |    Before     |     After     |       Diff        |
|----------------|--------------:|--------------:|------------------:|
| dontlink/32bit |  102.810.144  |  102.609.456  | -200.688 = -0,20% |
| dontlink/64bit |  107.420.576  |  107.221.792  | -198.784 = -0,19% |
| linksdk/32bit  |   40.957.296  |   40.936.864  |  -20.432 = -0,05% |
| linksdk/64bit  |   43.113.136  |   43.093.936  |  -19.200 = -0,04% |
| linkall/32bit  |   38.410.032  |   38.348.288  |  -61.744 = -0,16% |
| linkall/64bit  |   40.315.200  |   40.267.344  |  -47.856 = -0,12% |

Additionally I've removed the `lazy_map` dictionary, which we populated at
startup and was used to map between Class instances and the corresponding
managed type's FullName, and instead iterate over a native array of Class ->
metadata token mappings whenever we need to look up the managed type for a
certain Class instance.

This is slightly slower for each type we need to look up (for a non-linked app
there might be a 2000-3000 entries in the native array, which would be
iterated instead of using a hashtable lookup), but it's only done once per
type and there's a significant startup memory improvement.

For a non-linked test app I get the following using the Xamarin profiler:

|                   |  Before |  After  |       Diff      |
|-------------------|--------:|--------:|----------------:|
| Memory allocated  |  2,8 MB |  2,4 MB | -0,4 MB = -14 % |
| Objects allocated |   43678 |   38463 |   -5215 = -12 % |
| Private bytes     | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
| Working set       | 26,6 MB | 24,4 MB | -2,2 MB = -8,3% |
2016-11-01 14:34:56 -04:00
Rolf Bjarne Kvinge 4aea22ef15 [ObjCRuntime] Store a pointer to the initialization options in managed memory. (#1076)
This makes it possible to access the initialization options at a later point
(soon to be used by the registrar).
2016-11-01 12:40:51 +01:00
Rolf Bjarne Kvinge 0c43ddc615 Disable managed exception marshaling when the debugger is attached. Fixes #45116. (#1055)
Managed exception marshaling interferes with the debugger, because it adds
exception handlers to executing code, which makes the Mono runtime think an
exception is handled when logically it's not (although technically it is).

The consequence is that the IDEs will only be notified when we re-throw the
exception after catching it, making it impossible for the IDEs to stop when
the exception is thrown (they will instead stop when we re-throw the
exception).

So disable managed exception marshaling (unless the user changed the default
behavior) when a debugger is attached.

This is the same behavior as Xamarin.Android.

https://bugzilla.xamarin.com/show_bug.cgi?id=45116
2016-10-28 19:07:01 +02:00
Rolf Bjarne Kvinge 71a578ee38 [runtime] Remove deprecated and ignored mono option. (#1019)
Setting this option prints this to stdout:

> Mono Warning: option gen-compact-seq-points is deprecated.

and it's ignored, so just don't set this option.
2016-10-27 16:04:19 -04:00
Rolf Bjarne Kvinge 94485580b5 Use ExceptionDispatchInfo to keep stack traces when unhandled exceptions are marshaled. Improves bug #45742 a bit. (#1040)
Example code:

	public override void ViewDidLoad ()
	{
		throw new Exception ("USELESS");
	}

Current output with unhandled exceptions that are marshaled:

    Unhandled Exception:
    System.Exception: USELESS
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10
    [ERROR] FATAL UNHANDLED EXCEPTION: UselessExceptions.CustomException: USELESS
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10

Note how the managed frame where the exception was thrown does not show up.

This is because we technically catch exceptions when marshaling them, and then
later we call mono_raise_exception to raise the same exception. Unfortunately
that leads to overwriting the initial stack trace, and we end up with a stack
trace that does not include the location where the original exception was
thrown.

So instead of calling mono_raise_exception to rethrow the same exception, we
use ExceptionDispatchInfo, which is able to capture the stack trace for both
the original exception and the new exception, producing the following output:

    System.Exception: USELESS
      at UselessExceptions.ViewController.ViewDidLoad () [0x0000c] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/ViewController.cs:27
    --- End of stack trace from previous location where exception was thrown ---
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10
    [ERROR] FATAL UNHANDLED EXCEPTION: UselessExceptions.CustomException: USELESS
      at UselessExceptions.ViewController.ViewDidLoad () [0x0000c] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/ViewController.cs:27
    --- End of stack trace from previous location where exception was thrown ---
      at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
      at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /work/maccore/master/xamarin-macios/src/AppKit/NSApplication.cs:98
      at UselessExceptions.MainClass.Main (System.String[] args) [0x00007] in /Users/rolf/Downloads/filed-bug-test-cases-master/Xamarin/bxc45742/Main.cs:10

Incidently this is how Xamarin.Android does it [1].

[1]: 9387f2fe16

https://bugzilla.xamarin.com/show_bug.cgi?id=45742
2016-10-27 20:03:11 +02:00
Rolf Bjarne Kvinge 0863e412b4 Remove XI/Classic support (#926)
* [tests] Remove Classic SDK tests.

* Remove XI/Classic support.

This also means we can remove support for the legacy registrars.

* [monotouch-test] Remove legacy registrar tests.

* [tests/mtouch] Remove Classic tests (and legacy registrar logic).

* [tests/scripted] Fix tests to reference Xamarin.iOS.dll.
2016-09-30 15:02:17 -04:00
Rolf Bjarne Kvinge 1412b5bbed Remove any code related to the IL registrar. (#874)
We've used the dynamic registrar for years now when selecting the IL registrar
(and I've never heard about anybody doing it), so just remove all the related
(and in fact dead) code.
2016-09-22 14:27:54 +02:00
Rolf Bjarne Kvinge 8be3807162 [runtime] Re-enable the GC pump on watchOS to help track down issues. (#838) 2016-09-15 14:24:32 -04:00
Rolf Bjarne Kvinge 3eb0fdfdea [runtime] Fix compiler warning (unicode character treated as whitespace). (#822) 2016-09-13 10:04:15 -04:00
Sebastien Pouliot 38148c718a Merge branch 'xcode8' 2016-09-09 15:29:37 -04:00
Rolf Bjarne Kvinge cfb84f6e17 [runtime] Use printf on watchOS, NSLog doesn't shown up (by default) (#772)
* [runtime] Use printf on watchOS, NSLog doesn't shown up (by default).

* [runtime] Use a wrapper function for logging.

So that we can chose between printf and NSLog at runtime,
depending on where we're running.
2016-09-06 16:55:23 -04:00
Chris Hamons 1c6e1959b7 [XM] Add support for disabling lldb attach on crash (#670)
- https://bugzilla.xamarin.com/show_bug.cgi?id=23482
2016-08-25 13:06:38 -05:00
Rolf Bjarne Kvinge 22921dd8b7 [runtime] Fix a crash that occurs when Objective-C holds weak references. Fixes #39236. (#501)
Fix xamarin_switch_gchandle to not crash if the gchandle happens
to point to null (a collected object).

https://bugzilla.xamarin.com/show_bug.cgi?id=39236
2016-07-27 17:43:28 +02:00
Rolf Bjarne Kvinge 6e1f5c631b [runtime] Fix a crash that occurs when Objective-C holds weak references. Fixes #39236. (#500)
Fix xamarin_switch_gchandle to not crash if the gchandle happens
to point to null (a collected object).

https://bugzilla.xamarin.com/show_bug.cgi?id=39236
2016-07-27 12:47:35 +02:00
Rolf Bjarne Kvinge e6fc5a15d0 [runtime] Parse unions in objc encodings correctly. Fixes #42452. (#394)
Unions are defined as follows:

    (name=type...)

and we were not correctly parsing the 'name=' part.

https://bugzilla.xamarin.com/show_bug.cgi?id=42452
2016-07-14 18:03:02 +02:00
Rolf Bjarne Kvinge 249cf2f402 [runtime] Parse unions in objc encodings correctly. Fixes #42452. (#382)
Unions are defined as follows:

    (name=type...)

and we were not correctly parsing the 'name=' part.

https://bugzilla.xamarin.com/show_bug.cgi?id=42452
2016-07-12 20:19:06 -04:00
Rolf Bjarne Kvinge 2d28e24837 [runtime] Handle any exceptions whenever we return from managed code. 2016-06-08 20:05:54 +02:00
Rolf Bjarne Kvinge 5e302f9719 [runtime] Catch and process managed exceptions that are thrown in reverse P/Invoke (delegate) callbacks. 2016-06-08 20:05:54 +02:00
Rolf Bjarne Kvinge 71f4d78b18 [runtime] Generated binding wrappers that catch ObjC exceptions are supposed to always convert to managed exceptions. (#133) 2016-06-06 14:33:37 +02:00
Zoltan Varga 5270b63cee [runtime] Use the same coop gc macro names as mono master does. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge 13b7c6dd11 [runtime] Make sure to switch to GC SAFE before calling xamarin_switch_gchandle. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge 4a5ce42b48 [runtime] Add a MONO_ASSERT_GC_SAFE_OR_DETACHED.
Since MONO_ASSERT_GC_SAFE asserts when executed on a detached thread,
and yet it's clearly safe for the GC to run when a thread is detached.
2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge d7bdc5d126 [runtime] mono_set_pending_exception expects to be in GC Unsafe mode. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge af0d01c93a Initial review pass for COOP for watchOS. 2016-05-26 17:47:10 +02:00
Rolf Bjarne Kvinge fc0f656a53 [runtime] Make xamarin_[create|release]_managed_ref icalls.
This way we can pass pointers to managed objects to the native objects
without the coop GC interfering (since icalls won't automatically
switch to "gc safe" mode).
2016-05-26 17:47:10 +02:00
Chris Hamons ca028ea150 [Mac] Add support for os x extensions (#83) 2016-05-25 17:20:33 -04:00
Rolf Bjarne Kvinge cffc2e9181 Rewrite user-visible messages to use 'cooperative mode' instead of 'coop'.
This seems to be how we describe it publicly: http://tirania.org/blog/archive/2015/Dec-22.html
2016-05-17 11:30:38 +02:00
Rolf Bjarne Kvinge 53582429ec [runtime] Use the right condition when to reference libxammac.dylib vs __Internal. 2016-05-17 11:24:03 +02:00
Rolf Bjarne Kvinge f478657298 [runtime] Only insert dllmap for exception marshalling when the ObjC runtime supports zero-cost exceptions. 2016-05-17 11:24:03 +02:00
Rolf Bjarne Kvinge e8e8d6ea43 [runtime] Fix lookup of the inner exception when printing exception messages. 2016-05-17 11:24:02 +02:00
Rolf Bjarne Kvinge 79c68238ce [runtime] Don't use NSMethodSignature to compute frame size, it can't handle all method signature encodings.
In particular NSMethodSignature chokes on encodings like this:

	[NSDecimalNumber initWithDecimal:] = "@36@0:8{?=b8b4b1b1b18[8S]}16"

with an exception:

	NSInvalidArgumentException Reason: +[NSMethodSignature signatureWithObjCTypes:]: unsupported type encoding spec '{?}'

so implement our own code to calculate the frame size.
2016-05-17 11:24:02 +02:00
Rolf Bjarne Kvinge 3ac40ab007 [runtime] Improve a few assertion messages to include more information. 2016-05-17 11:24:02 +02:00
Rolf Bjarne Kvinge 1f1f6991a3 Implement support for exception marshalling. 2016-05-17 11:23:48 +02:00
Rolf Bjarne Kvinge 9b4f7532ab Add runtime variable to specify the exception marshalling modes, and mmp/mtouch options to select it. 2016-05-17 11:20:26 +02:00
Rolf Bjarne Kvinge b8abf3db01 Add runtime variable to specify if the Coop GC should be used, and a mmp/mtouch option to select it.
The mmp/mtouch option is hidden for now, since it's not actually possible
to select the Coop GC yet.
2016-05-17 11:20:26 +02:00
Rolf Bjarne Kvinge 50c65cf90b [runtime] Extract logic in xamarin_unhandled_exception_handler to collect exception information to a separate function.
So that we can later re-use this logic somewhere else.
2016-05-17 11:20:26 +02:00
Rolf Bjarne Kvinge a4dffa6a78 [runtime] Disable the GC pump for Xamarin.Mac. (#52)
It seems it prevents the app from exiting; Mono will wait
for the GC pump thread to exit, which never happens.

The GC pump was never enabled for Xamarin.Mac apps
until recently (d9677714a), so this will just revert
to the previous behavior.

    thread 1: tid = 0x2ab2bf5, 0x00007fff97815eb2 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'tid_50f', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
      frame 0: 0x00007fff97815eb2 libsystem_kernel.dylib`__psynch_cvwait + 10
      frame 1: 0x00007fff89015150 libsystem_pthread.dylib`_pthread_cond_wait + 767
      frame 2: 0x000000010ceb1283 MobileTestApp`_wapi_handle_timedwait_signal_handle [inlined] mono_os_cond_wait(cond=<unavailable>, mutex=<unavailable>) + 8 at mono-os-mutex.h:107 [opt]
      frame 3: 0x000000010ceb127b MobileTestApp`_wapi_handle_timedwait_signal_handle [inlined] mono_os_cond_timedwait(cond=<unavailable>, mutex=0x00007fb085016210, timeout_ms=<unavailable>) at mono-os-mutex.h:122 [opt]
      frame 4: 0x000000010ceb127b MobileTestApp`_wapi_handle_timedwait_signal_handle(handle=0x0000000000000400, timeout=<unavailable>, alertable=1, poll=0, alerted=0x00007fff52fb4984) + 1003 at handles.c:1555 [opt]
      frame 5: 0x000000010cec3d87 MobileTestApp`wapi_WaitForMultipleObjectsEx(numobjects=2, handles=<unavailable>, waitall=0, timeout=4294967295, alertable=<unavailable>) + 1527 at wait.c:615 [opt]
      frame 6: 0x000000010ce692b6 MobileTestApp`mono_thread_manage + 57 at threads.c:2956 [opt]
      frame 7: 0x000000010ce6927d MobileTestApp`mono_thread_manage + 301 at threads.c:3162 [opt]
      frame 8: 0x000000010ccbb533 MobileTestApp`mono_main(argc=<unavailable>, argv=<unavailable>) + 7987 at driver.g.c:2181 [opt]
      frame 9: 0x000000010cc61c67 MobileTestApp`main(argc=1, argv=0x00007fff52fb5268) + 775 at launcher.m:562
      frame 10: 0x000000010cc63150 MobileTestApp`start + 52

    thread 2: tid = 0x2ab2bf7, 0x00007fff97816ff6 libsystem_kernel.dylib`kevent_qos + 10, queue = 'com.apple.libdispatch-manager'
      frame 0: 0x00007fff97816ff6 libsystem_kernel.dylib`kevent_qos + 10
      frame 1: 0x00007fff88f18099 libdispatch.dylib`_dispatch_mgr_invoke + 216
      frame 2: 0x00007fff88f17d01 libdispatch.dylib`_dispatch_mgr_thread + 52

    thread 3: tid = 0x2ab2bfa, 0x00007fff97815eb2 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
      frame 0: 0x00007fff97815eb2 libsystem_kernel.dylib`__psynch_cvwait + 10
      frame 1: 0x00007fff89015150 libsystem_pthread.dylib`_pthread_cond_wait + 767
      frame 2: 0x000000010ceab31c MobileTestApp`thread_func [inlined] mono_os_cond_wait(mutex=0x000000010d02e190) + 15 at mono-os-mutex.h:107 [opt]
      frame 3: 0x000000010ceab30d MobileTestApp`thread_func(thread_data=0x0000000000000000) + 333 at sgen-thread-pool.c:110 [opt]
      frame 4: 0x00007fff89014c13 libsystem_pthread.dylib`_pthread_body + 131
      frame 5: 0x00007fff89014b90 libsystem_pthread.dylib`_pthread_start + 168
      frame 6: 0x00007fff89012375 libsystem_pthread.dylib`thread_start + 13

    thread 4: tid = 0x2ab2bfb, 0x00007fff978103c2 libsystem_kernel.dylib`semaphore_wait_trap + 10, name = 'Finalizer'
      frame 0: 0x00007fff978103c2 libsystem_kernel.dylib`semaphore_wait_trap + 10
      frame 1: 0x000000010cdb847b MobileTestApp`finalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) + 11 at mono-os-semaphore.h:72 [opt]
      frame 2: 0x000000010cdb8470 MobileTestApp`finalizer_thread + 11 at mono-coop-semaphore.h:40 [opt]
      frame 3: 0x000000010cdb8465 MobileTestApp`finalizer_thread(unused=<unavailable>) + 181 at gc.c:770 [opt]
      frame 4: 0x000000010ce6bb05 MobileTestApp`start_wrapper [inlined] start_wrapper_internal + 548 at threads.c:738 [opt]
      frame 5: 0x000000010ce6b8e1 MobileTestApp`start_wrapper(data=<unavailable>) + 49 at threads.c:785 [opt]
      frame 6: 0x000000010ced50f6 MobileTestApp`inner_start_thread(arg=<unavailable>) + 406 at mono-threads-posix.c:92 [opt]
      frame 7: 0x00007fff89014c13 libsystem_pthread.dylib`_pthread_body + 131
      frame 8: 0x00007fff89014b90 libsystem_pthread.dylib`_pthread_start + 168
      frame 9: 0x00007fff89012375 libsystem_pthread.dylib`thread_start + 13

    thread 5: tid = 0x2ab2c07, 0x00007fff97816206 libsystem_kernel.dylib`__semwait_signal + 10, name = 'tid_320b'
      frame 0: 0x00007fff97816206 libsystem_kernel.dylib`__semwait_signal + 10
      frame 1: 0x00007fff82df1d17 libsystem_c.dylib`nanosleep + 199
      frame 2: 0x00007fff82df1c0a libsystem_c.dylib`usleep + 54
      frame 3: 0x000000010cc5bc60 MobileTestApp`pump_gc(context=0x0000000000000000) + 64 at runtime.m:904
      frame 4: 0x00007fff89014c13 libsystem_pthread.dylib`_pthread_body + 131
      frame 5: 0x00007fff89014b90 libsystem_pthread.dylib`_pthread_start + 168
      frame 6: 0x00007fff89012375 libsystem_pthread.dylib`thread_start + 13
2016-05-16 08:12:49 -04:00
Rolf Bjarne Kvinge d9677714ad [runtime] Re-enable the gc pump by default for debug simulator/mac builds. (#50) 2016-05-13 09:49:08 -04:00
Rolf Bjarne Kvinge 7b863816b3 [runtime] Disable the GC pump for watchOS for now.
It causes the app to crash pretty much instantly.

This way watchOS apps at least runs until the app
itself wants to run the GC.
2016-04-26 12:48:11 -04:00
Rolf Bjarne Kvinge ac418df815 Build our runtime. 2016-04-24 14:47:24 -04:00