Skip to content
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

8340710: Optimize DirectClassBuilder::build #21118

Closed
wants to merge 10 commits into from

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented Sep 22, 2024

Do some refactoring so that the code can be inlined by the C1/C2 optimizer.

  1. DirectClassBuilder::build codeSize 361 -> 319
  2. DirectCodeBuilder::writeExceptionHandlers codeSize 183 -> 31
  3. BufWriterImpl::writeIndex codeSize 62 -> 37 (forceinline)
  4. BufWriterImpl::writeU2 (forceinline)
  5. Util::writeAttributes codSize 45 -> 40 (forceinline)
  6. Util::writeList codSize 47 -> 42 (forceinline)

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8340710: Optimize DirectClassBuilder::build (Sub-task - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21118/head:pull/21118
$ git checkout pull/21118

Update a local copy of the PR:
$ git checkout pull/21118
$ git pull https://git.openjdk.org/jdk.git pull/21118/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21118

View PR using the GUI difftool:
$ git pr show -t 21118

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21118.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 22, 2024

👋 Welcome back swen! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 22, 2024

@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:

8340710: Optimize DirectClassBuilder::build

Reviewed-by: liach

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Sep 22, 2024

@wenshao The following label will be automatically applied to this pull request:

  • core-libs

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.

@wenshao wenshao marked this pull request as draft September 22, 2024 09:11
@wenshao wenshao marked this pull request as ready for review September 22, 2024 11:12
writeAttribute(buf, e);
int size = list.size();
buf.writeU2(size);
for (int i = 0; i < size; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Manual loop unrolling is good for startup

head.writeInt(ClassFile.MAGIC_NUMBER);
head.writeU2(minorVersion);
head.writeU2(majorVersion);
head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | minorVersion << 16 | majorVersion);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minorVersion needs to be cast to a long first, as otherwise when the MSB is set after the shift, then it’ll overwrite the magic number with all 1s.

Suggested change
head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | minorVersion << 16 | majorVersion);
head.writeLong(((long) ClassFile.MAGIC_NUMBER) << 32 | ((long) minorVersion) << 16 | majorVersion);

Copy link
Member

@liach liach Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, I think using Integer.toUnsignedLong on the shift result is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If minorVersion > 0xFFFF, the result of using Integer.toUnsignedLong will be wrong. I guess this is the reason why the previous version build failed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a & 0xFFFF on majorVersion to defend against majorVersion > 0xFFFF too?

@@ -94,6 +96,10 @@ public ClassFileImpl context() {
return context;
}

void writeMagic(int minorVersion, int majorVersion) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this writeHeader as this writes both the magic and the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, through the local variable constantPool, codeSize < 325 can be achieved without extracting a separate method.

@wenshao wenshao requested a review from liach September 23, 2024 14:06
@wenshao wenshao changed the title Optimize DirectClassBuilder::build 8340710: Optimize DirectClassBuilder::build Sep 24, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 24, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 24, 2024

Webrevs

head.writeInt(ClassFile.MAGIC_NUMBER);
head.writeU2(minorVersion);
head.writeU2(majorVersion);
head.writeLong((((long) ClassFile.MAGIC_NUMBER) << 32) | ((minorVersion & 0xFFFFL) << 16) | majorVersion);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
head.writeLong((((long) ClassFile.MAGIC_NUMBER) << 32) | ((minorVersion & 0xFFFFL) << 16) | majorVersion);
head.writeLong((((long) ClassFile.MAGIC_NUMBER) << 32) | ((minorVersion & 0xFFFFL) << 16) | (majorVersion & 0xFFFFL));

@openjdk
Copy link

openjdk bot commented Sep 24, 2024

@wenshao this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout optim_classfile_build_202409
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

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Sep 24, 2024
…uild_202409

# Conflicts:
#	src/java.base/share/classes/jdk/internal/classfile/impl/Util.java
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Sep 24, 2024
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 24, 2024
@wenshao
Copy link
Contributor Author

wenshao commented Sep 25, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Sep 25, 2024

Going to push as commit 2e0554a.
Since your change was applied there have been 9 commits pushed to the master branch:

  • 2d38af6: 8340587: Optimize StackMapGenerator$Frame::checkAssignableTo
  • 9bcc7b6: 8340708: Optimize StackMapGenerator::processMethod
  • a37bb2e: 8340643: RISC-V: Small refactoring for sub/subw macro-assembler routines
  • c0fcb25: 8340717: Remove unused function declarations from java.c/java.h of the launcher
  • 0b8c9f6: 8338525: Leading and trailing code blocks by indentation
  • b639661: 8340804: doc/building.md update Xcode instructions to note that full install is required
  • e3d80f1: 8340670: Policy.UNSUPPORTED_EMPTY_COLLECTION.isReadOnly does not return true
  • 8c08c43: 8340433: Open source closed choice tests optimization algorithm:tableSizeFor #3
  • 90c2c0b: 8340143: Open source several Java2D rendering loop tests.

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 25, 2024
@openjdk openjdk bot closed this Sep 25, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 25, 2024
@openjdk
Copy link

openjdk bot commented Sep 25, 2024

@wenshao Pushed as commit 2e0554a.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants