Skip to content

8339576: Speed up raw bytecode processing in ClassFile API #20863

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

Closed
wants to merge 9 commits into from

Conversation

liach
Copy link
Member

@liach liach commented Sep 4, 2024

Currently, raw bytecode access goes through multiple wrappers, include one from ClassFile API and another ByteBuffer for merged big endian value reads. We can merge the ByteBuffer =into the ClassFile API one (RawBytecodeHelper) for safer access.

RawBytecodeHelper is also restructured so we avoid allocating it on the heap. Large rawNext method is now also inlined into the smaller next method.

Current benchmark results show this significantly speeds up jdk.classfile.Write and some degree of speedup for simple lambda startup. The impact on general application workloads is minuscule, but this doesn't seem to bring any regression.

Pinging @wenshao and @cl4es for review.


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-8339576: Speed up raw bytecode processing in ClassFile API (Sub-task - P4)

Reviewers

Contributors

  • Shaojin Wen <swen@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20863

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

Using diff file

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

Webrev

Link to Webrev Comment

@liach
Copy link
Member Author

liach commented Sep 4, 2024

/contributor add swen

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 4, 2024

👋 Welcome back liach! 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 4, 2024

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

8339576: Speed up raw bytecode processing in ClassFile API

Co-authored-by: Shaojin Wen <swen@openjdk.org>
Reviewed-by: asotona, redestad

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 24 new commits pushed to the master branch:

  • 7db4d46: 8330159: [C2] Remove or clarify Compile::init_start
  • 9e0ccb8: 8339548: GHA: RISC-V: Use Debian snapshot archive for bootstrap
  • 8fb8cd8: 8339347: keytool -importpass insists prompting the user even if there is no terminal
  • 9e1af8c: 8339285: Test fails with assert(depth < max_critical_stack_depth) failed: can't have more than 10 critical frames
  • 48d7943: 8339342: FieldAllocationCount is mostly unused
  • e203df4: 8338100: C2: assert(!n_loop->is_member(get_loop(lca))) failed: control must not be back in the loop
  • 98020e4: 8338133: Cleanup direct use of new HtmlTree
  • b895d7c: 8332423: [PPC64] Remove C1_MacroAssembler::call_c_with_frame_resize
  • 59c4649: 8329959: Update DigestMD5Client.java - fix typo in javadoc string
  • 4ffcf89: 8339619: ProblemList runtime/cds/appcds/jvmti/dumpingWithAgent/DumpingWithJavaAgent.java
  • ... and 14 more: https://git.openjdk.org/jdk/compare/1353601dcc8f9ec3e12dea21dc61b3585a154b13...master

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 master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Sep 4, 2024

@liach
Contributor Shaojin Wen <swen@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented Sep 4, 2024

@liach 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.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 4, 2024
@liach liach changed the title Speed up raw bytecode processing in ClassFile API 8339576: Speed up raw bytecode processing in ClassFile API Sep 5, 2024
@liach liach marked this pull request as ready for review September 5, 2024 04:46
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 5, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 5, 2024

Webrevs

* {@link #ILLEGAL}, so we can perform value access without bound checks if
* we have a valid opcode.
*/
public boolean next() {
Copy link
Contributor

Choose a reason for hiding this comment

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

In C1, this cannot be inlined. See if you need to add ForceInline

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should worry too much about making C1 inline more aggressively.

Copy link
Member Author

Choose a reason for hiding this comment

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

C2 needs 10000 calls to inline this method, so wenshao is worried. However, this method call is almost always followed by a huge switch to handle different opcode, so I doubt how much of a difference inlining brings.

But wenshao discovered that this method has too many field gets; I should indeed convert them to local variable access if possible.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, things like storing endBci() to a local variable can be great if it both reduces code size and improves interpreter/C1 speed - but don't over-do it as it's likely never-ending work for a kind of optimizations leyden might make pointless.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not necessary to use RawBytecodeHelper in the StackMapGenerator#detectFrameOffsets method. It may be better to operate directly on the byte[] bytecode.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could have just tracked the offsets when labels from DirectCodeBuilder are bound; we can explore such a fix in another patch.

Copy link
Member

@asotona asotona left a comment

Choose a reason for hiding this comment

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

From the Class-File API perspective the changes look good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 5, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 5, 2024
github-actions bot pushed a commit to dougxc/openjdk-pr-canary that referenced this pull request Sep 5, 2024
8339576: Speed up raw bytecode processing in ClassFile API
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 5, 2024
@liach liach requested a review from asotona September 5, 2024 17:53
@liach
Copy link
Member Author

liach commented Sep 6, 2024

Thanks for the reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Sep 6, 2024

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

  • a35fd38: 8339368: Switch targets are not inflated in CodeModel if no StackMap
  • 7db4d46: 8330159: [C2] Remove or clarify Compile::init_start
  • 9e0ccb8: 8339548: GHA: RISC-V: Use Debian snapshot archive for bootstrap
  • 8fb8cd8: 8339347: keytool -importpass insists prompting the user even if there is no terminal
  • 9e1af8c: 8339285: Test fails with assert(depth < max_critical_stack_depth) failed: can't have more than 10 critical frames
  • 48d7943: 8339342: FieldAllocationCount is mostly unused
  • e203df4: 8338100: C2: assert(!n_loop->is_member(get_loop(lca))) failed: control must not be back in the loop
  • 98020e4: 8338133: Cleanup direct use of new HtmlTree
  • b895d7c: 8332423: [PPC64] Remove C1_MacroAssembler::call_c_with_frame_resize
  • 59c4649: 8329959: Update DigestMD5Client.java - fix typo in javadoc string
  • ... and 15 more: https://git.openjdk.org/jdk/compare/1353601dcc8f9ec3e12dea21dc61b3585a154b13...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 6, 2024

@liach Pushed as commit a1eebbd.

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

@liach liach deleted the cf/bytebuf branch September 24, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants