Skip to content
This repository has been archived by the owner. It is now read-only.

8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper#pagePosition #84

Closed
wants to merge 3 commits into from

Conversation

@mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Jan 5, 2021

Hi,
this patch fixes an oversight where the address() method in FileChannelImpl.Unmapper does not take into account the value of pagePosition - this leads to a situation in which, effectively, the specified offset when mapping the segment is ignored by the runtime (because base address will always be aligned to some known quantity - which is OS/platform dependent).

To test this I had to break open into FileChannelImpl and ready the granularity.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper#pagePosition

Reviewers

Contributors

  • Uwe Schindler <uschindler@openjdk.org>

Download

$ git fetch https://git.openjdk.java.net/jdk16 pull/84/head:pull/84
$ git checkout pull/84

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jan 5, 2021

👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Loading

@openjdk openjdk bot added the rfr label Jan 5, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jan 5, 2021

@mcimadamore The following labels will be automatically applied to this pull request:

  • core-libs
  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Jan 5, 2021

Webrevs

Loading

@@ -25,7 +25,7 @@
* @test
* @modules java.base/sun.nio.ch
* jdk.incubator.foreign/jdk.internal.foreign
* @run testng/othervm -Dforeign.restricted=permit TestByteBuffer
* @run testng/othervm --illegal-access=permit -Dforeign.restricted=permit TestByteBuffer

Choose a reason for hiding this comment

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

Can you change java.base/sun.nio.ch to java.base/sun.nio.ch:+open instead? That would avoid the --illegal-access=permit.

Loading

Copy link
Member

@uschindler uschindler Jan 5, 2021

Choose a reason for hiding this comment

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

I am not sure if a test like this is really needed.
The alignment is pageSize on Linux and some arbitrary value (65536) on Windows. If you have some test file that writes like a few bytes (1, 2, 3, 4,...) To a file and then maps it with offsets other than zero, you just have to get the first byte and compare it to offset.

Loading

Copy link
Member

@uschindler uschindler Jan 5, 2021

Choose a reason for hiding this comment

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

In fact the new test only checks if everything is aligned like we expect, but it does not test that our mapping returns a memory segment with expected contents.

Loading

Copy link
Member

@uschindler uschindler Jan 5, 2021

Choose a reason for hiding this comment

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

So I tend to make a simple test without reflection that writes a defined sequence of bytes to a file and then maps it with various offsets, checking that the first byte in the mapped segment is from that sequence.

Loading

Copy link
Contributor Author

@mcimadamore mcimadamore Jan 5, 2021

Choose a reason for hiding this comment

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

Good suggestion!

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jan 5, 2021

@mcimadamore this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8259032_pagepos
git fetch https://git.openjdk.java.net/jdk16 master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

Loading

@uschindler
Copy link
Member

@uschindler uschindler commented Jan 5, 2021

Hi,
The new test looks fine to me.
Uwe

Loading

Copy link

@AlanBateman AlanBateman left a comment

Good suggestion from Uwe.

Loading

@mcimadamore
Copy link
Contributor Author

@mcimadamore mcimadamore commented Jan 6, 2021

/integrate

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jan 6, 2021

@mcimadamore This PR has not yet been marked as ready for integration.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jan 6, 2021

@mcimadamore This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8259032: MappedMemorySegmentImpl#makeMappedSegment() ignores Unmapper#pagePosition

Co-authored-by: Uwe Schindler <uschindler@openjdk.org>
Reviewed-by: alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

Loading

@openjdk openjdk bot added ready and removed merge-conflict labels Jan 6, 2021
@mcimadamore
Copy link
Contributor Author

@mcimadamore mcimadamore commented Jan 6, 2021

/contributor add uschindler

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jan 6, 2021

@mcimadamore
Contributor Uwe Schindler <uschindler@openjdk.org> successfully added.

Loading

@mcimadamore
Copy link
Contributor Author

@mcimadamore mcimadamore commented Jan 6, 2021

/integrate

Loading

@openjdk openjdk bot closed this Jan 6, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Jan 6, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jan 6, 2021

@mcimadamore Pushed as commit e66187d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants