Skip to content

Commit 15ebf49

Browse files
authored
[Mono.Android] Remove Mono_UnhandledException lookup (#8618)
We can simplify `JNIEnv.PropagateUncaughtException` by removing the fallback case that would attempt to look for `System.Diagnostics.Debugger.Mono_UnhandledException`. In .NET the `MonodroidRuntime::monodroid_debugger_unhandled_exception` function will always be defined, and `Mono_UnhandledException` appears to no longer exist in .NET. This simplification should also appease our latest set of API scan results that were complaining about missing documentation for `Mono_UnhandledException`.
1 parent e7d97ee commit 15ebf49

File tree

5 files changed

+65
-90
lines changed

5 files changed

+65
-90
lines changed

src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,12 @@ namespace Android.Runtime
66
{
77
public static class AndroidRuntimeInternal
88
{
9-
internal static MethodInfo? mono_unhandled_exception_method = null;
10-
internal static Action<Exception> mono_unhandled_exception = RuntimeNativeMethods.monodroid_debugger_unhandled_exception;
9+
internal static readonly Action<Exception> mono_unhandled_exception = RuntimeNativeMethods.monodroid_debugger_unhandled_exception;
1110

1211
#pragma warning disable CS0649 // Field is never assigned to. This field is assigned from monodroid-glue.cc.
1312
internal static volatile bool BridgeProcessing; // = false
1413
#pragma warning restore CS0649 // Field is never assigned to.
1514

16-
internal static void InitializeUnhandledExceptionMethod ()
17-
{
18-
if (mono_unhandled_exception == null) {
19-
mono_unhandled_exception_method = typeof (System.Diagnostics.Debugger)
20-
.GetMethod ("Mono_UnhandledException", BindingFlags.NonPublic | BindingFlags.Static);
21-
if (mono_unhandled_exception_method != null)
22-
mono_unhandled_exception = (Action<Exception>) Delegate.CreateDelegate (typeof(Action<Exception>), mono_unhandled_exception_method);
23-
}
24-
if (mono_unhandled_exception_method == null && mono_unhandled_exception != null) {
25-
mono_unhandled_exception_method = mono_unhandled_exception.Method;
26-
}
27-
}
28-
2915
public static void WaitForBridgeProcessing ()
3016
{
3117
if (!BridgeProcessing)

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,11 @@ static void ManualJavaObjectDispose (Java.Lang.Object obj)
103103
GC.SuppressFinalize (obj);
104104
}
105105

106-
static void Initialize ()
107-
{
108-
AndroidRuntimeInternal.InitializeUnhandledExceptionMethod ();
109-
}
110-
111106
internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPtr, IntPtr javaExceptionPtr)
112107
{
113108
if (!JNIEnvInit.PropagateExceptions)
114109
return;
115110

116-
try {
117-
Initialize ();
118-
} catch (Exception e) {
119-
Android.Runtime.AndroidEnvironment.FailFast ($"Unable to initialize UncaughtExceptionHandler. Nested exception caught: {e}");
120-
}
121-
122111
var javaException = JavaObject.GetObject<Java.Lang.Throwable> (env, javaExceptionPtr, JniHandleOwnership.DoNotTransfer)!;
123112

124113
if (Debugger.IsAttached) {

src/Mono.Android/Android.Runtime/JNINativeWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public static Delegate CreateDelegate (Delegate dlg)
7373
ig.Emit (OpCodes.Leave, label);
7474

7575
bool filter = Debugger.IsAttached || !JNIEnvInit.PropagateExceptions;
76-
if (filter && AndroidRuntimeInternal.mono_unhandled_exception_method != null) {
76+
if (filter) {
7777
ig.BeginExceptFilterBlock ();
7878

79-
ig.Emit (OpCodes.Call, AndroidRuntimeInternal.mono_unhandled_exception_method);
79+
ig.Emit (OpCodes.Call, AndroidRuntimeInternal.mono_unhandled_exception.Method);
8080
ig.Emit (OpCodes.Ldc_I4_1);
8181
ig.BeginCatchBlock (null!);
8282
} else {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,61 @@
88
"Size": 1028
99
},
1010
"assemblies/Java.Interop.dll": {
11-
"Size": 61348
11+
"Size": 61588
1212
},
1313
"assemblies/Mono.Android.dll": {
14-
"Size": 90896
14+
"Size": 90724
1515
},
1616
"assemblies/Mono.Android.Runtime.dll": {
17-
"Size": 5577
17+
"Size": 5147
1818
},
1919
"assemblies/rc.bin": {
2020
"Size": 1512
2121
},
2222
"assemblies/System.Console.dll": {
23-
"Size": 6548
23+
"Size": 6547
2424
},
2525
"assemblies/System.Linq.dll": {
26-
"Size": 7171
26+
"Size": 7163
2727
},
2828
"assemblies/System.Private.CoreLib.dll": {
29-
"Size": 553674
29+
"Size": 554659
3030
},
3131
"assemblies/System.Runtime.dll": {
32-
"Size": 2630
32+
"Size": 2551
3333
},
3434
"assemblies/System.Runtime.InteropServices.dll": {
35-
"Size": 4033
35+
"Size": 4028
3636
},
3737
"assemblies/UnnamedProject.dll": {
38-
"Size": 2935
38+
"Size": 2937
3939
},
4040
"classes.dex": {
41-
"Size": 377956
41+
"Size": 377856
4242
},
4343
"lib/arm64-v8a/libmono-component-marshal-ilgen.so": {
44-
"Size": 86944
44+
"Size": 87080
4545
},
4646
"lib/arm64-v8a/libmonodroid.so": {
47-
"Size": 334496
47+
"Size": 339864
4848
},
4949
"lib/arm64-v8a/libmonosgen-2.0.so": {
50-
"Size": 3182072
50+
"Size": 3184512
5151
},
5252
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
5353
"Size": 723560
5454
},
5555
"lib/arm64-v8a/libSystem.Native.so": {
56-
"Size": 94208
56+
"Size": 94504
5757
},
5858
"lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": {
5959
"Size": 155568
6060
},
6161
"lib/arm64-v8a/libxamarin-app.so": {
62-
"Size": 11680
62+
"Size": 11648
6363
},
6464
"META-INF/BNDLTOOL.RSA": {
65-
"Size": 1213
65+
"Size": 1223
6666
},
6767
"META-INF/BNDLTOOL.SF": {
6868
"Size": 3037

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64XFormsDotNet.apkdesc

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,136 +5,136 @@
55
"Size": 3572
66
},
77
"assemblies/_Microsoft.Android.Resource.Designer.dll": {
8-
"Size": 2105
8+
"Size": 2104
99
},
1010
"assemblies/FormsViewGroup.dll": {
1111
"Size": 7113
1212
},
1313
"assemblies/Java.Interop.dll": {
14-
"Size": 69478
14+
"Size": 69705
1515
},
1616
"assemblies/Mono.Android.dll": {
17-
"Size": 447443
17+
"Size": 447230
1818
},
1919
"assemblies/Mono.Android.Runtime.dll": {
20-
"Size": 5577
20+
"Size": 5147
2121
},
2222
"assemblies/mscorlib.dll": {
23-
"Size": 3863
23+
"Size": 3862
2424
},
2525
"assemblies/netstandard.dll": {
26-
"Size": 5581
26+
"Size": 5578
2727
},
2828
"assemblies/rc.bin": {
2929
"Size": 1512
3030
},
3131
"assemblies/System.Collections.Concurrent.dll": {
32-
"Size": 11516
32+
"Size": 11514
3333
},
3434
"assemblies/System.Collections.dll": {
35-
"Size": 15409
35+
"Size": 15408
3636
},
3737
"assemblies/System.Collections.NonGeneric.dll": {
38-
"Size": 7454
38+
"Size": 7452
3939
},
4040
"assemblies/System.ComponentModel.dll": {
4141
"Size": 1939
4242
},
4343
"assemblies/System.ComponentModel.Primitives.dll": {
44-
"Size": 2553
44+
"Size": 2549
4545
},
4646
"assemblies/System.ComponentModel.TypeConverter.dll": {
47-
"Size": 6037
47+
"Size": 6033
4848
},
4949
"assemblies/System.Console.dll": {
50-
"Size": 6579
50+
"Size": 6578
5151
},
5252
"assemblies/System.Core.dll": {
53-
"Size": 1993
53+
"Size": 1991
5454
},
5555
"assemblies/System.Diagnostics.DiagnosticSource.dll": {
56-
"Size": 9071
56+
"Size": 9068
5757
},
5858
"assemblies/System.Diagnostics.TraceSource.dll": {
59-
"Size": 6555
59+
"Size": 6552
6060
},
6161
"assemblies/System.dll": {
6262
"Size": 2345
6363
},
6464
"assemblies/System.Drawing.dll": {
65-
"Size": 1940
65+
"Size": 1939
6666
},
6767
"assemblies/System.Drawing.Primitives.dll": {
6868
"Size": 11975
6969
},
7070
"assemblies/System.IO.Compression.Brotli.dll": {
71-
"Size": 11194
71+
"Size": 11196
7272
},
7373
"assemblies/System.IO.Compression.dll": {
74-
"Size": 15863
74+
"Size": 15880
7575
},
7676
"assemblies/System.IO.IsolatedStorage.dll": {
7777
"Size": 9875
7878
},
7979
"assemblies/System.Linq.dll": {
80-
"Size": 19604
80+
"Size": 19599
8181
},
8282
"assemblies/System.Linq.Expressions.dll": {
83-
"Size": 165118
83+
"Size": 165117
8484
},
8585
"assemblies/System.Net.Http.dll": {
86-
"Size": 67636
86+
"Size": 67631
8787
},
8888
"assemblies/System.Net.Primitives.dll": {
89-
"Size": 22437
89+
"Size": 22432
9090
},
9191
"assemblies/System.Net.Requests.dll": {
92-
"Size": 3604
92+
"Size": 3602
9393
},
9494
"assemblies/System.ObjectModel.dll": {
95-
"Size": 8119
95+
"Size": 8116
9696
},
9797
"assemblies/System.Private.CoreLib.dll": {
98-
"Size": 848850
98+
"Size": 849646
9999
},
100100
"assemblies/System.Private.DataContractSerialization.dll": {
101-
"Size": 193994
101+
"Size": 193991
102102
},
103103
"assemblies/System.Private.Uri.dll": {
104-
"Size": 42863
104+
"Size": 42860
105105
},
106106
"assemblies/System.Private.Xml.dll": {
107-
"Size": 216250
107+
"Size": 216226
108108
},
109109
"assemblies/System.Private.Xml.Linq.dll": {
110-
"Size": 16646
110+
"Size": 16639
111111
},
112112
"assemblies/System.Runtime.dll": {
113-
"Size": 2755
113+
"Size": 2708
114114
},
115115
"assemblies/System.Runtime.InteropServices.dll": {
116-
"Size": 4033
116+
"Size": 4028
117117
},
118118
"assemblies/System.Runtime.Serialization.dll": {
119-
"Size": 1866
119+
"Size": 1865
120120
},
121121
"assemblies/System.Runtime.Serialization.Formatters.dll": {
122-
"Size": 2485
122+
"Size": 2484
123123
},
124124
"assemblies/System.Runtime.Serialization.Primitives.dll": {
125-
"Size": 3760
125+
"Size": 3758
126126
},
127127
"assemblies/System.Security.Cryptography.dll": {
128-
"Size": 8109
128+
"Size": 8111
129129
},
130130
"assemblies/System.Text.RegularExpressions.dll": {
131-
"Size": 159114
131+
"Size": 159112
132132
},
133133
"assemblies/System.Xml.dll": {
134-
"Size": 1757
134+
"Size": 1758
135135
},
136136
"assemblies/System.Xml.Linq.dll": {
137-
"Size": 1777
137+
"Size": 1774
138138
},
139139
"assemblies/UnnamedProject.dll": {
140140
"Size": 4990
@@ -206,28 +206,28 @@
206206
"Size": 42285
207207
},
208208
"classes.dex": {
209-
"Size": 3514468
209+
"Size": 3502580
210210
},
211211
"lib/arm64-v8a/libmono-component-marshal-ilgen.so": {
212-
"Size": 86944
212+
"Size": 87080
213213
},
214214
"lib/arm64-v8a/libmonodroid.so": {
215-
"Size": 334496
215+
"Size": 339864
216216
},
217217
"lib/arm64-v8a/libmonosgen-2.0.so": {
218-
"Size": 3182072
218+
"Size": 3184512
219219
},
220220
"lib/arm64-v8a/libSystem.IO.Compression.Native.so": {
221221
"Size": 723560
222222
},
223223
"lib/arm64-v8a/libSystem.Native.so": {
224-
"Size": 94208
224+
"Size": 94504
225225
},
226226
"lib/arm64-v8a/libSystem.Security.Cryptography.Native.Android.so": {
227227
"Size": 155568
228228
},
229229
"lib/arm64-v8a/libxamarin-app.so": {
230-
"Size": 102920
230+
"Size": 102888
231231
},
232232
"META-INF/android.support.design_material.version": {
233233
"Size": 12
@@ -338,7 +338,7 @@
338338
"Size": 6
339339
},
340340
"META-INF/BNDLTOOL.RSA": {
341-
"Size": 1213
341+
"Size": 1221
342342
},
343343
"META-INF/BNDLTOOL.SF": {
344344
"Size": 77024
@@ -1916,5 +1916,5 @@
19161916
"Size": 325240
19171917
}
19181918
},
1919-
"PackageSize": 7949326
1919+
"PackageSize": 7941134
19201920
}

0 commit comments

Comments
 (0)