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

Blazor hang with marshal methods #7927

Closed
wants to merge 108 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
31fa878
Some debug messages
grendello Mar 28, 2023
40646c5
Merge branch 'main' into blazor-hang
grendello Mar 28, 2023
a89f45b
Marshal methods tracing
grendello Mar 28, 2023
fd06651
Native backtrace implementation
grendello Mar 29, 2023
2193db1
Merge branch 'main' into blazor-hang
grendello Mar 30, 2023
0564634
[WIP] Stack unwinding (doesn't build yet)
grendello Mar 30, 2023
3732378
Build and use our own libunwind
grendello Mar 31, 2023
8b05e39
Merge branch 'main' into blazor-hang
grendello Apr 3, 2023
97c5127
Make lld really ignore missing symbols + other stuff
grendello Apr 3, 2023
d37a22a
Eliminate the need to use NDK when enabling marshal methods tracing
grendello Apr 4, 2023
1ca486a
Merge branch 'main' into blazor-hang
grendello Apr 5, 2023
fb7f7e6
Java stack trace implemented
grendello Apr 5, 2023
2f58b13
Merge branch 'main' into blazor-hang
grendello Apr 6, 2023
e3d2649
Add signal handlers to the report
grendello Apr 6, 2023
581194e
Merge branch 'main' into blazor-hang
grendello Apr 7, 2023
0ba212e
Day spent debugging
grendello Apr 7, 2023
a512324
Merge branch 'main' into blazor-hang
grendello Apr 11, 2023
8c1b27f
Merge branch 'main' into blazor-hang
grendello Apr 11, 2023
b8cb13d
Tracing code is going to live in a separate DSO
grendello Apr 11, 2023
0cf46bd
Merge branch 'main' into blazor-hang
grendello Apr 12, 2023
61f2114
Merge branch 'main' into blazor-hang
grendello Apr 12, 2023
d0ef3e7
Put tracing code in a separate library
grendello Apr 12, 2023
469e752
Merge branch 'main' into blazor-hang
grendello Apr 12, 2023
1076ed5
Don't package the tracing DSO unless told so
grendello Apr 13, 2023
d9d869c
Merge branch 'main' into blazor-hang
grendello Apr 14, 2023
c291dc4
Spent the day tracking registered and executed methods
grendello Apr 17, 2023
35be489
A small TODO
grendello Apr 17, 2023
4b595a8
Merge branch 'main' into blazor-hang
grendello Apr 24, 2023
4288baf
Make sure invariant culture is used
grendello Apr 24, 2023
b68b512
Merge branch 'main' into blazor-hang
grendello Apr 25, 2023
7eb75e3
Merge branch 'main' into blazor-hang
grendello Apr 27, 2023
caae9e9
Add some Java tracing + Java.Interop tracing
grendello Apr 27, 2023
6a48e52
Merge branch 'main' into blazor-hang
grendello Apr 28, 2023
72abfa3
More tracing, perhaps getting closer
grendello Apr 28, 2023
4b45d5f
Merge branch 'main' into blazor-hang
grendello May 4, 2023
48f4b6a
Base code for parameter and return value logging
grendello May 4, 2023
212f6ef
Different approach to printing params
grendello May 5, 2023
bc5b0f8
Progress towards supporting variadic functions
grendello May 8, 2023
7600af1
Well, it generates correct code now
grendello May 8, 2023
788bd63
Merge branch 'main' into blazor-hang
grendello May 9, 2023
19e79a2
Generated code not complete, won't compile
grendello May 9, 2023
cae9bb0
Merge branch 'main' into blazor-hang
grendello May 10, 2023
cae0bd8
Way too much time spent on this...
grendello May 10, 2023
9fd0b07
Merge branch 'main' into blazor-hang
grendello May 11, 2023
fd3eefd
Found and fixed an issue with marshal methods
grendello May 11, 2023
fde3078
asprintf call & co is complete
grendello May 12, 2023
46fe18b
Merge branch 'main' into blazor-hang
grendello May 15, 2023
79cf274
Merge branch 'main' into blazor-hang
grendello May 16, 2023
d942663
Function parameter and return value tracing works
grendello May 16, 2023
37c401a
Merge branch 'main' into blazor-hang
grendello May 17, 2023
a74882f
Preparations for better argument logging
grendello May 17, 2023
3673a3a
Merge branch 'main' into blazor-hang
grendello May 18, 2023
37b16d3
Third iteration... done for today
grendello May 18, 2023
9af8f8e
Merge branch 'main' into blazor-hang
grendello May 19, 2023
8f86bc7
Cul-de-sac, dead end, wrong way, doh
grendello May 19, 2023
f6df472
Merge branch 'main' into blazor-hang
grendello May 22, 2023
135744c
New approach to LLVM IR generation
grendello May 22, 2023
58965d1
Merge branch 'main' into blazor-hang
grendello May 23, 2023
ef27fe5
More steps towards new LLVM IR generator
grendello May 23, 2023
c9cb983
Merge branch 'main' into blazor-hang
grendello May 24, 2023
12b8a61
Moving forward with the new LLVM IR generator
grendello May 24, 2023
49b7d63
Rearchitecting things for simpler use
grendello May 25, 2023
c67fbb9
Merge branch 'main' into blazor-hang
grendello May 26, 2023
3d5e073
New generator is alive
grendello May 26, 2023
603afbb
Merge branch 'main' into blazor-hang
grendello May 29, 2023
ec099cf
Data generation progressing nicely.
grendello May 29, 2023
db5be23
Structures written fine, onto structure arrays tomorrow
grendello May 30, 2023
42437cd
Structure arrays done
grendello May 31, 2023
0f39485
Phew, array and structure handling simplified and unified
grendello Jun 1, 2023
c937202
Merge branch 'main' into blazor-hang
grendello Jun 2, 2023
f81fa85
ApplicationConfigNativeAssemblyGenerator switched to the new LLVM IR …
grendello Jun 2, 2023
0da112c
Merge branch 'main' into blazor-hang
grendello Jun 5, 2023
09fbf9c
Moving on with new LLVM IR generator
grendello Jun 5, 2023
fd93c1f
Merge branch 'main' into blazor-hang
grendello Jun 6, 2023
c32dc33
Release TypeMap composer converted to the new generator
grendello Jun 6, 2023
55aec7d
Merge branch 'main' into blazor-hang
grendello Jun 7, 2023
f35855b
Debug typemap generator converted
grendello Jun 7, 2023
2990041
Compressed assemblies composer converted
grendello Jun 7, 2023
cd4584b
Merge branch 'main' into blazor-hang
grendello Jun 12, 2023
d126d26
JNI remapping composer converted
grendello Jun 12, 2023
0de8a6f
Merge branch 'main' into blazor-hang
grendello Jun 13, 2023
7a23158
Data portion of the marshal methods generator done
grendello Jun 13, 2023
0fea526
Merge branch 'main' into blazor-hang
grendello Jun 14, 2023
3d27e22
Beginnings of code generation
grendello Jun 14, 2023
fb63716
Merge branch 'main' into blazor-hang
grendello Jun 15, 2023
5e98bc3
Code generation works
grendello Jun 15, 2023
11bf0a7
Merge branch 'main' into blazor-hang
grendello Jun 16, 2023
1ddf89f
Halfway through code generation
grendello Jun 16, 2023
80c510a
Merge branch 'main' into blazor-hang
grendello Jun 19, 2023
5c17d76
`call` sorted out, tomorrow onto `phi`
grendello Jun 19, 2023
76e4d0c
Merge branch 'main' into blazor-hang
grendello Jun 20, 2023
33c9ac3
Conversion to the new LLVM IR complete for everything except tracing
grendello Jun 20, 2023
69bd75e
Merge branch 'main' into blazor-hang
grendello Jun 21, 2023
4d8d4dc
Cleanup
grendello Jun 21, 2023
6799989
A bit more cleanup
grendello Jun 21, 2023
60b0a13
Merge branch 'main' into blazor-hang
grendello Jun 22, 2023
580aae9
Update libunwind to 1.7.0
grendello Jun 22, 2023
944b73b
Tracing progress
grendello Jun 22, 2023
2c74196
Merge branch 'main' into blazor-hang
grendello Jun 23, 2023
95d423d
asprintf progress, new style
grendello Jun 23, 2023
1ef3255
Add some more tracing capabilities
grendello Jun 26, 2023
e148e1b
Merge branch 'main' into blazor-hang
grendello Jun 27, 2023
5316425
More tracing improvements
grendello Jun 27, 2023
c11f03b
Merge branch 'main' into blazor-hang
grendello Jun 28, 2023
b864253
asprintf simpler, general `call` improvements, assorted fixes
grendello Jun 28, 2023
c1cad61
Merge branch 'main' into blazor-hang
grendello Jun 28, 2023
b5fc35f
Merge branch 'main' into blazor-hang
grendello Mar 8, 2024
76cd39a
Fixups after merge
grendello Mar 8, 2024
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
path = external/xamarin-android-tools
url = https://github.com/xamarin/xamarin-android-tools
branch = main
[submodule "external/libunwind"]
path = external/libunwind
url = https://github.com/libunwind/libunwind.git
branch = v1.7-stable
4 changes: 4 additions & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<IgnoreMaxMonoVersion Condition=" '$(IgnoreMaxMonoVersion)' == '' ">True</IgnoreMaxMonoVersion>
<OpenTKSourceDirectory>$(MSBuildThisFileDirectory)external\opentk</OpenTKSourceDirectory>
<SqliteSourceDirectory Condition=" '$(SqliteSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\sqlite</SqliteSourceDirectory>
<LibUnwindSourceDirectory Condition=" '$(LibUnwindSourceDirectory)' == '' ">$(MSBuildThisFileDirectory)external\libunwind</LibUnwindSourceDirectory>
<LibUnwindGeneratedHeadersDirectory Condition=" '$(LibUnwindGeneratedHeadersDirectory)' == '' ">$(BootstrapOutputDirectory)\libunwind</LibUnwindGeneratedHeadersDirectory>
<XamarinAndroidSourcePath>$(MSBuildThisFileDirectory)</XamarinAndroidSourcePath>
<ThirdPartySourcePath>$(MSBuildThisFileDirectory)src-ThirdParty\</ThirdPartySourcePath>
<AllSupported32BitTargetAndroidAbis>armeabi-v7a;x86</AllSupported32BitTargetAndroidAbis>
Expand Down Expand Up @@ -144,6 +146,8 @@
<JavaInteropFullPath>$([System.IO.Path]::GetFullPath ('$(JavaInteropSourceDirectory)'))</JavaInteropFullPath>
<MonoSourceFullPath>$([System.IO.Path]::GetFullPath ('$(MonoSourceDirectory)'))</MonoSourceFullPath>
<SqliteSourceFullPath>$([System.IO.Path]::GetFullPath ('$(SqliteSourceDirectory)'))</SqliteSourceFullPath>
<LibUnwindSourceFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindSourceDirectory)'))</LibUnwindSourceFullPath>
<LibUnwindGeneratedHeadersFullPath>$([System.IO.Path]::GetFullPath ('$(LibUnwindGeneratedHeadersDirectory)'))</LibUnwindGeneratedHeadersFullPath>
<OpenTKSourceFullPath>$([System.IO.Path]::GetFullPath ('$(OpenTKSourceDirectory)'))</OpenTKSourceFullPath>
<JavaInteropTargetFrameworkVersion>net8.0</JavaInteropTargetFrameworkVersion>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions TheoriesToTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* See if it's a threading issue - add full locking to `get_function_pointer` instead of atomics that we use now
* See if it's an ALC issue - call `get_function_pointer` every time and check the returned pointer value
* Implement Jon's idea to always have the "old" dynamic registration stuff in JCW and only use it when some flag
is set and marshal methods are active.
2 changes: 2 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Diagnost
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Cecil", "external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj", "{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libunwind", "src\libunwind-xamarin\libunwind-xamarin.csproj", "{F8E4961B-C427-47F9-92D6-0BEB5B76B3D7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "monodroid", "src\monodroid\monodroid.csproj", "{53EE4C57-1C03-405A-8243-8DA539546C88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}"
Expand Down
3 changes: 2 additions & 1 deletion build-tools/cmake/xa_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ function(xa_common_prepare)
-fstack-protector-strong
-fstrict-return
-fno-strict-aliasing
-ffunction-sections
-fno-function-sections
-fno-data-sections
-funswitch-loops
-finline-limit=300
-Wa,-noexecstack
Expand Down
2 changes: 2 additions & 0 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ projects that use the Microsoft.Android framework in .NET 6+.
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.debug.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.release.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-debug-app-helper.so" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmarshal-methods-tracing.a" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libxamarin-native-tracing.so" />
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssemblies->'%(Filename)%(Extension)')" Profile="Android" />
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssets->'%(Filename)%(Extension)')" Profile="Android" />
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,20 @@
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)ManifestOverlays\Timing.xml" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm64\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-arm\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x64\liblog.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libc.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libm.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\libdl.so" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)libstubs\android-x86\liblog.so" />
</ItemGroup>
<ItemGroup>
<_MSBuildTargetsSrcFiles Include="$(MSBuildTargetsSrcDir)\Xamarin.Android.AvailableItems.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static class KnownProperties
public const string JavaInteropFullPath = "JavaInteropFullPath";
public const string JavaSdkDirectory = "JavaSdkDirectory";
public const string JdkIncludePath = "JdkIncludePath";
public const string LibUnwindGeneratedHeadersFullPath = nameof (LibUnwindGeneratedHeadersFullPath);
public const string LibUnwindSourceFullPath = nameof (LibUnwindSourceFullPath);
public const string LibZipSourceFullPath = "LibZipSourceFullPath";
public const string ManagedRuntime = "ManagedRuntime";
public const string MicrosoftAndroidSdkOutDir = "MicrosoftAndroidSdkOutDir";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.JavaInteropFullPath, StripQuotes (@"@JavaInteropFullPath@"));
properties.Add (KnownProperties.JavaSdkDirectory, StripQuotes (@"@JavaSdkDirectory@"));
properties.Add (KnownProperties.JdkIncludePath, StripQuotes (@"@JdkIncludePath@"));
properties.Add (KnownProperties.LibUnwindGeneratedHeadersFullPath, StripQuotes (@"@LibUnwindGeneratedHeadersFullPath@"));
properties.Add (KnownProperties.LibUnwindSourceFullPath, StripQuotes (@"@LibUnwindSourceFullPath"));
properties.Add (KnownProperties.LibZipSourceFullPath, StripQuotes (@"@LibZipSourceFullPath@"));
properties.Add (KnownProperties.ManagedRuntime, StripQuotes (@"@ManagedRuntime@"));
properties.Add (KnownProperties.MicrosoftAndroidSdkOutDir, StripQuotes (@"@MicrosoftAndroidSdkOutDir@"));
Expand Down
1 change: 1 addition & 0 deletions build-tools/xaprepare/xaprepare/xaprepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Replacement Include="@JavaInteropFullPath@=$(JavaInteropFullPath)" />
<Replacement Include="@JavaSdkDirectory@=$(JavaSdkDirectory)" />
<Replacement Include="@JdkIncludePath@=$(JavaIncludePath)" />
<Replacement Include="@LibUnwindSourceFullPath@=$(LibUnwindSourceFullPath)" />
<Replacement Include="@LibZipSourceFullPath@=$(LibZipSourceFullPath)" />
<Replacement Include="@ManagedRuntime@=$(ManagedRuntime)" />
<Replacement Include="@MicrosoftAndroidSdkOutDir@=$(MicrosoftAndroidSdkOutDir)" />
Expand Down
1 change: 1 addition & 0 deletions external/libunwind
Submodule libunwind added at 688caa
213 changes: 213 additions & 0 deletions java.interop-tracing.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs
index 76f2bfc0..7a57f6b2 100644
--- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs
+++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs
@@ -133,6 +133,7 @@ namespace Java.Interop.Tools.JavaCallableWrappers {

JavaCallableWrapperGenerator (TypeDefinition type, string? outerType, Action<string, object[]> log, IMetadataResolver resolver, JavaCallableMethodClassifier? methodClassifier = null)
{
+ Console.WriteLine ($"JCWG: processing {type}");
this.methodClassifier = methodClassifier;
this.type = type;
this.log = log;
@@ -224,6 +225,8 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
curCtors = new List<MethodDefinition> ();
AddConstructors (ctorTypes [i], outerType, baseCtors, curCtors, false);
}
+
+ Console.WriteLine ($"JCWG: done processing {type}");
}

