Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16 Public archive

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 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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 5, 2021
@openjdk
Copy link

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.

@openjdk openjdk bot added nio nio-dev@openjdk.java.net core-libs core-libs-dev@openjdk.java.net labels Jan 5, 2021
@mlbridge
Copy link

mlbridge bot commented Jan 5, 2021

Webrevs

@@ -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
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion!

@openjdk
Copy link

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

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Jan 5, 2021
@uschindler
Copy link
Member

Hi,
The new test looks fine to me.
Uwe

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Good suggestion from Uwe.

@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 6, 2021

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

@openjdk
Copy link

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.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed merge-conflict Pull request has merge conflict with target branch labels Jan 6, 2021
@mcimadamore
Copy link
Contributor Author

/contributor add uschindler

@openjdk
Copy link

openjdk bot commented Jan 6, 2021

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

@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk openjdk bot closed this Jan 6, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 6, 2021
@openjdk
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core-libs core-libs-dev@openjdk.java.net integrated Pull request has been integrated nio nio-dev@openjdk.java.net
Development

Successfully merging this pull request may close these issues.

3 participants