jdk
jdk copied to clipboard
8305895: Implement JEP 450: Compact Object Headers (Experimental)
This is the main body of the JEP 450: Compact Object Headers (Experimental).
It is also a follow-up to #20640, which now also includes (and supersedes) #20603 and #20605, plus the Tiny Class-Pointers parts that have been previously missing.
Main changes:
- Introduction of the (experimental) flag UseCompactObjectHeaders. All changes in this PR are protected by this flag. The purpose of the flag is to provide a fallback, in case that users unexpectedly observe problems with the new implementation. The intention is that this flag will remain experimental and opt-in for at least one release, then make it on-by-default and diagnostic (?), and eventually deprecate and obsolete it. However, there are a few unknowns in that plan, specifically, we may want to further improve compact headers to 4 bytes, we are planning to enhance the Klass* encoding to support virtually unlimited number of Klasses, at which point we could also obsolete UseCompressedClassPointers.
- The compressed Klass* can now be stored in the mark-word of objects. In order to be able to do this, we are add some changes to GC forwarding (see below) to protect the relevant (upper 22) bits of the mark-word. Significant parts of this PR deal with loading the compressed Klass* from the mark-word. This PR also changes some code paths (mostly in GCs) to be more careful when accessing Klass* (or mark-word or size) to be able to fetch it from the forwardee in case the object is forwarded.
- Self-forwarding in GCs (which is used to deal with promotion failure) now uses a bit to indicate 'self-forwarding'. This is needed to preserve the crucial Klass* bits in the header. This also allows to get rid of preserved-header machinery in SerialGC and G1 (Parallel GC abuses preserved-marks to also find all other relevant oops).
- Full GC forwarding now uses an encoding similar to compressed-oops. We have 40 bits for that, and can encode up to 8TB of heap. When exceeding 8TB, we turn off UseCompressedClassPointers (except in ZGC, which doesn't use the GC forwarding at all).
- Instances can now have their base-offset (the offset where the field layouter starts to place fields) at offset 8 (instead of 12 or 16).
- Arrays will now store their length at offset 8.
- CDS can now write and read archives with the compressed header. However, it is not possible to read an archive that has been written with an opposite setting of UseCompactObjectHeaders. Some build machinery is added so that _coh variants of CDS archives are generated, next to the _nocoops variant.
- Note that oopDesc::klass_offset_in_bytes() is not used by +UCOH paths anymore. The only exception is C2, which uses it as a placeholder/identifier of the special memory slice that only LoadNKlass uses. The backend then extracts the original oop and loads its mark-word and extracts the narrow-Klass* from that. I played with other approaches to implement LoadNKlass. Expanding it as a macro did not easily work, because C2 is missing a way to cast a word-sized integral to a narrow-Klass* (or at least I could not find it), and also I fear that doing so could mess with optimizations. This may be useful to revisit. OTOH, the approach that I have taken works and is similar to DecodeNKlass and similar instructions.
Testing: (+UseCompactObjectHeaders tests are run with the flag hard-patched into the build, to also catch @flagless tests.) The below testing has been run many times, but not with this exact base version of the JDK. I want to hold off the full testing until we also have the Tiny Class-Pointers PR lined-up, and test with that.
- [ ] tier1 (x86_64)
- [ ] tier2 (x86_64)
- [ ] tier3 (x86_64)
- [ ] tier4 (x86_64)
- [ ] tier1 (aarch64)
- [ ] tier2 (aarch64)
- [ ] tier3 (aarch64)
- [ ] tier4 (aarch64)
- [x] tier1 (x86_64) +UseCompactObjectHeaders
- [x] tier2 (x86_64) +UseCompactObjectHeaders
- [x] tier3 (x86_64) +UseCompactObjectHeaders
- [x] tier4 (x86_64) +UseCompactObjectHeaders
- [x] tier1 (aarch64) +UseCompactObjectHeaders
- [x] tier2 (aarch64) +UseCompactObjectHeaders
- [x] tier3 (aarch64) +UseCompactObjectHeaders
- [x] tier4 (aarch64) +UseCompactObjectHeaders
- [x] Running as a backport in production since >1 year.
Progress
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
- [ ] Change requires a JEP request to be targeted
- [ ] Change must be properly reviewed (3 reviews required, with at least 1 Reviewer, 2 Authors)
Issues
- JDK-8305895: Implement JEP 450: Compact Object Headers (Experimental) (Enhancement - P4)
- JDK-8294992: JEP 450: Compact Object Headers (Experimental) (JEP)
- JDK-8306000: Add experimental -XX:+UseCompactObjectHeaders flag (CSR) (Withdrawn)
Reviewers
- Magnus Ihse Bursie (@magicus - Reviewer) π Re-review required (review applies to 1b907cc8)
- Thomas Schatzl (@tschatzl - Reviewer) π Re-review required (review applies to 1b907cc8)
- Coleen Phillimore (@coleenp - Reviewer) π Re-review required (review applies to ec42f4d6)
- Stefan Karlsson (@stefank - Reviewer) π Re-review required (review applies to 4035bb61)
- Matias Saavedra Silva (@matias9927 - Reviewer) π Re-review required (review applies to 0d8a9236)
- Roberto CastaΓ±eda Lozano (@robcasloz - Reviewer) π Re-review required (review applies to b289ef88)
- @vpaprotsk (no known openjdk.org user name / role) π Re-review required (review applies to e4c08780)
- Yudi Zheng (@mur47x111 - Committer) π Re-review required (review applies to 1b907cc8)
- Erik Gahlin (@egahlin - Reviewer)
Contributors
- Sandhya Viswanathan
<[email protected]>
- Martin Doerr
<[email protected]>
- Hamlin Li
<[email protected]>
- Thomas Stuefe
<[email protected]>
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20677/head:pull/20677
$ git checkout pull/20677
Update a local copy of the PR:
$ git checkout pull/20677
$ git pull https://git.openjdk.org/jdk.git pull/20677/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20677
View PR using the GUI difftool:
$ git pr show -t 20677
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20677.diff