Skip to content

[Java.Runtime.Environment] don't call PeekPeer() inside AddPeer() #1329

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

Closed
wants to merge 1 commit into from

Conversation

jonathanpeppers
Copy link
Member

Context: dotnet/android#10004

This breaks the "replaceable" logic otherwise.

Context: dotnet/android#10004

This breaks the "replaceable" logic otherwise.
@jonathanpeppers jonathanpeppers requested a review from Copilot April 3, 2025 16:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the call to PeekPeer inside AddPeer to fix issues with the "replaceable" logic in the Java runtime environment.

  • Removed PeekPeer check from MonoRuntimeValueManager.cs
  • Removed PeekPeer check from ManagedValueManager.cs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Java.Runtime.Environment/Java.Interop/MonoRuntimeValueManager.cs Removed PeekPeer call from AddPeer to prevent premature return when a duplicate peer is encountered.
src/Java.Runtime.Environment/Java.Interop/ManagedValueManager.cs Removed PeekPeer check from AddPeer, aligning with the updated logic to support replaceable peers.

@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

No pipelines are associated with this pull request.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 3, 2025 17:12
@jonpryor
Copy link
Member

jonpryor commented Apr 4, 2025

This could use a test. dotnet/android#10004 notes behavior around "replaceable" values. What somewhat confuses me about this is #1323 also attempted to test replaceable values, and did not need any changes within dotnet/java-interop to pass. Meanwhile, the tests failed under dotnet/android#9921, for reasons I haven't gotten a chance to investigate.

Is the test in #1323 incorrect or insufficient? Are we hitting a different corner case around "replaceable" values?

The explanation in this PR also leaves me wanting:

This breaks the "replaceable" logic otherwise.

How does this break "replaceable" logic?

Especially considering this existing test, which attempts to assert that duplicate AddPeer() calls is idempotent:

[Test]
public void AddPeer_NoDuplicates ()
{
int startPeerCount = GetSurfacedPeersCount ();
using (var v = new MyDisposableObject ()) {
// MyDisposableObject ctor implicitly calls AddPeer();
Assert.AreEqual (startPeerCount + 1, GetSurfacedPeersCount (), DumpPeers ());
valueManager.AddPeer (v);
Assert.AreEqual (startPeerCount + 1, GetSurfacedPeersCount (), DumpPeers ());
}
}

The existing test passes, but why? I wonder if we're now getting a WarnNotReplacing()?

@jonathanpeppers
Copy link
Member Author

I do need to revisit what's happening this repo (java.interop) & the test above, but on the dotnet/android side:

  1. Object A is replaceable, it will be returned if asked for by PeekPeer()
  2. Object B comes around and needs to replace A
  3. PeekPeer() returns A and so none of the "replacing" logic runs at all, it returns early here:

var o = PeekPeer (value.PeerReference);
if (o != null)
return;

So, I think this one we could merge, as a test caught it and is fixed by the change:

Further investigation & test changes needed on this PR.

@jonpryor
Copy link
Member

I believe that this has been superseded by #1323, which also removes the PeekPeer() invocation from ManagedValueManager.cs, and adds unit tests (and more!).

@jonpryor jonpryor closed this Apr 11, 2025
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.

2 participants