static void ExtractJavaNames (string jniName, out string package, out string type)
@@ -285,8 +288,10 @@ namespace Java.Interop.Tools.JavaCallableWrappers {

void AddConstructor (MethodDefinition ctor, TypeDefinition type, string? outerType, List<MethodDefinition>? baseCtors, List<MethodDefinition> curCtors, bool onlyRegisteredOrExportedCtors, bool skipParameterCheck)
{
+ Console.WriteLine ($" JCWG: AddConstructor ({ctor}, {type}, ..., onlyRegisteredOrExportedCtors: {onlyRegisteredOrExportedCtors}, skipParameterCheck: {skipParameterCheck});");
string managedParameters = GetManagedParameters (ctor, outerType);
if (!skipParameterCheck && (managedParameters == null || ctors.Any (c => c.ManagedParameters == managedParameters))) {
+ Console.WriteLine (" JCWG: skip #1");
return;
}

@@ -297,28 +302,38 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
}
ctors.Add (new Signature (ctor, eattr, cache));
curCtors.Add (ctor);
+ Console.WriteLine (" JCWG: add #1");
return;
}

RegisterAttribute rattr = GetMethodRegistrationAttributes (ctor).FirstOrDefault ();
if (rattr != null) {
- if (ctors.Any (c => c.JniSignature == rattr.Signature))
+ if (ctors.Any (c => c.JniSignature == rattr.Signature)) {
+ Console.WriteLine (" JCWG: skip #2");
return;
+ }
ctors.Add (new Signature (ctor, rattr, managedParameters, outerType, cache));
curCtors.Add (ctor);
+ Console.WriteLine (" JCWG: add #2");
return;
}

