Skip to content

Conversation

@cl4es
Copy link
Member

@cl4es cl4es commented Apr 29, 2024

I'm looking at ways at reducing/eliminating startup overheads the classfile API in preparation of #17108, and have pushed a series of enhancements to that effect already. This PR is a collection of minor improvements which add up to a 1.5% reduction in retired instructions - or a 5% reduction in executed bytecode - on a simple lambda startup test.


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-8331264: Reduce java.lang.constant initialization overhead (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18991

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 29, 2024

👋 Welcome back redestad! 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 Apr 29, 2024

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

8331264: Reduce java.lang.constant initialization overhead

Reviewed-by: liach, mchung

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

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 openjdk bot added the rfr Pull request is ready for review label Apr 29, 2024
@openjdk
Copy link

openjdk bot commented Apr 29, 2024

@cl4es 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 Apr 29, 2024
@mlbridge
Copy link

mlbridge bot commented Apr 29, 2024

Webrevs


for (ClassDesc cd : trustedArgTypes)
if (cd.isPrimitive() && cd.descriptorString().charAt(0) == 'V') // implicit null check
if (cd.descriptorString().equals("V")) // implicit null check
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, is equals faster than charAt(0) == for single-char strings?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've not benchmarked this detail in JMH, only verified it does less work when interpreted. We could probably just drop cd.isPrimitive() &&, though, since a descriptor of length > 1 starting with V can't be created.

ConstantDescs.CD_MethodHandles_Lookup,
ConstantDescs.CD_String,
ConstantDescs.CD_MethodType};
CD_MethodHandles_Lookup,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these fields be @stable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it'd hurt, but I would be surprised if any of these would be hot enough to see a benefit from that.

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 this really helps; the array elements are not used directly via field reference.

Copy link
Member

@mlchung mlchung left a comment

Choose a reason for hiding this comment

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

The changes look good to me but I wonder if the non-zero length check before calling arraycopy really needed? That seems to add some noise to the code.

@cl4es
Copy link
Member Author

cl4es commented Apr 29, 2024

The changes look good to me but I wonder if the non-zero length check before calling arraycopy really needed? That seems to add some noise to the code.

I recall benchmarking similar code in MethodType extensively, and found that it had a small but significant impact, especially when adding or dropping parameters at the end or beginning of an argument list (which is the most common case). Adhoc JMH:

    @Benchmark
    public MethodTypeDesc dropFirstParameter() {
        return desc.dropParameterTypes(0, 1);
    }

Name                                                                   (descString) Cnt   Base   Error    Test   Error  Unit  Change
MethodTypeDescFactories.dropFirstParameter  (Ljava/lang/Object;Ljava/lang/String;)I   6 20,382 ± 0,635  16,116 ± 0,737 ns/op   1,26x (p = 0,000*)
MethodTypeDescFactories.dropFirstParameter ([IJLjava/lang/String;Z)Ljava/util/List;   6 26,875 ± 0,652  19,863 ± 0,749 ns/op   1,35x (p = 0,000*)
MethodTypeDescFactories.dropFirstParameter                                 (..IIJ)V   6 29,774 ± 0,983  20,747 ± 1,181 ns/op   1,44x (p = 0,000*)
MethodTypeDescFactories.dropFirstParameter                 (.....................).   6 33,224 ± 0,939  30,350 ± 1,739 ns/op   1,09x (p = 0,000*)
  * = significant

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 30, 2024
@cl4es
Copy link
Member Author

cl4es commented Apr 30, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Apr 30, 2024

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Apr 30, 2024

@cl4es Pushed as commit 0630bb0.

💡 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 core-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants