Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Adventures with Mono Runtime on Mobile Platforms

Weitere Verwandte Inhalte

Ähnliche Bücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Ähnliche Hörbücher

Kostenlos mit einer 30-tägigen Testversion von Scribd

Alle anzeigen

Adventures with Mono Runtime on Mobile Platforms

  1. 1. Adventures with Mono Runtime on Mobile Platforms .NET Stammtisch Linz Bernhard Urban beurba@microsoft.com https://www.xamarin.com https://www.mono-project.com July 23, 2019 foundation 1 / 13
  2. 2. 2 / 13
  3. 3. Xamarin 3 / 13
  4. 4. The Mono Runtime — Overview Execution modes 4 / 13
  5. 5. The Mono Runtime — Overview Execution modes Just-In-Time compiler 4 / 13
  6. 6. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler 4 / 13
  7. 7. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT 4 / 13
  8. 8. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT 4 / 13
  9. 9. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter 4 / 13
  10. 10. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms 4 / 13
  11. 11. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms Linux, macOS, Windows, *BSD, AIX, IBM i, . . . 4 / 13
  12. 12. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms Linux, macOS, Windows, *BSD, AIX, IBM i, . . . iOS, tvOS, watchOS & Android 4 / 13
  13. 13. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms Linux, macOS, Windows, *BSD, AIX, IBM i, . . . iOS, tvOS, watchOS & Android XBox, PlayStation, WiiU, . . . 4 / 13
  14. 14. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms Linux, macOS, Windows, *BSD, AIX, IBM i, . . . iOS, tvOS, watchOS & Android XBox, PlayStation, WiiU, . . . amd64, x86, armv7, armv8, powerpc, s390x 4 / 13
  15. 15. The Mono Runtime — Overview Execution modes Just-In-Time compiler Ahead-Of-Time compiler normal AOT FullAOT Interpreter Supported platforms Linux, macOS, Windows, *BSD, AIX, IBM i, . . . iOS, tvOS, watchOS & Android XBox, PlayStation, WiiU, . . . amd64, x86, armv7, armv8, powerpc, s390x WebAssembly 4 / 13
  16. 16. Embedding the Mono Runtime Embedding Mono link Mono into your application 5 / 13
  17. 17. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting 5 / 13
  18. 18. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting Users 5 / 13
  19. 19. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting Users Game Studios 5 / 13
  20. 20. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting Users Game Studios Unity 5 / 13
  21. 21. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting Users Game Studios Unity Blazor: check out https://learn-blazor.com/ 5 / 13
  22. 22. Embedding the Mono Runtime Embedding Mono link Mono into your application allows execution of .NET, e.g. useful for scripting Users Game Studios Unity Blazor: check out https://learn-blazor.com/ Xamarin.Android & Xamarin.iOS 5 / 13
  23. 23. Platform & Device landscape iOS on iPhone/iPad. 6 / 13
  24. 24. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. 6 / 13
  25. 25. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. 6 / 13
  26. 26. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. 6 / 13
  27. 27. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. 6 / 13
  28. 28. FullAOT 7 / 13
  29. 29. FullAOT iOS does not allow JIT compilation 7 / 13
  30. 30. FullAOT iOS does not allow JIT compilation Normal AOT uses JIT occasionally at runtime 7 / 13
  31. 31. FullAOT iOS does not allow JIT compilation Normal AOT uses JIT occasionally at runtime All trampolines and wrappers must be included in the AOT image 7 / 13
  32. 32. FullAOT iOS does not allow JIT compilation Normal AOT uses JIT occasionally at runtime All trampolines and wrappers must be included in the AOT image Side-effect: System.Reflection.Emit does not work 7 / 13
  33. 33. What about generics? 8 / 13
  34. 34. What about generics? public T return_t<T> (T arg) { return arg; } 8 / 13
  35. 35. What about generics? public T return_t<T> (T arg) { return arg; } // "Generic sharing for value types" public void return_t (T& ret, T& arg, ptr hidden_arg) { int size = rgctx_fetch (hidden_arg); memcpy (ret, arg, size); } 8 / 13
  36. 36. What about generics? public T return_t<T> (T arg) { return arg; } // "Generic sharing for value types" public void return_t (T& ret, T& arg, ptr hidden_arg) { int size = rgctx_fetch (hidden_arg); memcpy (ret, arg, size); } int i = return_t<int> (5); 8 / 13
  37. 37. What about generics? public T return_t<T> (T arg) { return arg; } // "Generic sharing for value types" public void return_t (T& ret, T& arg, ptr hidden_arg) { int size = rgctx_fetch (hidden_arg); memcpy (ret, arg, size); } int i = return_t<int> (5); // calling chain caller ⇒ callee 8 / 13
  38. 38. What about generics? public T return_t<T> (T arg) { return arg; } // "Generic sharing for value types" public void return_t (T& ret, T& arg, ptr hidden_arg) { int size = rgctx_fetch (hidden_arg); memcpy (ret, arg, size); } int i = return_t<int> (5); // calling chain caller ⇒ gsharedvt_arg_trampoline ⇒ callee 8 / 13
  39. 39. What about generics? public T return_t<T> (T arg) { return arg; } // "Generic sharing for value types" public void return_t (T& ret, T& arg, ptr hidden_arg) { int size = rgctx_fetch (hidden_arg); memcpy (ret, arg, size); } int i = return_t<int> (5); // calling chain caller ⇒ gsharedvt_arg_trampoline ⇒ gsharedvt_in_trampoline ⇒ callee 8 / 13
  40. 40. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () 9 / 13
  41. 41. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () 9 / 13
  42. 42. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () Runtime interpreter enables System.Reflection.Emit 9 / 13
  43. 43. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () Runtime interpreter enables System.Reflection.Emit Faster “inner dev loop” No need to run the AOT compiler Smaller app bundle size ⇒ faster deploy 9 / 13
  44. 44. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () Runtime interpreter enables System.Reflection.Emit Faster “inner dev loop” No need to run the AOT compiler Smaller app bundle size ⇒ faster deploy Best of both worlds: “Mixed Mode” with FullAOT 9 / 13
  45. 45. System.Reflection.Emit? System.ExecutionEngineException: Attempting to JIT compile method MyClass:DynamicallyGeneratedMethod () Runtime interpreter enables System.Reflection.Emit Faster “inner dev loop” No need to run the AOT compiler Smaller app bundle size ⇒ faster deploy Best of both worlds: “Mixed Mode” with FullAOT Ships with upcoming release of Xamarin.iOS (Preview available) 9 / 13
  46. 46. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. 10 / 13
  47. 47. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. 10 / 13
  48. 48. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. x86 64: JIT. 10 / 13
  49. 49. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. x86 64: JIT. watchOS on Apple Watch. 10 / 13
  50. 50. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. x86 64: JIT. watchOS on Apple Watch. armv7k: FullAOT and bitcode. 10 / 13
  51. 51. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. x86 64: JIT. watchOS on Apple Watch. armv7k: FullAOT and bitcode. arm64 32: interpreter (WIP) and bitcode. 10 / 13
  52. 52. Platform & Device landscape iOS on iPhone/iPad. armv7: FullAOT. arm64: FullAOT and interpreter. x86: JIT. x86 64: JIT. tvOS on Apple TV. arm64: FullAOT and interpreter. x86 64: JIT. watchOS on Apple Watch. armv7k: FullAOT and bitcode. arm64 32: interpreter (WIP) and bitcode. x86: JIT. 10 / 13
  53. 53. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together 11 / 13
  54. 54. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 11 / 13
  55. 55. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. 11 / 13
  56. 56. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. Co-worker in the US got the device. 11 / 13
  57. 57. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. Co-worker in the US got the device. He could not reproduce it. 11 / 13
  58. 58. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. Co-worker in the US got the device. He could not reproduce it. US edition: Ships with Snapdragon 820. 11 / 13
  59. 59. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. Co-worker in the US got the device. He could not reproduce it. US edition: Ships with Snapdragon 820. World edition: Ships with Exynos 8890. 11 / 13
  60. 60. Xamarin.Android Simliar to Linux, except for interop between C# and Java Two Garbage collectors have to work together War story: Samsung Galaxy S7 First bug report: “Xamarin.Android apps on the Samsung Galaxy S7 fails to start with the error System.ExecutionEngineException SIGILL“. Co-worker in the US got the device. He could not reproduce it. US edition: Ships with Snapdragon 820. World edition: Ships with Exynos 8890. Could reproduce it with Xamarin Test Cloud. 11 / 13
  61. 61. War story: Samsung Galaxy S7 $ grep SIGILL *.log custom_01.log:E/mono (13964): SIGILL at ip=0x0000007f4f15e8d0 custom_02.log:E/mono (13088): SIGILL at ip=0x0000007f8ff76cc0 custom_03.log:E/mono (12824): SIGILL at ip=0x0000007f68e93c70 custom_04.log:E/mono (12876): SIGILL at ip=0x0000007f4b3d55f0 custom_05.log:E/mono (13008): SIGILL at ip=0x0000007f8df1e8d0 custom_06.log:E/mono (14093): SIGILL at ip=0x0000007f6c21edf0 12 / 13
  62. 62. War story: Samsung Galaxy S7 $ grep SIGILL *.log custom_01.log:E/mono (13964): SIGILL at ip=0x0000007f4f15e8d0 custom_02.log:E/mono (13088): SIGILL at ip=0x0000007f8ff76cc0 custom_03.log:E/mono (12824): SIGILL at ip=0x0000007f68e93c70 custom_04.log:E/mono (12876): SIGILL at ip=0x0000007f4b3d55f0 custom_05.log:E/mono (13008): SIGILL at ip=0x0000007f8df1e8d0 custom_06.log:E/mono (14093): SIGILL at ip=0x0000007f6c21edf0 void __clear_cache (char *address, size_t size) { static int cache_line_size = 0; if (!cache_line_size) cache_line_size = get_current_cpu_cache_line_size (); for (int i = 0; i < size; i += cache_line_size) flush_cache_line (address + i); }
  63. 63. War story: Samsung Galaxy S7 $ grep SIGILL *.log custom_01.log:E/mono (13964): SIGILL at ip=0x0000007f4f15e8d0 custom_02.log:E/mono (13088): SIGILL at ip=0x0000007f8ff76cc0 custom_03.log:E/mono (12824): SIGILL at ip=0x0000007f68e93c70 custom_04.log:E/mono (12876): SIGILL at ip=0x0000007f4b3d55f0 custom_05.log:E/mono (13008): SIGILL at ip=0x0000007f8df1e8d0 custom_06.log:E/mono (14093): SIGILL at ip=0x0000007f6c21edf0 void __clear_cache (char *address, size_t size) { static int cache_line_size = 0; if (!cache_line_size) cache_line_size = get_current_cpu_cache_line_size (); for (int i = 0; i < size; i += cache_line_size) flush_cache_line (address + i); }
  64. 64. War story: Samsung Galaxy S7 $ grep SIGILL *.log custom_01.log:E/mono (13964): SIGILL at ip=0x0000007f4f15e8d0 custom_02.log:E/mono (13088): SIGILL at ip=0x0000007f8ff76cc0 custom_03.log:E/mono (12824): SIGILL at ip=0x0000007f68e93c70 custom_04.log:E/mono (12876): SIGILL at ip=0x0000007f4b3d55f0 custom_05.log:E/mono (13008): SIGILL at ip=0x0000007f8df1e8d0 custom_06.log:E/mono (14093): SIGILL at ip=0x0000007f6c21edf0 void __clear_cache (char *address, size_t size) { static int cache_line_size = 0; if (!cache_line_size) cache_line_size = get_current_cpu_cache_line_size (); for (int i = 0; i < size; i += cache_line_size) flush_cache_line (address + i); } 12 / 13
  65. 65. War story: Samsung Galaxy S7 $ grep SIGILL *.log custom_01.log:E/mono (13964): SIGILL at ip=0x0000007f4f15e8d0 custom_02.log:E/mono (13088): SIGILL at ip=0x0000007f8ff76cc0 custom_03.log:E/mono (12824): SIGILL at ip=0x0000007f68e93c70 custom_04.log:E/mono (12876): SIGILL at ip=0x0000007f4b3d55f0 custom_05.log:E/mono (13008): SIGILL at ip=0x0000007f8df1e8d0 custom_06.log:E/mono (14093): SIGILL at ip=0x0000007f6c21edf0 void __clear_cache (char *address, size_t size) { static int cache_line_size = 0; if (!cache_line_size) cache_line_size = get_current_cpu_cache_line_size (); for (int i = 0; i < size; i += cache_line_size) flush_cache_line (address + i); } 64byte buckets: 0x00-0x3f: always flushed 0x40-0x7f: only flushed when cacheline size is 64 byte. 0x80-0xbf: always flushed 0xc0-0xff: only flushed when cacheline size is 64 byte. 12 / 13
  66. 66. Thanks Visit us https://www.mono-project.com Chat with us https://gitter.im/mono/mono Mail me beurba@microsoft.com foundation 13 / 13

×