Integrated: 8255299: Drop explicit zeroing at instantiation of Atomic* objects

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Wed Oct 28 12:14:48 UTC 2020


On Thu, 22 Oct 2020 20:46:15 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:

> As discussed in https://github.com/openjdk/jdk/pull/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?

This pull request has now been integrated.

Changeset: 3c4fc793
Author:    Sergey Tsypanov <sergei.tsypanov at yandex.ru>
Committer: Daniel Fuchs <dfuchs at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/3c4fc793
Stats:     19 lines in 17 files changed: 0 ins; 3 del; 16 mod

8255299: Drop explicit zeroing at instantiation of Atomic* objects

Reviewed-by: redestad, serb, prr

-------------

PR: https://git.openjdk.java.net/jdk/pull/818



More information about the security-dev mailing list