RFR: 8255299: Drop explicit zeroing at instantiation of Atomic* objects
Claes Redestad
redestad at openjdk.java.net
Fri Oct 23 08:08:35 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?
Marked as reviewed by redestad (Reviewer).
-------------
PR: https://git.openjdk.java.net/jdk/pull/818
More information about the security-dev
mailing list