Skip to content

[Java.Interop] Remove orphaned internal JNI runtime helpers - #13057

Merged
simonrozsival merged 1 commit into
mainfrom
simonrozsival-orphaned-jni-helpers
Oct 10, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
simonrozsival-orphaned-jni-helpers

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Small, independently mergeable .NET 12 cleanup follow-up to #13030. Remove only internal JniRuntime.JniValueManager.GetRuntimeType() and JniPeerMembers.JniInstanceMethods.AllocObject() / NewObject() (two files, 26 deleted lines).

Semantic references contain only the declarations. Source, generators/templates, reflection strings, conditional sources, friend-assembly tests, and API records were checked for consumers. Public JNI allocation APIs, StartCreateInstance() / FinishCreateInstance(), constructor caches, ActivatePeer, expression marshalling, type management, and ownership logic are unchanged. No framework/package/API-gate upgrade is included.

Build and host validation

Command Result
dotnet build external/Java.Interop/src/Java.Interop/Java.Interop.csproj -c Release -v minimal Passed before and after removal; 0 warnings/errors.
dotnet build external/Java.Interop/src/Java.Interop/Java.Interop.csproj -c Debug -v minimal Passed; 0 warnings/errors.
dotnet test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj -c Release -v minimal --filter 'FullyQualifiedName~generatortests.Constructors' Passed: 1 test, 0 failed/skipped.
make prepare CONFIGURATION=Release Passed, using isolated in-worktree toolchain paths below.
make all CONFIGURATION=Release Initial solution compilation passed (43 warnings, 0 errors), but local workload setup failed because API 37.1 reference output was missing. Passed in full after the existing extra-API target below; no source/config workaround.
./dotnet-local.sh build Microsoft.Android.slnx -t:BuildExtraApiLevels -c Release -v quiet Passed: 78 warnings, 0 errors; generated the missing extra-API references.
./dotnet-local.sh build external/Java.Interop/src/Java.Interop/Java.Interop.csproj -c Release -v minimal Passed with this worktree's rebuilt SDK: 0 warnings/errors.
git diff --check Passed.

Preparation/build environment:

export AndroidToolchainDirectory="$PWD/bin/Release/android-toolchain" AndroidToolchainCacheDirectory="$PWD/bin/Release/android-archives" AndroidSdkDirectory="$PWD/bin/Release/android-sdk" AndroidNdkDirectory="$PWD/bin/Release/android-ndk"

Device validation

Executed against the SDK rebuilt from this change on selected emulator-5554 (API 36, arm64). Focused categories cover constructor parity and activation, Unicode type lookup, core JNI control blocks, peer identity, and transferred-reference ownership. Both TRX files confirm 97 passed, 0 failed, 0 skipped, including ConstructorActivationTests, JavaPeerControlBlockTests, PeerIdentityTests, and TransferredReferenceTests.

Device environment:

export ANDROID_SERIAL=emulator-5554 ANDROID_HOME="$PWD/bin/Release/android-sdk" AndroidSdkDirectory="$PWD/bin/Release/android-sdk" AndroidNdkDirectory="$PWD/bin/Release/android-ndk"

CoreCLR install/build passed (38 warnings, 0 errors); test passed 97/97:

