-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8315082: [REDO] Generational ZGC: Tests crash with assert(index == 0 || is_power_of_2(index)) #15589
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
Conversation
👋 Welcome back rcastanedalo! A progress list of the required criteria for merging this PR into |
@robcasloz The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
/contributor add @stefank |
/contributor add @fisk |
/label add hotspot-compiler |
/label add hotspot-gc |
@robcasloz |
@robcasloz |
@robcasloz |
@robcasloz |
b703e12
to
b3109e3
Compare
@albertnetymk @vnkozlov @TobiHartmann could you please review this revised version of JDK-8312749? The core changes remain identical, the only additional changes are an assertion relaxation and a second regression test (see description for details). Thanks! |
@robcasloz 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 205 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 |
Thanks for reviewing, Albert! |
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.
Thanks for the detailed analysis and explanation. The fix looks good.
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.
Few comments.
if (is_array) { | ||
// Ensure the array payload size is rounded up to the next BytesPerLong | ||
// multiple when converting to double-words. This is necessary because array | ||
// size does not include object alignment padding, so it might not be a | ||
// multiple of BytesPerLong for sub-long element types. | ||
payload_size = kit->gvn().transform(new AddXNode(payload_size, kit->MakeConX(BytesPerLong - 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.
Back to this change. Why rounding is only arrays? Do we have a check that object's alignment >= 8 bytes? If it less you may access beyond array.
Can Add
result overflow in 32-bit VM?
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.
Why rounding is only arrays?
Class instance (bytewise) size is already rounded to MinObjAlignmentInBytes
(i.e. it is a multiple of BytesPerLong
, assuming minimum object alignment of 8 bytes), so rounding it again would be a no-op.
Do we have a check that object's alignment >= 8 bytes? If it less you may access beyond array.
This code simply assumes that the minimum object alignment in HotSpot is 8 bytes, as per src/hotspot/share/runtime/globals.hpp
:
#ifdef _LP64
...
product(int, ObjectAlignmentInBytes, 8, \
"Default object alignment in bytes, 8 is minimum") \
range(8, 256) \
constraint(ObjectAlignmentInBytesConstraintFunc, AtParse)
...
#else
...
const int ObjectAlignmentInBytes = 8;
...
#endif
Is there any VM configuration where this might not hold? Or do I misunderstand your question?
Can
Add
result overflow in 32-bit VM?
payload_size + (BytesPerLong - 1)
cannot overflow because it is performed after a subtraction of a larger quantity (base_off
). Would it make sense to add an assertion like this?:
assert(base_off >= BytesPerLong - 1, "array payload size computation should not overflow");
} | ||
// else if round_mask == 0, the size computation is self-rounding | ||
Node* non_rounded_size = _gvn.transform(new AddXNode(headerx, abody)); |
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.
Here
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.
headerx + abody
cannot overflow because of the array length limit imposed by TypeAryPtr::max_array_length()
, which is designed to fit the total bytes of an array header and payload (including external alignment) in 32 bits (on 32-bits platforms). I checked this using the length limits for all basic types. Exceeding this limit causes the array allocation to throw a java.lang.OutOfMemoryError: Requested array size exceeds VM limit
exception).
Node* size = non_rounded_size; | ||
if (round_mask != 0) { | ||
Node* mask1 = MakeConX(round_mask); | ||
size = _gvn.transform(new AddXNode(size, mask1)); |
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.
and here again question about overflow in 32-bit VM.
Do we generate compare with FastAllocateSizeLimit before this code is executed?
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.
size + mask1
cannot overflow because, as you suggest, it is only computed in the fast allocation path (i.e. for small values of size
restricted by FastAllocateSizeLimit). The only way to bypass this check and indeed trigger the overflow is to set -XX:FastAllocateSizeLimit=2147483647
(debug-only flag), this causes indeed a segmentation fault, reported in JDK-8316512.
In general, the behavior of size computation within GraphKit::new_array
w.r.t. overflow is not altered by this changeset, as far as I can see, because it essentially only changes whether round_mask
is added to the header size (as done before) or to the total, non-rounded size (as proposed here).
Thanks for reviewing, Tobias! |
Thanks for reviewing, Vladimir! See my replies inlined for each comment/question. |
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.
Thank you for answering all my questions.
/integrate |
Going to push as commit ceff47b.
Your commit was automatically rebased without conflicts. |
@robcasloz Pushed as commit ceff47b. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This changeset (REDO of JDK-8312749) ensures that the array copy stub underlying the intrinsic implementation of
Object.clone
only copies its (double-word aligned) payload, excluding the remaining object alignment padding words, when a non-defaultObjectAlignmentInBytes
value is used. This prevents the specialized ZGC stubs forObject[]
array copy from processing undefined object alignment padding words as valid object pointers. For further details about the specific failure, see initial analysis of JDK-8312749 by Erik Österlund and Stefan Karlsson and comments intest/hotspot/jtreg/compiler/gcbarriers/TestArrayCopyWithLargeObjectAlignment.java
.As a side-benefit, the changeset simplifies the array size computation logic in
GraphKit::new_array()
by decoupling computation of header size and alignment padding size.Additional changes compared to JDK-8312749
This changeset proposes the exact same solution as JDK-8312749, that is, identical changes to
barrierSetC2.cpp
,graphKit.cpp
,library_call.cpp
, andTestArrayCopyWithLargeObjectAlignment.java
. On top of that, it relaxes an assertion in the idealization ofArrayCopy
nodes violated by JDK-8312749 and reported in JDK-8315029 (new changes inarraycopynode.cpp
, new regression testTestCloneArrayWithDifferentLengthConstness.java
). The original, stricter assertion checks that, while idealizing an ArrayCopy node, the "constness" of the array copy's word-length (whether it is known by C2 to be constant or not) is equivalent to that of the array copy's element-length. For cases in which the element-length is within a small, fixed range (e.g. for anint
array of length3..4
) so that all element-length values lead to the same number of words (2
), the assertion used to hold before this changeset only because of weak type propagation inAndL
(preventing the constant word-length to be discovered), see the left graph below:With the proposed changes, the array copy word-length is computed in a more straightforward way that enables C2 to infer the precise number of words in the same scenario (see the right graph above). To accommodate this optimization, this changeset relaxes the assertion to check only one direction of the implication (if the element-length is constant, so is the word-length). The optimization does not affect the remaining idealization code, since it only uses element-length in the context in which the optimization is applied.
The changeset includes an additional regression test (
TestCloneArrayWithDifferentLengthConstness.java
) that exercises different constant/variable combinations of element-length and word-length.Testing
Functionality
Performance
Tested performance on the following set of OpenJDK micro-benchmarks, on linux-x64 (for both G1 and ZGC, using different ObjectAlignmentInBytes values):
openjdk.bench.java.lang.ArrayClone.byteClone
openjdk.bench.java.lang.ArrayClone.intClone
openjdk.bench.java.lang.ArrayFiddle.simple_clone
openjdk.bench.java.lang.Clone.cloneLarge
openjdk.bench.java.lang.Clone.cloneThreeDifferent
No significant regression was observed.
Progress
Issue
Reviewers
Contributors
<stefank@openjdk.org>
<eosterlund@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15589/head:pull/15589
$ git checkout pull/15589
Update a local copy of the PR:
$ git checkout pull/15589
$ git pull https://git.openjdk.org/jdk.git pull/15589/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15589
View PR using the GUI difftool:
$ git pr show -t 15589
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15589.diff
Webrev
Link to Webrev Comment