-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8323552: AbstractMemorySegmentImpl#mismatch returns -1 when comparing distinct areas of the same instance of MemorySegment #17354
Conversation
👋 Welcome back plevart! A progress list of the required criteria for merging this PR into |
Webrevs
|
Note there's another bug for this: https://bugs.openjdk.org/browse/JDK-8323524 |
@@ -681,7 +681,7 @@ public static long mismatch(MemorySegment srcSegment, long srcFromOffset, long s | |||
long dstBytes = dstToOffset - dstFromOffset; | |||
srcImpl.checkAccess(srcFromOffset, srcBytes, true); | |||
dstImpl.checkAccess(dstFromOffset, dstBytes, true); | |||
if (dstImpl == srcImpl) { | |||
if (dstImpl.equals(srcImpl) && srcFromOffset == dstFromOffset && srcBytes == dstBytes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also ok to completely drop this check (or move it into the instance version of the mismatch method). This also needs a test.
if ( | ||
other instanceof AbstractMemorySegmentImpl that && | ||
unsafeGetBase() == that.unsafeGetBase() && | ||
unsafeGetOffset() == that.unsafeGetOffset() && | ||
byteSize() == that.byteSize() | ||
) { | ||
this.checkAccess(0, this.byteSize(), true); | ||
that.checkAccess(0, that.byteSize(), true); | ||
checkValidState(); | ||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skeptical of trying to optimize this without a more thorough performance investigation. We shouldn't add this complexity on a whim.
I'm more in favor of just dropping the check from the static mismatch method and leaving it at that. (And adding a test as Maurizio mentioned).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have similar thoughts. This is low-level API. Code using it has more context knowledge and is more fit to do optimisations like that or not, depending if they are worth it. I would want such low level API to do as little checks as possible to accommodate faster common case scenario.
@plevart This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@plevart Are you planning to finish this? (add a test). Or maybe someone else can take over and do the rest? |
❗ This change is not yet ready to be integrated. |
@plevart This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@plevart This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
I belive there is a bug in
AbstractMemorySegmentImpl#mismatch
method. It returns-1
(meaning that regions are equal) when passing the same instance of MemorySegment as bothsrcSegment
anddstSegment
parameters regardless of whethersrcFromOffset
anddstFromOffset
as well assrcToOffset
anddstToOffset
are also equal.Am I right?
Progress
Error
Issue
Backport <hash>
with the hash of the original commit. See Backports.Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17354/head:pull/17354
$ git checkout pull/17354
Update a local copy of the PR:
$ git checkout pull/17354
$ git pull https://git.openjdk.org/jdk.git pull/17354/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17354
View PR using the GUI difftool:
$ git pr show -t 17354
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17354.diff
Webrev
Link to Webrev Comment