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

Loading

@openjdk
Copy link

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

Loading

@cl4es
Copy link
Member

@cl4es cl4es commented Oct 23, 2020

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

Loading

@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 label Oct 23, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Oct 23, 2020

Webrevs

Loading

cl4es
cl4es approved these changes Oct 23, 2020
@openjdk
Copy link

@openjdk 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

Loading

@openjdk
Copy link

@openjdk 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).

Loading

@openjdk openjdk bot added the ready label Oct 23, 2020
mrserb
mrserb approved these changes Oct 23, 2020
Copy link
Member

@mrserb mrserb left a comment

The changes in src/java.desktop looks fine.

Loading

@stsypanov
Copy link
Contributor Author

@stsypanov stsypanov commented Oct 23, 2020

/integrate

Loading

@openjdk openjdk bot added the sponsor label Oct 23, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 23, 2020

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

Loading

@dfuch
Copy link
Member

@dfuch dfuch commented Oct 23, 2020

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

Loading

@dfuch
Copy link
Member

@dfuch 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

Loading

prrace
prrace approved these changes Oct 24, 2020
Copy link
Contributor

@prrace prrace left a comment

client changes are fine

Loading

@stsypanov
Copy link
Contributor Author

@stsypanov stsypanov commented Oct 28, 2020

Rebased onto master to have the fix introduced in #778

Loading

@openjdk openjdk bot removed the sponsor label Oct 28, 2020
@mrserb
Copy link
Member

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

Loading

@stsypanov
Copy link
Contributor Author

@stsypanov stsypanov commented Oct 28, 2020

@mrserb thanks for pointing this out!

Loading

@stsypanov
Copy link
Contributor Author

@stsypanov stsypanov commented Oct 28, 2020

/integrate

Loading

@openjdk openjdk bot added the sponsor label Oct 28, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 28, 2020

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

Loading

@dfuch
Copy link
Member

@dfuch dfuch commented Oct 28, 2020

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

Loading

@openjdk
Copy link

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

Loading

@stsypanov stsypanov deleted the atom-simpl branch Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment