Skip to content

Conversation

@asotona
Copy link
Member

@asotona asotona commented Jan 8, 2024

ClassFile API performance related improvements have been separated from #17121 into this PR.

These improvements are important to minimize performance regression of
8294961: Convert java.base/java.lang.reflect.ProxyGenerator to use the Classfile API to generate proxy classes #17121

Please review.

Thanks,
Adam


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-8323183: ClassFile API performance improvements (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17306

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 8, 2024

👋 Welcome back asotona! 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 Jan 8, 2024

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

@mlbridge
Copy link

mlbridge bot commented Jan 8, 2024

@liach
Copy link
Member

liach commented Jan 8, 2024

You need to update the slot counting from DirectCodeBuilder and StackMapDecoder to fully avoid creating any MethodTypeDesc.

@asotona
Copy link
Member Author

asotona commented Jan 8, 2024

You need to update the slot counting from DirectCodeBuilder and StackMapDecoder to fully avoid creating any MethodTypeDesc.

It would be good to avoid all bottlenecks, however not all of them have equal effect.
This patch avoids MTD construction for every invocation instruction. We may cache the symbol in the relevant Utf8Entry, however it still means to create each MTD at least once. "Hairy" methods doing a lot of various invocations are the most affected.

@asotona
Copy link
Member Author

asotona commented Jan 9, 2024

StackMapGenerator benchmark is heavily benefiting from symbols caching for repeated execution.
I've created new CodeAttributeTools::benchmarkStackMapsGenerator and CodeAttributeTools::benchmarkStackCounter with focus on single use of each parsed model to eliminate background caching effect.
Then I've compared version with custom method parameter slots counting and version with symbols cached in NaT entries.
There is insignificant difference between these two approaches.
Explanation may by that repeated uses of the same NaT entry (of the called method) compensate the initial parsing cost.

Based on these results I've decided to revert custom parameter slots counting method and apply the previously proposed solution by @liach .

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 12, 2024

@asotona This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@asotona
Copy link
Member Author

asotona commented Mar 4, 2024

Please review.

Thank you!

Copy link
Member

@cl4es cl4es left a comment

Choose a reason for hiding this comment

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

Improvement looks good, but the microbenchmark needs to sink new instances into a blackhole to make sure we measure the right thing.

import java.lang.classfile.constantpool.DynamicConstantPoolEntry;
import java.lang.classfile.constantpool.MemberRefEntry;
import static java.lang.classfile.ClassFile.*;
import java.lang.constant.MethodTypeDesc;
Copy link
Member

Choose a reason for hiding this comment

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

Imports are strangely out-of-order and imports in the classfile package look haphazard. Is there some system to it that I don't see? I don't know if we have an applicable style guide to lean on, but alphabetically sorted and static imports split out at the end seem like the convention in the OpenJDK sources.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks.

this.methodDesc = methodDesc;
this.cp = cp;
map = new LinkedHashMap<>();
targets = new ArrayDeque<>();
Copy link
Member

Choose a reason for hiding this comment

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

Seeing ArrayDeque being put to good use always makes me happy.

Comment on lines 107 to 108
public void benchmarkStackMapsGenerator() {
for (var d : data) new StackMapGenerator(
Copy link
Member

@cl4es cl4es Mar 4, 2024

Choose a reason for hiding this comment

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

When we return something from a benchmark JMH makes sure to sink that something into a blackhole to avoid JIT assuming the result is unused and eliminating it, wholly or in parts. When it's impractical to return a single thing that captures all the computation in the benchmark it's good practice to let a org.openjdk.jmh.infra.Blackhole consume effects to attain the same effect:

    public void benchmarkStackMapsGenerator(Blackhole bh) {
        for (var d : data) bh.consume(new StackMapGenerator(

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks.

@openjdk
Copy link

openjdk bot commented Mar 4, 2024

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

8323183: ClassFile API performance improvements

Reviewed-by: 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 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 openjdk bot added the ready Pull request is ready to be integrated label Mar 4, 2024
@asotona
Copy link
Member Author

asotona commented Mar 4, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Mar 4, 2024

Going to push as commit 0583f73.
Since your change was applied there has been 1 commit pushed to the master branch:

  • b69d1b5: 8327042: G1: Parallelism used for redirty logged cards needs better control.

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 4, 2024

@asotona Pushed as commit 0583f73.

💡 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.

5 participants