- if (onlyRegisteredOrExportedCtors)
+ if (onlyRegisteredOrExportedCtors) {
+ Console.WriteLine (" JCWG: skip #1");
return;
+ }

string? jniSignature = GetJniSignature (ctor, cache);

- if (jniSignature == null)
+ if (jniSignature == null) {
+ Console.WriteLine (" JCWG: skip #3");
return;
+ }

- if (ctors.Any (c => c.JniSignature == jniSignature))
+ if (ctors.Any (c => c.JniSignature == jniSignature)) {
+ Console.WriteLine (" JCWG: skip #4");
return;
+ }

if (baseCtors == null) {
throw new InvalidOperationException ("`baseCtors` should not be null!");
@@ -327,11 +342,13 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
if (baseCtors.Any (m => m.Parameters.AreParametersCompatibleWith (ctor.Parameters, cache))) {
ctors.Add (new Signature (".ctor", jniSignature, "", managedParameters, outerType, null));
curCtors.Add (ctor);
+ Console.WriteLine (" JCWG: add #3");
return;
}
if (baseCtors.Any (m => !m.HasParameters)) {
ctors.Add (new Signature (".ctor", jniSignature, "", managedParameters, outerType, ""));
curCtors.Add (ctor);
+ Console.WriteLine (" JCWG: add #4");
return;
}
}
@@ -549,17 +566,17 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
GenerateHeader (writer);