./dotnet-local.sh build -t:Install -c Release -v minimal -p:RuntimeIdentifier=android-arm64 -p:PublishAot=false '-p:IncludeCategories=ConstructorParity%2CInheritedActivationCreateInstance%2CUnicodeJavaIdentifiers%2CPeerControlBlock%2CTransferredReferences%2CJNIObjectArray' '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
(cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:RuntimeIdentifier=android-arm64 -p:PublishAot=false '-p:IncludeCategories=ConstructorParity%2CInheritedActivationCreateInstance%2CUnicodeJavaIdentifiers%2CPeerControlBlock%2CTransferredReferences%2CJNIObjectArray' '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" --report-trx --results-directory ../../../bin/TestRelease/TestResults/OrphanedJniCoreCLRFocused)

NativeAOT install/build passed (11 warnings, 0 errors); test passed 97/97:

./dotnet-local.sh build -t:Install -c Release -v minimal -p:RuntimeIdentifier=android-arm64 -p:PublishAot=true '-p:IncludeCategories=ConstructorParity%2CInheritedActivationCreateInstance%2CUnicodeJavaIdentifiers%2CPeerControlBlock%2CTransferredReferences%2CJNIObjectArray' '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
(cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:RuntimeIdentifier=android-arm64 -p:PublishAot=true '-p:IncludeCategories=ConstructorParity%2CInheritedActivationCreateInstance%2CUnicodeJavaIdentifiers%2CPeerControlBlock%2CTransferredReferences%2CJNIObjectArray' '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" --report-trx --results-directory ../../../bin/TestRelease/TestResults/OrphanedJniNativeAOTFocused)

Bounded broader-suite comparison

An initial unfiltered CoreCLR run crashed in Java.InteropTests.JnienvTest.ThreadReuse: 241 passed, 1 crashed, 2 skipped. Device logcat recorded a fatal runtime error and SIGABRT on the test's native-created thread. Its cause was not established and is not labelled pre-existing.

Before opening this PR, the original versions of the two owned files were temporarily restored and verified exactly against 338725eac0c9e9a4c23f151d18ee52831eed630b. The affected SDK project was rebuilt and its staged Java.Interop assembly checked against the build output, followed by one matching unfiltered CoreCLR run. Then the committed helper deletions were restored and the same affected-project rebuild/install/run repeated. No unrelated source changes, new exclusions, or new tests were introduced.

Implementation Full CoreCLR result ThreadReuse
Retirement-base Java.Interop 924 passed, 0 failed, 7 skipped Passed, verified in TRX
This PR's helper deletions 924 passed, 0 failed, 7 skipped Passed, verified in TRX

The initial crash was not reproduced in this bounded comparison; no root-cause claim is made.

Commands used for each implementation (the baseline used result directory OrphanedJniRetirementBaseline; the restored change used OrphanedJniChangedComparison):

./dotnet-local.sh build src/Mono.Android/Mono.Android.csproj -c Release -m:1 -v minimal "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory"
cmp external/Java.Interop/bin/Release-net10.0/Java.Interop.dll bin/Release/lib/packs/Microsoft.Android.Runtime.37.android/37.99.0/runtimes/android/lib/net11.0/Java.Interop.dll
./dotnet-local.sh build -t:Install -c Release -m:1 -v minimal -p:RuntimeIdentifier=android-arm64 -p:PublishAot=false '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
(cd tests/Mono.Android-Tests/Mono.Android-Tests && ../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:RuntimeIdentifier=android-arm64 -p:PublishAot=false '-p:AdbTarget=-s emulator-5554' "-p:AndroidSdkDirectory=$AndroidSdkDirectory" "-p:AndroidNdkDirectory=$AndroidNdkDirectory" --report-trx --results-directory ../../../bin/TestRelease/TestResults/OrphanedJniChangedComparison)

All matched comparison build/install commands passed; both full test invocations passed. The worktree is restored to the committed deletions, with no temporary baseline source changes left.

JavaInterop1 retirement in #13030 left three internal helpers without
callers: JniRuntime.JniValueManager.GetRuntimeType() and
JniPeerMembers.JniInstanceMethods.AllocObject()/NewObject().

Remove only these orphaned members.  Preserve public JNI allocation,
StartCreateInstance()/FinishCreateInstance(), constructor caches, and
peer activation, identity, and reference-ownership behavior.

Validated with rebuilt Release SDK and 97 focused JNI construction,
identity, and ownership tests on both CoreCLR and NativeAOT.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 22:43

Copilot AI 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.

🟢 Approval recommended

Repository searches found no consumers, public API records are unchanged, and validation is comprehensive.

0 open findings

What changed in this PR

Removes three unused internal Java.Interop helpers left after JavaInterop1 retirement.

Changes:

  • Removes unused runtime type lookup.
  • Removes unused JNI object allocation helpers.
  • Preserves public construction and peer-management APIs.
File Description
JniRuntime.JniValueManager.cs Removes orphaned GetRuntimeType().
JniPeerMembers.JniInstanceMethods.cs Removes orphaned AllocObject() and NewObject().

🧠 Review effort: Balanced

@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto stamp

@simonrozsival
simonrozsival enabled auto-merge (squash) October 10, 2026 05:16

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stamping as requested by @simonrozsival; no code review performed.

@simonrozsival
simonrozsival merged commit ed35c12 into main Oct 10, 2026
43 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-orphaned-jni-helpers branch October 10, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants