Skip to content

[tests] run Java.Interop-Tests on NativeAOT - #10496

Merged
jonathanpeppers merged 10 commits into
mainfrom
dev/peppers/java-interop-tests-nativeaot
Mar 16, 2026
Merged

[tests] run Java.Interop-Tests on NativeAOT#10496
jonathanpeppers merged 10 commits into
mainfrom
dev/peppers/java-interop-tests-nativeaot

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

In 32fcc8b, I enabled tests related to the "GC Bridge" on NativeAOT, but discovered we still weren't running dotnet/java-interop's tests. Let's enable them.

We can also remove $(DefineConstants) for CORECLR and NATIVEAOT as there is nothing using these.

In 32fcc8b, I enabled tests related to the "GC Bridge" on NativeAOT,
but discovered we still weren't running dotnet/java-interop's tests.
Let's enable them.
We can also remove `$(DefineConstants)` for `CORECLR` and `NATIVEAOT`
as there is nothing using these.
@jonathanpeppers

Copy link
Copy Markdown
MemberAuthor

This one crashes with:

09-17 20:22:12.204 9703 9724 I NUnit : RegisterWithVM_PermitsAliases 09-17 20:22:12.204 9703 9724 I NUnit : Passed
09-17 20:22:12.204 9703 9724 I NUnit : UnreferencedInstanceIsCollected 09-17 20:22:12.227 9703 9723 I droid.NET_Test: Explicit concurrent copying GC freed 47(62KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 1366KB/2902KB, paused 2.044ms total 12.476ms
09-17 20:22:12.242 9703 9723 I droid.NET_Test: Explicit concurrent copying GC freed 3(16KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 1366KB/2902KB, paused 2.037ms total 10.965ms
09-17 20:22:12.243 9703 9741 F monodroid: The method is not implemented. This is a stub and should not be called.
09-17 20:22:12.243 9703 9741 F monodroid: Abort at internal-pinvoke-stubs.cc:10:3 ('void (anonymous namespace)::pinvoke_unreachable()')
--------- beginning of crash
09-17 20:22:12.243 9703 9741 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 9741 (Thread-15), pid 9703 (droid.NET_Tests)
09-17 20:22:12.292 9760 9760 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
09-17 20:22:12.301 1870 1870 I /system/bin/tombstoned: received crash request for pid 9741
09-17 20:22:12.303 9760 9760 I crash_dump64: performing dump of process 9703 (target tid = 9741)
09-17 20:22:12.308 9760 9760 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-17 20:22:12.309 9760 9760 F DEBUG : Build fingerprint: 'Android/sdk_phone_x86_64/generic_x86_64:10/QSR1.210820.001/7663313:userdebug/test-keys'
09-17 20:22:12.309 9760 9760 F DEBUG : Revision: '0'
09-17 20:22:12.309 9760 9760 F DEBUG : ABI: 'x86_64'
09-17 20:22:12.312 9760 9760 F DEBUG : Timestamp: 2025-09-17 20:22:12+0000
09-17 20:22:12.312 9760 9760 F DEBUG : pid: 9703, tid: 9741, name: Thread-15 >>> Mono.Android.NET_Tests <<<
09-17 20:22:12.312 9760 9760 F DEBUG : uid: 10121
09-17 20:22:12.312 9760 9760 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
09-17 20:22:12.312 9760 9760 F DEBUG : Abort message: 'The method is not implemented. This is a stub and should not be called.'
09-17 20:22:12.312 9760 9760 F DEBUG : rax 0000000000000000 rbx 00000000000025e7 rcx 000072e776f643f8 rdx 0000000000000006
09-17 20:22:12.312 9760 9760 F DEBUG : r8 000072e69daf3356 r9 0000000000000000 r10 000072e5205a54f0 r11 0000000000000246
09-17 20:22:12.313 9760 9760 F DEBUG : r12 000072e69daf3356 r13 000072e69daf9345 r14 000072e5205a5578 r15 000000000000260d
09-17 20:22:12.313 9760 9760 F DEBUG : rdi 00000000000025e7 rsi 000000000000260d
09-17 20:22:12.313 9760 9760 F DEBUG : rbp 000072e5205a57e0 rsp 000072e5205a54e8 rip 000072e776f643f8
09-17 20:22:12.412 9760 9760 F DEBUG : 09-17 20:22:12.412 9760 9760 F DEBUG : backtrace:
09-17 20:22:12.413 9760 9760 F DEBUG : #00 pc 00000000000943f8 /apex/com.android.runtime/lib64/bionic/libc.so (syscall+24) (BuildId: b5c6019a3b4ea61b5e9a2f56319b584e)
09-17 20:22:12.414 9760 9760 F DEBUG : #01 pc 0000000000097146 /apex/com.android.runtime/lib64/bionic/libc.so (abort+182) (BuildId: b5c6019a3b4ea61b5e9a2f56319b584e)
09-17 20:22:12.414 9760 9760 F DEBUG : #02 pc 000000000010409f /data/app/Mono.Android.NET_Tests-Gfdg4USGyH70bxzMdRh4Tw==/split_config.x86_64.apk

Context: 869b0e0
The `pinvoke_unreachable` function, when invoked, would log
its own source location instead of that of the call site.
That's a bit useless in diagnosing issues, so let's improve
it by logging the call site location... :)
@grendello

Copy link
Copy Markdown
Contributor

I added the #10502 change to this PR, it should give us better info on which p/invoke was called.

grendello added a commit that referenced this pull request Sep 19, 2025
Context: #10496 (comment)
Context: 869b0e0
The `_monodroid_weak_gref_delete` p/invoke wasn't implemented
in 869b0e0 as it was thought to be unused. However, the test
failure in #10496 shows that it's not true.
Bring the `_monodroid_weak_gref_delete` implementation to NativeAOT
host from the CoreCLR host.
Context: #10496 (comment)
Context: 869b0e0
The `_monodroid_weak_gref_delete` p/invoke wasn't implemented
in 869b0e0 as it was thought to be unused. However, the test
failure in #10496 shows that it's not true.
Bring the `_monodroid_weak_gref_delete` implementation to NativeAOT
host from the CoreCLR host.
@grendello

Copy link
Copy Markdown
Contributor

Comitted the change in #10504 to this PR, it implements _monodroid_weak_gref_delete, the p/invoke that causing the crash.

@jonathanpeppers

Copy link
Copy Markdown
MemberAuthor

Now we are beyond the crash, there are test failures that are probably bugs:

Mono.Android.NET_Tests, Java.InteropTests.JniPeerMembersTests.ReplaceStaticMethodName / Release
Java.Lang.NoSuchMethodError : no static method "Ljava/lang/Runtime;.remappedToGetRuntime()Ljava/lang/Runtime;"

Seems like some package name or text is missing before the .remappedToGetRuntime value.

jonathanpeppers pushed a commit that referenced this pull request Sep 19, 2025
Context: #10496 (comment)
Context: 869b0e0
The `_monodroid_weak_gref_delete` p/invoke wasn't implemented
in 869b0e0 as it was thought to be unused. However, the test
failure in #10496 shows that it's not true.
Bring the `_monodroid_weak_gref_delete` implementation to NativeAOT
host from the CoreCLR host.
Resolve 3 merge conflicts:
- internal-pinvokes-clr.cc: accept main's removal of _monodroid_timezone_get_default_id (moved elsewhere)
- internal-pinvoke-stubs.cc: accept main's removal of _monodroid_timezone_get_default_id stub
- Mono.Android.NET-Tests.csproj: keep PR's removal of CORECLR/NATIVEAOT DefineConstants
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppersforce-pushed the dev/peppers/java-interop-tests-nativeaot branch from 39e3ff3 to 6c349a2CompareMarch 12, 2026 19:36
The function already exists with [[maybe_unused]] on from_writable and
correctly calls OSBridge with 5 args. The duplicate caused:
- redefinition error (same C++ signature)
- wrong arg count (OSBridge only takes 5 args, not 6)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppersand others added 3 commits March 13, 2026 16:44
Three changes to ManagedTypeManager (the NativeAOT type manager):
1. Add GetStaticMethodFallbackTypesCore override - returns Desugar{name}
and {name}$-CC fallback types for desugared interface static methods.
Fixes: DesugarInterfaceStaticMethod test.
2. Reorder GetTypesForSimpleReference to yield base class results first.
The base JniTypeManager has built-in mappings (java/lang/String to
System.String, java/lang/Float to float?, etc.) that must take priority
over ManagedTypeMapping (which returns Java.Lang.String).
Fixes: GetType, GetTypeSignature, and JavaObjectArray equality tests.
3. Call base.RegisterNativeMembers when methods string is empty, so the
base class can find and invoke [JniAddNativeMethodRegistrationAttribute]
methods. Previously ManagedTypeManager returned early, skipping this.
Fixes: InvokeVirtualFromConstructorTests.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The fallback type must include the \ suffix to match the actual
desugared companion class name (e.g. DesugarAndroidInterface\).
This matches the pattern used by the Java.Interop test fixture.
Fixes DesugarInterfaceStaticMethod test on NativeAOT.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds [Category("NativeAOTIgnore")] to InvokeVirtualFromConstructorTests.
Tracking: #10950
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppersjonathanpeppers added the copilot `copilot-cli` or other AIs were used to author this label Mar 16, 2026
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review March 16, 2026 17:39
CopilotAI review requested due to automatic review settings March 16, 2026 17:39

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables running dotnet/java-interop tests (Java.Interop-Tests) under NativeAOT and adjusts runtime type resolution behavior to support those tests, while simplifying test project build constants.

Changes:

  • Always include Java.Interop-Tests in the runtime test assembly list (removes the NativeAOT exclusion).
  • Remove now-unneeded CORECLR/NATIVEAOTDefineConstants from the test project.
  • Update ManagedTypeManager type mapping priority and add fallback type name generation for desugared static methods.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

FileDescription
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.RuntimeTests/NUnitInstrumentation.csRuns Java.Interop-Tests on NativeAOT by always including the assembly in instrumentation.
tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csprojRemoves unused conditional compilation constants for CORECLR/NATIVEAOT.
src/Mono.Android/Microsoft.Android.Runtime/ManagedTypeManager.csAdjusts type-mapping precedence and adds fallback type-name logic for desugared static method resolution.
external/Java.InteropUpdates the Java.Interop submodule revision, likely containing fixes needed for NativeAOT test execution.

Replace StringBuilder with simple string interpolation. Also removes
unused System.Text using.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers merged commit d0f4507 into mainMar 16, 2026
5 of 6 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/peppers/java-interop-tests-nativeaot branch March 16, 2026 20:40
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 16, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

copilot`copilot-cli` or other AIs were used to author this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jonathanpeppers@grendello@simonrozsival