RFR: 8255299: Drop explicit zeroing at instantiation of Atomic* objects
Daniel Fuchs
dfuchs at openjdk.java.net
Fri Oct 23 09:17:36 UTC 2020
On Fri, 23 Oct 2020 08:15:00 GMT, Sergey Bylokhov <serb 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?
>
> The changes in src/java.desktop looks fine.
Changes to `java.logging` and `java.net.http` also look good to me.
-------------
PR: https://git.openjdk.java.net/jdk/pull/818
More information about the security-dev
mailing list