[intrinsics] performance improvements for the intrinsified version of Objects::hash
Aleksey Shipilev
shade at redhat.com
Thu Mar 7 22:21:15 UTC 2019
On 3/7/19 11:15 PM, Alex Buckley wrote:
> On 3/7/2019 1:40 PM, Aleksey Shipilev wrote:
>> Arguably, reading from fields is what would happen "in real world", when Object::hashcode is called
>> on object with unknown identity, object fields have to be read before calling into Object::hash,
>> etc. Measuring folding through the constants is good, but it might not be the target scenario here.
>
> IIUC (and I realize this is basic stuff in JMH-land) you're saying there may be a measurable
> difference between these two benchmarks:
>
> @State(Scope.Benchmark)
> public class IntrinsicsBenchmark {
> int i1 = 1;
>
> @Benchmark
> public int testHash0001Int_Field() {
> // Single read of field with unknown value
> return Objects.hash(i1);
> }
>
> @Benchmark
> public int testHash0001Int_Local() {
> // This local variable is not constant to a Java compiler
> // but will be constant folded by the JIT compiler
> int i = 1;
> return Objects.hash(i);
> }
> }
Yes. Because JIT compiler is ought to realize "i" is constant "1" during JIT compilation time, and
fold through. It is trivial to do when compiler parses the bytecode into IR, and the whole thing
does not require any speculation, profile, or anything advanced at all, to be honest. Even C1 should
be able to pull it off.
Seeing these effects is why you use -prof perfasm to study the generated code :)
-Aleksey
More information about the amber-dev
mailing list