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

8255299: Drop explicit zeroing at instantiation of Atomic* objects #818

Closed
wants to merge 1 commit into from

Conversation

stsypanov
Copy link
Contributor

@stsypanov stsypanov commented Oct 22, 2020

As discussed in #510 there is never a reason to explicitly instantiate any instance of Atomic* class with its default value, i.e. new AtomicInteger(0) could be replaced with new AtomicInteger() which is faster:

@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(value = Mode.AverageTime)
public class AtomicBenchmark {
  @Benchmark
  public Object defaultValue() {
    return new AtomicInteger();
  }
  @Benchmark
  public Object explicitValue() {
    return new AtomicInteger(0);
  }
}

THis benchmark demonstrates that explicitValue() is much slower:

Benchmark                      Mode  Cnt   Score   Error  Units
AtomicBenchmark.defaultValue   avgt   30   4.778 ± 0.403  ns/op
AtomicBenchmark.explicitValue  avgt   30  11.846 ± 0.273  ns/op

So meanwhile https://bugs.openjdk.java.net/browse/JDK-8145948 is still in progress we could trivially replace explicit zeroing with default constructors gaining some performance benefit with no risk.

I've tested the changes locally, both tier1 and tier 2 are ok.

Could one create an issue for tracking this?


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Testing

Linux x64 Linux x86 Windows x64 macOS x64
Build ✔️ (5/5 passed) ✔️ (2/2 passed) ✔️ (2/2 passed) ✔️ (2/2 passed)
Test (tier1) ✔️ (9/9 passed) ✔️ (9/9 passed) ✔️ (9/9 passed) ✔️ (9/9 passed)

Issue

  • JDK-8255299: Drop explicit zeroing at instantiation of Atomic* objects

Reviewers

  • Claes Redestad (@cl4es - Reviewer) ⚠️ Review applies to c1fb362f6d2f4c099c05ef606daf881ebde475de
  • Sergey Bylokhov (@mrserb - Reviewer) ⚠️ Review applies to c1fb362f6d2f4c099c05ef606daf881ebde475de
  • Phil Race (@prrace - Reviewer) ⚠️ Review applies to c1fb362f6d2f4c099c05ef606daf881ebde475de

Download

$ git fetch https://git.openjdk.java.net/jdk pull/818/head:pull/818
$ git checkout pull/818

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 22, 2020

👋 Welcome back stsypanov! 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 Oct 22, 2020

@stsypanov The following labels will be automatically applied to this pull request:

  • awt
  • core-libs
  • hotspot
  • net
  • security
  • swing

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added swing client-libs-dev@openjdk.org security security-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org awt client-libs-dev@openjdk.org labels Oct 22, 2020
@cl4es
Copy link
Member

cl4es commented Oct 23, 2020

Filed 8255299 for this. Prefix the name of the PR with "8255299: " and it should pass checks.

@stsypanov stsypanov changed the title Drop explicit zeroing at instantiation of Atomic* objects 8255299: Drop explicit zeroing at instantiation of Atomic* objects Oct 23, 2020
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 23, 2020
@mlbridge
Copy link

mlbridge bot commented Oct 23, 2020

Webrevs

@openjdk
Copy link

openjdk bot commented Oct 23, 2020

⚠️ @stsypanov the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout atom-simpl
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Oct 23, 2020

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

8255299: Drop explicit zeroing at instantiation of Atomic* objects

Reviewed-by: redestad, serb, prr

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

  • 591e7e2: 8255378: [Vector API] Remove redundant vector length check after JDK-8254814 and JDK-8255210
  • 2c9dfc7: 8255234: ZGC: Bulk allocate forwarding data structures
  • b7d483c: 8255245: C1: Fix output of -XX:+PrintCFGToFile to open it with visualizer
  • 5e0a8cd: 8255488: Re-enable some problem listed tests

Please see this link for an up-to-date comparison between the source branch of this pull request and 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@cl4es, @mrserb, @prrace) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 23, 2020
Copy link
Member

@mrserb mrserb 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 in src/java.desktop looks fine.

@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 23, 2020
@openjdk
Copy link

openjdk bot commented Oct 23, 2020

@stsypanov
Your change (at version c1fb362f6d2f4c099c05ef606daf881ebde475de) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Oct 23, 2020

Changes to java.logging and java.net.http also look good to me.

@dfuch
Copy link
Member

dfuch commented Oct 23, 2020

Hi Sergey,

I'll give it some testing and sponsor it next week unless someone else steps up.

best regards,
-- daniel

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

client changes are fine

@stsypanov
Copy link
Contributor Author

Rebased onto master to have the fix introduced in #778

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Oct 28, 2020
@mrserb
Copy link
Member

mrserb commented Oct 28, 2020

FYI it is better to use merge, instead of rebase+force push. Rebase breaks history and all existed code comments.

@stsypanov
Copy link
Contributor Author

@mrserb thanks for pointing this out!

@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 28, 2020
@openjdk
Copy link

openjdk bot commented Oct 28, 2020

@stsypanov
Your change (at version 7dc646d) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Oct 28, 2020

Thanks for updating with latest master changes Sergey! My tests were all green.
/sponsor

@openjdk openjdk bot closed this Oct 28, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 28, 2020
@openjdk
Copy link

openjdk bot commented Oct 28, 2020

@dfuch @stsypanov Since your change was applied there have been 5 commits pushed to the master branch:

  • 6b2d11b: 8255246: AArch64: Implement BigInteger shiftRight and shiftLeft accelerator/intrinsic
  • 591e7e2: 8255378: [Vector API] Remove redundant vector length check after JDK-8254814 and JDK-8255210
  • 2c9dfc7: 8255234: ZGC: Bulk allocate forwarding data structures
  • b7d483c: 8255245: C1: Fix output of -XX:+PrintCFGToFile to open it with visualizer
  • 5e0a8cd: 8255488: Re-enable some problem listed tests

Your commit was automatically rebased without conflicts.

Pushed as commit 3c4fc79.

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

@stsypanov stsypanov deleted the atom-simpl branch October 28, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awt client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated net net-dev@openjdk.org security security-dev@openjdk.org swing client-libs-dev@openjdk.org
5 participants