8323159: Consider adding some text re. memory zeroing in Arena::allocate#17308
8323159: Consider adding some text re. memory zeroing in Arena::allocate#17308minborg wants to merge 6 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back pminborg! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
@minborg 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: 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 100 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
/csr |
|
@minborg has indicated that a compatibility and specification (CSR) request is needed for this pull request. @minborg please create a CSR request for issue JDK-8323159 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
| * Implementations of this method must return a native, zero-initialized segment | ||
| * featuring the requested size, and that is compatible with the provided alignment |
There was a problem hiding this comment.
Do we want to mandate that all arenas return zero-initialized memory? Maybe it's enough to say that the default implementation does this.
There was a problem hiding this comment.
It's not a default method. That said, according to this suggestion it could be possible to move the text in the ofAuto/ofConfined/ofArena factories.
There was a problem hiding this comment.
The choice here is: if we allow non-zeroing implementation, implementors of Arena have more flexibility, but clients have less guarantees (how does a client know if what they get back is zeroed?)
There was a problem hiding this comment.
(how does a client know if what they get back is zeroed?)
It seems similar to e.g. a HashMap vs. LinkedHashMap with regards to ordering. The creator of the Arena would decide the zeroing strategy.
There was a problem hiding this comment.
Not sure if that analogy is 100% correct. In that case a client that takes a Map, but wants order, can say to accept e.g. a SequencedMap. In the case of Arena, there's no subtype which adds the "zeroing" characteristics. So a client accepting an arena, and doing some allocation would be effectively at the mercy of who created the arena. I think one can argue this both ways.
| * @implSpec | ||
| * Arenas obtained from the factory methods {@linkplain #ofAuto()}, {@linkplain #global()} | ||
| * {@linkplain #ofConfined()} and, {@linkplain #ofShared()} will return segments | ||
| * that are zeroed out when invoking {@linkplain Arena#allocate(long, long) allocate()}. | ||
| * |
There was a problem hiding this comment.
I'd expect to find this in the javadoc of each factory method (not in an implSpec). The note says something about those particular methods, not about the Arena type as a whole.
I also think "zero intialized" sounds a bit more professional than "zeroed out". I suggest the following phrasing:
Memory segments {@linkPlain #allocate(long, long) allocated} by the returned arena are zero initialized
|
/integrate |
|
Going to push as commit f5b757c.
Your commit was automatically rebased without conflicts. |
|
/backport jdk22 |
|
@minborg the backport was successfully created on the branch backport-minborg-f5b757ce in my personal fork of openjdk/jdk22. To create a pull request with this backport targeting openjdk/jdk22:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22: |
| assertEquals(expectedScope, MemorySegment.ofBuffer(view).scope()); | ||
| } | ||
|
|
||
| private static final MemorySegment ZEROED_MEMORY = MemorySegment.ofArray(new byte[8102]); |
There was a problem hiding this comment.
The nearest power of two is 8192 (213):
| private static final MemorySegment ZEROED_MEMORY = MemorySegment.ofArray(new byte[8102]); | |
| private static final MemorySegment ZEROED_MEMORY = MemorySegment.ofArray(new byte[8192]); |
There was a problem hiding this comment.
Good catch. This was a typo. However, the test works as intended and the PR is already integrated.
This PR proposes to add a clarification that an
Arenaalways returns zeroed-out segments forArena::allocatemethods.Note that other overloaded methods refer to the abstract
Arena::allocatemethod via implementation notes.Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17308/head:pull/17308$ git checkout pull/17308Update a local copy of the PR:
$ git checkout pull/17308$ git pull https://git.openjdk.org/jdk.git pull/17308/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17308View PR using the GUI difftool:
$ git pr show -t 17308Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17308.diff
Webrev
Link to Webrev Comment