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

[macos]Provide ArrayViewVarHandle for java primitive arrays beside byte[]

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 14.0.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      ADDITIONAL SYSTEM INFORMATION :
      MacOS
      JDK 14

      A DESCRIPTION OF THE PROBLEM :
      Currently MethodHandles.byteArrayViewHandle(...) can be used to read 64bits, 32bits, 16bits from a byte array. This allows vectorized like operations on byte[] elements and can for the most part substitute for Unsafe.Unsafe.getLong / Unsafe.ArrayBaseOffset

      However, this is not possible for char[] or int[] arrays. It would be nice to have something of the form:

      VarHandle v = MethodHandles.arrayViewVarHandle(char[].class, long[].class, ByteOrder.nativeOrder());

      This would allow client code to work with regular java char[] array while using Unsafe (JDK 8) and VarHandle (JDK 11?) for specialized array algorithms. Currently there is no way to move beyond JDK 8 without loss of performance for such scenarios.

      Possible workarounds:

      1) use byte[] array for storage and then access all elements using a VarHandle from MethodHandles.byteArrayViewVarHandle(char[].class, ...) for regular access. This is cumbersome and error prone since indexing is still at the byte[] array level.

      2) Not sure if jdk.incubator.foreign.MemoryLayout could be used to get a VarHandle that can access 64 bits at a time from a char[]. It is not clear if such a VarHandle can be used concurrently in a lock-free algorithm.


        Attachments

          Activity

            People

            • Assignee:
              psandoz Paul Sandoz
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: