-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8341141: Optimize DirectCodeBuilder #21243
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 swen! A progress list of the required criteria for merging this PR into |
@wenshao 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 35 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 |
Webrevs
|
src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/classfile/impl/BufWriterImpl.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
Outdated
Show resolved
Hide resolved
Reviewed-by: jjg
Reviewed-by: lancea, eirbjo
…racter literals Reviewed-by: mcimadamore
Reviewed-by: azafari, yan, gziemski
Reviewed-by: mr, jwaters, erikj
…mitDirectMemory.java to problem list Reviewed-by: liach, dcubed, alanb
…no test coverage Reviewed-by: lancea
Reviewed-by: prr
…osx-all Reviewed-by: liach, alanb, darcy, dfuchs
…ad of AtomicInteger Reviewed-by: jrose, redestad, shade
…dles.Lookup Reviewed-by: redestad
Reviewed-by: shade, kvn
Reviewed-by: dnguyen, prr
… thread safe Reviewed-by: liach, shade, jvernee
Reviewed-by: asotona
I took this for a spin and results looks promising. Even a tentative win on the Write.jdkTree microbenchmark. The number of changes is a bit staggering so will take a while to thoroughly review in detail. I might be able to get through it all tomorrow. |
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.
Everything else looks good.
src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java
Outdated
Show resolved
Hide resolved
return this; | ||
} | ||
|
||
@Override | ||
public CodeBuilder aload(int slot) { | ||
writeLocalVar(BytecodeHelpers.aload(slot), slot); | ||
if (slot >= 0 && slot <= 3) { |
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.
Should we use if ((slot & ~3) != 0)
for shorter bytecode? #21367
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.
While fun, I wonder if such bit-fiddling optimizations obfuscate the code more than it helps performance. Would be good with some supporting evidence that it 1) helps interpreted performance and 2) that all JITs recognize and optimize this pattern well and without surprises.
if (slot < 256) { | ||
bytecodesBufWriter.writeU1U1(bytecode, slot); | ||
} else { | ||
bytecodesBufWriter.writeU1U1U2(WIDE, bytecode, slot); | ||
} |
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.
Can we do:
if ((slot & ~0xFF) == 0)
bytecodesBufWriter.writeU1U1(bytecode, slot);
else if ((slot & ~0xFFFF) == 0)
bytecodesBufWriter.writeU1U1U2(WIDE, bytecode, slot);
else
throw BytecodeHelpers.slotOutOfBounds(slot);
/contributor add redestad |
/contributor add liach |
@wenshao |
@wenshao |
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.
LGTM.
I spotted places outside of the DirectCodeBuilder paths that could benefit from using these new coalescing writers, but write-only cases is a good focus point for now.
} else { | ||
bytecodesBufWriter.writeU1(value); | ||
bytecodesBufWriter.writeU1U1(opcode.bytecode(), value); | ||
} | ||
} | ||
|
||
public void writeLoadConstant(Opcode opcode, LoadableConstantEntry value) { | ||
// Make sure Long and Double have LDC2_W and | ||
// rewrite to _W if index is > 256 |
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.
Pre-existing..
- Comment should say >= 256.
- As we're cloning from a pre-existing pool I assume there's a (perhaps unlikely) possibility we go from a wide to a lower index? In that case the opcode could profitably be "rewritten" to
Opcode.LDC
in an else clause. (I assumeLDC_W
with an index in the 0-255 range works fine functionally; it just wastes a byte.)
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.
Indeed, the opcode here is pointless if we have a pool adaption; in that case we should just use ldc(LoadableConstantEntry)
.
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 in writeLoadConstant, some branches have curly braces, and some don't. The style is inconsistent. Should I change it?
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 think we can do it in a later cleanup that fixes writeLoadConstant. This patch is already huge.
Are you talking about merging multiple writeU2 in places like AbstractAttributeMapper? I am planning to make a new PR to complete these works, because this PR has too many changes. |
Good. I would have suggested the same. |
/integrate |
Going to push as commit 047c2d7.
Your commit was automatically rebased without conflicts. |
Some DirectCodeBuilder related optimizations to improve startup and running performance:
Progress
Issue
Reviewers
Contributors
<redestad@openjdk.org>
<liach@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21243/head:pull/21243
$ git checkout pull/21243
Update a local copy of the PR:
$ git checkout pull/21243
$ git pull https://git.openjdk.org/jdk.git pull/21243/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21243
View PR using the GUI difftool:
$ git pr show -t 21243
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21243.diff
Webrev
Link to Webrev Comment