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

[Java.Interop] Add JniIdentityHashCode to ObjectDisposedException #1276

Merged

Conversation

jonpryor
Copy link
Member

@jonpryor jonpryor commented Nov 8, 2024

Context: dotnet/android#9039
Context: dotnet/android@32495f3

@jonpryor suspects that the ObjectDisposedException being thrown within dotnet/android#9039 may be due to a GC-related bug.

A problem with diagnosing this is tracking object lifetimes: yes, an Android.Runtime.InputStreamInvoker is throwing
ObjectDisposedException, but in local reproductions, there are multiple InputStreamInvoker instances created! Which one is throwing?

A local answer to that was "Update InputStreamInvoker.Read() to log BaseInputStream.JniIdentityHashCode", which was useful, but is not a "scalable" solution.

Review all throw new ObjectDisposedException() calls within Java.Interop.dll, and update all sites which use IJavaPeerable to include the JniIdentityHashCode value in the exception message. This would result in a message like:

System.ObjectDisposedException: Cannot access disposed object with JniIdentityHashCode=0x12345678.
Object name: 'Android.Runtime.InputStreamInvoker'.
   at Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable )
   …

Context: dotnet/android#9039
Context: dotnet/android@32495f3

@jonpryor suspects that the `ObjectDisposedException` being thrown
within dotnet/android#9039 *may* be due to a GC-related bug.

A problem with diagnosing this is tracking object lifetimes: yes, an
`Android.Runtime.InputStreamInvoker` is throwing
`ObjectDisposedException`, but in local reproductions, there are
*multiple* `InputStreamInvoker` instances created!  Which one is
throwing?

A local answer to that was "Update `InputStreamInvoker.Read()` to log
`BaseInputStream.JniIdentityHashCode`", which *was* useful, but is
not a "scalable" solution.

Review all `throw new ObjectDisposedException()` calls within
`Java.Interop.dll`, and update all sites which use `IJavaPeerable`
to include the `JniIdentityHashCode` value in the exception message.
This would result in a message like:

	System.ObjectDisposedException: Cannot access disposed object with JniIdentityHashCode=0x12345678.
	Object name: 'Android.Runtime.InputStreamInvoker'.
	   at Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable )
	   …
@jonpryor jonpryor merged commit 2440416 into main Nov 8, 2024
4 checks passed
@jonpryor jonpryor deleted the dev/jonp/jonp-IdentityHashCode-in-ObjectDisposedException branch November 8, 2024 16:54
jonpryor added a commit to dotnet/android that referenced this pull request Nov 8, 2024
Changes: dotnet/java-interop@2bdf2bc...2440416

  * dotnet/java-interop@24404162: [Java.Interop] Add JniIdentityHashCode to ObjectDisposedException (dotnet/java-interop#1276)
jonpryor added a commit to dotnet/android that referenced this pull request Nov 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants