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

VarHandle accesses are penalized when argument conversion is required

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:

      Description

      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
        

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: