Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160821

VarHandle accesses are penalized when argument conversion is required

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8, 22
    • core-libs

      This looks similar to JDK-8153870, but for arguments.

      See the test:

          private static final VarHandle VH_LONG = MethodHandles.byteBufferViewVarHandle(
                  long[].class, java.nio.ByteOrder.nativeOrder());

          ByteBuffer buffer;

          @Setup
          public void setup() {
              buffer = ByteBuffer.allocateDirect(3 * 1024).alignedSlice(8);
          }

          @Benchmark
          public void test_int() {
              for (int i = 0; i < 100; i++) {
                  VH_LONG.set(buffer, i, i);
              }
          }

          @Benchmark
          public void test_long() {
              for (int i = 0; i < 100; i++) {
                  VH_LONG.set(buffer, i, (long) i);
              }
          }

      Benchmark Mode Cnt Score Error Units
      VHLongMismatch.test_int avgt 5 1370.022 ± 0.350 ns/op
      VHLongMismatch.test_long avgt 5 41.471 ± 0.537 ns/op

      33x performance hit.

      Tests:
        http://cr.openjdk.java.net/~shade/8160821/VHLongMismatch.java
        http://cr.openjdk.java.net/~shade/8160821/benchmarks.jar
        

            liach Chen Liang
            shade Aleksey Shipilev
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: