Remove unnecessary DAM attributes#1481
Merged
Merged
Conversation
Remove DynamicallyAccessedMembers annotations from runtime extensibility points where broad rooting is more harmful than useful. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove test-side DAM annotations that no longer match the updated runtime signatures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR reduces trimming/AOT rooting pressure by removing DynamicallyAccessedMembers annotations from several runtime type/value-manager and marshaler extensibility points, shifting responsibility to explicit RequiresUnreferencedCode/feature-guarded call sites and updating tests/samples/PublicAPI accordingly.
Changes:
- Removed broad
DynamicallyAccessedMembersannotations fromJniTypeManager/JniValueManager/JniValueMarshalerAPIs and related overrides. - Introduced/adjusted trimming annotations (
RequiresUnreferencedCode,FeatureGuard) around reflection-heavy paths. - Updated tests, NativeAOT samples, and
PublicAPI.Unshipped.txtto match signature/API removals.
Show a summary per file
| File | Description |
|---|---|
| tests/Java.Interop-Tests/Java.Interop/JniValueMarshalerContractTests.cs | Updates test marshaler override signature to match removed DAM annotations. |
| tests/Java.Interop-Tests/Java.Interop/JavaVMFixture.cs | Removes return DAM annotation from test override. |
| src/Java.Runtime.Environment/Java.Interop/JreTypeManager.cs | Updates override signature to match removed DAM annotations. |
| src/Java.Interop/PublicAPI.Unshipped.txt | Removes unshipped API entries for removed type(s)/member(s). |
| src/Java.Interop/Java.Interop/RuntimeFeature.cs | Adds feature guard for trimming, but currently introduces a switch-caching behavior change. |
| src/Java.Interop/Java.Interop/ManagedPeer.cs | Adds RequiresUnreferencedCode and removes suppressions tied to prior DAM behavior. |
| src/Java.Interop/Java.Interop/JniValueMarshaler.cs | Removes DAM-related constants/annotations from marshaler extensibility points. |
| src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs | Updates override signature to match removed DAM annotations. |
| src/Java.Interop/Java.Interop/JniRuntime.ReflectionJniValueManager.cs | Removes DAM usage and updates type enumeration to GetTypes. Adds RequiresUnreferencedCode to reflection-heavy marshalers. |
| src/Java.Interop/Java.Interop/JniRuntime.ReflectionJniTypeManager.cs | Removes GetReflectionConstructibleTypes and DAM annotations in overrides/registration. |
| src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs | Removes DAM annotations from several APIs (except where still retained), updating generic marshaler APIs/signatures. |
| src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs | Removes DAM annotations and removes the ReflectionConstructibleType API surface. |
| src/Java.Interop/Java.Interop/JniBuiltinMarshalers.cs | Adjusts placement of builtin marshaler map, but is T4-generated and should be updated via the .tt template. |
| src/Java.Interop/Java.Interop/JavaPrimitiveArrays.cs | Removes DAM annotations from marshaling entrypoints. |
| src/Java.Interop/Java.Interop/JavaObjectArray.cs | Adjusts generic parameter annotation formatting and removes now-unneeded DAM usage in marshaler override signature. |
| src/Java.Interop/Java.Interop/JavaArray.cs | Removes DAM annotation from JavaPrimitiveArray<T>. |
| samples/Hello-NativeAOTFromJNI/NativeAotTypeManager.cs | Removes DAM return annotation, but suppression text now references removed DAM behavior. |
| samples/Hello-NativeAOTFromAndroid/NativeAotTypeManager.cs | Removes DAM return annotation, but suppression text now references removed DAM behavior. |
Copilot's findings
- Files reviewed: 18/18 changed files
- Comments generated: 4
Update the builtin marshaler template and NativeAOT sample suppression justifications after removing broad DAM annotations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DynamicallyAccessedMembersannotations from runtime type/value manager and marshaler extensibility points where broad rooting is more harmful than usefulTesting
dotnet build tests/Java.Interop-Tests/Java.Interop-Tests.csproj --nologo -m:1dotnet build --nologo -m:1