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

8297784: Optimize @Stable field for Method.isCallerSensitive #11422

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented Nov 29, 2022

JDK-8271820 introduced the @Stable private Boolean callerSensitive; cache in Method. That field is essentially a tri-state Boolean that relies on its null value to serve as "not initialized" value for @Stable.

This works well when the holder Method instance is constant: JIT compilers fold @Stable well. But if such folding fails, we always dereference the full-blown reference to "boxed" Boolean from the field on every access. We can instead do a more lean tri-state primitive field to improve that non-optimized case without sacrificing optimized case.

I chose byte and -1, 0, 1 to let the fastpath encode well on most (all?) architectures.

On adhoc benchmark like:

@State(Scope.Thread)
public class WrapperConstness {
    static final Method CONST;
    static Method NON_CONST;

    static {
        try {
            CONST = WrapperConstness.class.getDeclaredMethod("target");
            NON_CONST = CONST;
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    public void target() {}

    @Benchmark
    public void nonConstant() throws Exception {
        NON_CONST.invoke(this);
    }

    @Benchmark
    public void constant() throws Exception {
        CONST.invoke(this);
    }
}

We have a minor improvement for non-const case, confirmed due to better isCallerSensitive access:

Benchmark                     Mode  Cnt  Score   Error  Units

# Baseline
WrapperConstness.constant     avgt   25  0.410 ± 0.010  ns/op
WrapperConstness.nonConstant  avgt   25  7.283 ± 0.025  ns/op

# Patched
WrapperConstness.constant     avgt    5  0.407 ± 0.008  ns/op
WrapperConstness.nonConstant  avgt    5  7.054 ± 0.027  ns/op  ; -3%

Additional testing:

  • Ad-hoc benchmarks
  • Linux x86_64 fastdebug java/lang/reflect
  • Linux x86_64 fastdebug tier1, tier2

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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11422

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2022

👋 Welcome back shade! 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 openjdk bot added the rfr Pull request is ready for review label Nov 29, 2022
@openjdk
Copy link

openjdk bot commented Nov 29, 2022

@shipilev 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 Nov 29, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 29, 2022

Webrevs

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.

LGTM.

@openjdk
Copy link

openjdk bot commented Nov 29, 2022

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

8297784: Optimize @Stable field for Method.isCallerSensitive

Reviewed-by: redestad, jvernee, alanb

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

  • f05bfb1: 8297515: serialVersionUID fields are not annotated with @serial
  • 22f5d01: 8252584: HotSpot Style Guide should permit alignas
  • 8ffed34: 8297681: Unnecessary color conversion during 4BYTE_ABGR_PRE to INT_ARGB_PRE blit
  • abe532a: 8296924: C2: assert(is_valid_AArch64_address(dest.target())) failed: bad address
  • 5dcaf6c: 8297749: Remove duplicate space in the ProtocolException message being thrown from HttpURLConnection
  • c7a679f: 8297290: Use int indices to reference CDS archived primitive mirrors
  • 37f613b: 8297676: DataBuffer.TYPE_SHORT/TYPE_FLOAT/TYPE_DOUBLE are not placeholders
  • 87f00f4: 8296878: Document Filter attached to JPasswordField and setText("") is not cleared instead inserted characters replaced with unicode null characters
  • 9ced2ea: 8297311: Improve exception message thrown by java.net.HostPortrange::toLowerCase(String s)
  • defe060: 8296905: Replace the native LCMS#getProfileID() method with the accessor
  • ... and 10 more: https://git.openjdk.org/jdk/compare/69ede5baeda6645aa3e961a02cbd40db965fc6a1...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 openjdk bot added the ready Pull request is ready to be integrated label Nov 29, 2022
@shipilev
Copy link
Member Author

shipilev commented Dec 2, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 2, 2022

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

  • 11ba759: 8297992: Tests fail after JDK-8297215 due to lack of @enablePreview
  • b035056: 8297455: Use the official ToolProvider API to call javac
  • 257aa15: 8297444: Refactor the javacserver build tool
  • e846b04: 8297875: jar should not compress the manifest directory entry
  • 82031d3: 8297294: compiler/c2/irTests/TestMulNodeIdealization.java failed compilation
  • 337ca10: 8297978: Exclude vmTestbase/nsk/stress/except/except012.java until 8297977 is fixed
  • 770ff5a: 8297215: Update libs tests to use @enablePreview
  • c69aa42: 8297968: Crash in PrintOptoAssembly
  • 5a5ced3: 8297830: aarch64: Make Address a discriminated union internally
  • 391599b: 8297313: Refactor APIs for calculating address of CDS archive heap regions
  • ... and 63 more: https://git.openjdk.org/jdk/compare/69ede5baeda6645aa3e961a02cbd40db965fc6a1...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 2, 2022

@shipilev Pushed as commit 9bbcb54.

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

@shipilev shipilev deleted the JDK-8297784-method-callersensitive branch January 4, 2023 10:16
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
4 participants