-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
JDK-8311035: CDS should not use dump time JVM narrow Klass encoding to pre-compute Klass ids #14688
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
a8bd151
to
5211504
Compare
Hi Thomas, thanks for doing the clean up. I am not quite sure about the meaning of Since it's hard-coded to zero now, it's hard to observe how it would affect the calculation. Before Liliput: At dump time, all narrowKlass values are updated to be relative to At runtime, we always set jdk/src/hotspot/share/cds/metaspaceShared.cpp Line 1149 in 46e4ee1
Currently it's impossible to set an alternative
Also we will always have zero shifts, as we don't allow CompressedClassSpaceSize to be larger than 3G:
This means we can actually always use the archived Java objects, and this "if" block can be turned into an assert
I think for the current implementation, we might as well get rid of these fields in filemap.hpp.
Having them there will create more confusion. They may be useful for the future, but it's hard to understand how these fields would be used without implementing the "future" :-) |
Hi @iklam, thanks a lot for looking at this!
You missed a hunk without this patch makes no sense :) I added a new function, We call I introduce this new function to remove CDS-specific paths from About the "delta" constant: Its point was to codify the knowledge that the pre-computed encoding is calculated such that the future encoding base must be the same as the future mapping address (hence the 0). I'm fine with removing the constant though and replacing it with clear comments.
I agree. We still could fail, but not here, and here we cannot deal with it. We could still fail later if we mapped somewhere inconvenient due to ASLR, and the resulting Klass range start could not be used as an encoding base. That only can happen on Arm64 today. Today, we then assert, and this patch carries that assert over (at the start of the new As part of my Lilliput work, I also tackle that one. The JVM will then fall back to try a different base address and be smarter about it too. Then, as you have suggested offline, we could go and recompute the narrow Klass ids.
I agree. Cheers, Thomas |
- remove ArchiveHeapWriter::precomputed_narrow_klass_base_delta and replaced it with clear comments - changed runtime fail condition to asserts in FileMapInfo::can_use_heap_region()
@tstuefe this pull request can not be integrated into git checkout fix-cleanup-CDS-nKlass-encoding
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
@iklam : I removed the "delta" constant and replaced it with hopefully clear comments. I also removed the narrow_klass_xxx fields from FileMap. And translated runtime fail conditions to asserts in FileMapInfo::can_use_heap_region(). |
x86 test error unrelated. |
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.
Looks reasonable to me. This is a nice clean up. Just a few nits.
@tstuefe 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 6 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Thanks @iklam ! |
Could I have a second review, please? @ashu-mehra, maybe? |
const size_t encoding_range_size = nth_bit(narrow_klasspointer_bits + requested_shift); | ||
address encoding_range_end = requested_base + encoding_range_size; | ||
|
||
assert(requested_base <= addr && encoding_range_end >= end, "Encoding does not cover the full Klass range"); |
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.
Is it possible for requested_base
to ever be less than addr
?
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.
Not at the moment, no. Probably never. I separated those two mainly for cleanliness, since Klass range and encoding range are different things.
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 am fine having them separately but that assert condition forced me to think if requested_base can ever be less than addr. If not, then I guess assert for requested_base == addr
?
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.
Sure, makes sense.
Thanks for the changes. lgtm! |
Thanks @iklam and @ashu-mehra ! /integrate |
Going to push as commit 0616648.
Your commit was automatically rebased without conflicts. |
I recently spent too much time trying to understand the interleaving of narrow Klass decoding with CDS. Thanks to @iklam for clarifying some details. This patch aims to make the code easier to understand and more correct.
(2023-07-05 Updated to fit patch description to the agreed final form)
CDS narrow Klass handling plays a role for archived heap objects.
When dumping heap objects, we must recompute their narrow Klass ids since the relative positions of archived Klass instances change compared to their live counterparts in the dump time JVM.
We recompute those narrow Klass ids using the following encoding scheme:
see
ArchiveHeapWriter::update_header_for_requested_obj
jdk/src/hotspot/share/cds/archiveHeapWriter.cpp
Lines 419 to 425 in c3f10e8
At CDS runtime, we load the CDS archive, then place the class space behind it. We then initialize narrow Klass encoding for the resulting combined Klass range such that:
see
CompressedKlassPointers::initialize
:jdk/src/hotspot/share/oops/compressedOops.cpp
Lines 195 to 231 in c3f10e8
The lengthy comment there is misleading and partly wrong (regrettable since it was mine :)
At dump time, when initializing the JVM, we also set the encoding base to klass range start and shift to zero (also
CompressedKlassPointers::initialize
). That is the shift we later use for (A); hence, that shift is zero.There are minor things wrong with the current code. Mainly, the dump time VM's narrow Klass encoding scheme is irrelevant for the encoding employed on the future runtime archive since we recalculate the narrow Klass ids for archived heap objects. That means:
In
CompressedKlassPointers::initialize
, there is no need to fix the encoding base and shift for the dump time JVM. Dump time JVM can use whatever base+shift it pleases; it can use the same code path as when CDS is off (e.g. use zero-based encoding).In
ArchiveHeapWriter::update_header_for_requested_obj
, we should not use the dump time JVM shift for pre-computing the narrow Klass ids. Instead, we should use the minimal shift needed for the maximal possible future Klass range size. The comment in ArchiveHeapWriter explains this in greater detail. Thankfully, that minimal shift is zero in today's hotspot (but Lilliput may change that).Similarly, we should not save the dump time JVMs encoding shift as the "narrow Klass shift" into the archive but the one we use for pre-computing the narrow Klass ids.
The patch makes the encoding scheme used for precomputing klass ids explicit and obvious. It introduces a new constant,
ArchiveHeapWriter::precomputed_narrow_klass_shift
, that holds the shift used to encode nKlass Ids (for the current hotspot, it is null). (A companion constant for the precomputed base makes little sense since the archive can be mapped everywhere; the only condition for using the precomputed narrow Klass Ids is to set the runtime base to the mapping start; I considered encoding this in a "delta" constant but Ioi convinced me otherwise).I removed the "narrow_klass_" data holders from FileMap.
The only functional change is the fact that at dumptime, the JVM now is free to choose its base+shift for its own JVM. Encoding at runtime and for CDS=off does not change.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14688/head:pull/14688
$ git checkout pull/14688
Update a local copy of the PR:
$ git checkout pull/14688
$ git pull https://git.openjdk.org/jdk.git pull/14688/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14688
View PR using the GUI difftool:
$ git pr show -t 14688
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14688.diff
Webrev
Link to Webrev Comment