[intrinsics] performance improvements for the intrinsified version of Objects::hash

Alex Buckley alex.buckley at oracle.com
Thu Mar 7 22:15:03 UTC 2019


On 3/7/2019 1:40 PM, Aleksey Shipilev wrote:
> On 3/7/19 10:20 PM, Vicente Romero wrote:
>>> *) I guess what you want to check for performance when arguments read from instance fields -- that
>>> would be the target test case that simulates Object.hashCode(), no?
>>
>> reading instance fields or local variables shouldn't make a big difference
>
> It would for @Benchmarks, because reading from @State field would make sure neither javac nor JIT
> compiler knows the value during the compilation. See e.g.:
>
> https://hg.openjdk.java.net/code-tools/jmh/file/5984e353dca7/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_10_ConstantFold.java
>
> 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);
     }
   }

Alex


More information about the amber-dev mailing list