bool needCtor = false;
- if (HasDynamicallyRegisteredMethods) {
+// if (HasDynamicallyRegisteredMethods) {
needCtor = true;
writer.WriteLine ("/** @hide */");
writer.WriteLine ("\tpublic static final String __md_methods;");
- }
+// }

if (children != null) {
for (int i = 0; i < children.Count; i++) {
- if (!children[i].HasDynamicallyRegisteredMethods) {
- continue;
- }
+ // if (!children[i].HasDynamicallyRegisteredMethods) {
+ // continue;
+ // }
needCtor = true;
writer.Write ("\tstatic final String __md_");
writer.Write (i + 1);
@@ -570,9 +587,9 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
if (needCtor) {
writer.WriteLine ("\tstatic {");

- if (HasDynamicallyRegisteredMethods) {
+// if (HasDynamicallyRegisteredMethods) {
GenerateRegisterType (writer, this, "__md_methods");
- }
+// }

if (children != null) {
for (int i = 0; i < children.Count; ++i) {
@@ -687,9 +704,12 @@ namespace Java.Interop.Tools.JavaCallableWrappers {

void GenerateBody (TextWriter sw)
{
+ Console.WriteLine ($" JCWG: GenerateBody for {name} (ctors size: {ctors.Count})");
foreach (Signature ctor in ctors) {
- if (string.IsNullOrEmpty (ctor.Params) && JavaNativeTypeManager.IsApplication (type, cache))
+ if (string.IsNullOrEmpty (ctor.Params) && JavaNativeTypeManager.IsApplication (type, cache)) {
+ Console.WriteLine ($" JCWG: skipping constructor generation; params empty? {string.IsNullOrEmpty (ctor.Params)}; is application? {JavaNativeTypeManager.IsApplication (type, cache)}");
continue;
+ }
GenerateConstructor (ctor, sw);
}

@@ -745,9 +765,9 @@ namespace Java.Interop.Tools.JavaCallableWrappers {

void GenerateRegisterType (TextWriter sw, JavaCallableWrapperGenerator self, string field)
{
- if (!self.HasDynamicallyRegisteredMethods) {
- return;
- }
+ // if (!self.HasDynamicallyRegisteredMethods) {
+ // return;
+ // }

sw.Write ("\t\t");
sw.Write (field);
@@ -818,9 +838,13 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
return jniName.Replace ('/', '.').Replace ('$', '.');
}

- bool CannotRegisterInStaticConstructor (TypeDefinition type)
+ bool CannotRegisterInStaticConstructor (TypeDefinition type, bool dolog = false)
{
- return JavaNativeTypeManager.IsApplication (type, cache) || JavaNativeTypeManager.IsInstrumentation (type, cache);
+ Console.WriteLine ($" JCWG: CannotRegisterInStaticConstructor ({type})");
+ bool ret = JavaNativeTypeManager.IsApplication (type, cache) || JavaNativeTypeManager.IsInstrumentation (type, cache);
+ Console.WriteLine ($" JCWG: CannotRegisterInStaticConstructor for type {type}; ret == {ret}; IsApplication: {JavaNativeTypeManager.IsApplication (type, cache)}; IsInstrumentation: {JavaNativeTypeManager.IsInstrumentation (type, cache)}");
+
+ return ret;
}

class Signature {
@@ -941,6 +965,8 @@ namespace Java.Interop.Tools.JavaCallableWrappers {

void GenerateConstructor (Signature ctor, TextWriter sw)
{
+ Console.WriteLine ($" JCWG: GenerateConstructor for {name}");
+
// TODO: we only generate constructors so that Android types w/ no
// default constructor can be subclasses by our generated code.
//
diff --git a/tools/java-source-utils/.classpath b/tools/java-source-utils/.classpath
index 30230c1c..cbded110 100644
--- a/tools/java-source-utils/.classpath
+++ b/tools/java-source-utils/.classpath
@@ -20,6 +20,12 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
+ <classpathentry kind="src" output="bin/main" path="src/main/resources">
+ <attributes>
+ <attribute name="gradle_scope" value="main"/>
+ <attribute name="gradle_used_by_scope" value="main,test"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
diff --git a/tools/java-source-utils/.project b/tools/java-source-utils/.project
index 8337a1c5..613733c8 100644
--- a/tools/java-source-utils/.project
+++ b/tools/java-source-utils/.project
@@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
+ <filteredResources>
+ <filter>
+ <id>1682588570543</id>
+ <name></name>
+ <type>30</type>
+ <matcher>
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
+ <arguments>node_modules|.metadata|archetype-resources|META-INF/maven|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+ </matcher>
+ </filter>
+ </filteredResources>
</projectDescription>
17 changes: 7 additions & 10 deletions src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,11 @@ public void RegisterNativeMembers (
{
try {
if (methods.IsEmpty) {
if (jniAddNativeMethodRegistrationAttributePresent)
RuntimeNativeMethods.monodroid_log (LogLevel.Info, LogCategories.Assembly, $"RegisterJniNatives: Type {type.FullName} registers no methods");
if (jniAddNativeMethodRegistrationAttributePresent) {
RuntimeNativeMethods.monodroid_log (LogLevel.Info, LogCategories.Assembly, $"RegisterJniNatives: Type {type.FullName} has [AddNativeMethodRegistration] attribute");
base.RegisterNativeMembers (nativeClass, type, methods.ToString ());
}
return;
} else if (FastRegisterNativeMembers (nativeClass, type, methods)) {
return;
Expand Down Expand Up @@ -539,6 +542,7 @@ public void RegisterNativeMembers (
throw new InvalidOperationException (FormattableString.Invariant ($"Specified managed method '{mname.ToString ()}' was not found. Signature: {signature.ToString ()}"));
callback = CreateDynamicCallback (minfo);
needToRegisterNatives = true;
RuntimeNativeMethods.monodroid_log (LogLevel.Info, LogCategories.Assembly, $"RegisterJniNativesMethod: [ ] {type.FullName}: __export__ found for method '{name.ToString ()}'");
} else {
Type callbackDeclaringType = type;
if (!callbackDeclaringTypeString.IsEmpty) {
Expand All @@ -556,27 +560,20 @@ public void RegisterNativeMembers (
if (callback != null) {
needToRegisterNatives = true;
natives [nativesIndex++] = new JniNativeMethodRegistration (name.ToString (), signature.ToString (), callback);
RuntimeNativeMethods.monodroid_log (LogLevel.Info, LogCategories.Assembly, $"RegisterJniNativesMethod: [ ] {type.FullName}.{name.ToString ()}");
}
}

methodsSpan = newLineIndex != -1 ? methodsSpan.Slice (newLineIndex + 1) : default;
}

if (needToRegisterNatives) {
RuntimeNativeMethods.monodroid_log (LogLevel.Info, LogCategories.Assembly, $"RegisterJniNatives: Type {type.FullName} calling JniEnvironment.Types.RegisterNatives");
JniEnvironment.Types.RegisterNatives (nativeClass.PeerReference, natives, nativesIndex);
}
} catch (Exception e) {
JniEnvironment.Runtime.RaisePendingException (e);
}

bool ShouldRegisterDynamically (string callbackTypeName, string callbackString, string typeName, string callbackName)
{
if (String.Compare (typeName, callbackTypeName, StringComparison.Ordinal) != 0) {
return false;
}

return String.Compare (callbackName, callbackString, StringComparison.Ordinal) == 0;
}
}

static int CountMethods (ReadOnlySpan<char> methodsSpan)
Expand Down
Loading
Loading