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

Add a method to MemoryLayout which returns a offset-computing method handle

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • None
    • repo-panama
    • tools

    Description

      MemoryLayout::byteOffset is useful, but only works when the path elements passed to it are fully specified.

      There might be cases where the user has a multi-dimensional layout like:

      MemoryLayout.ofSequence(100,
          MemoryLayout.ofSequence(200,
               MemoryLayout.ofValueBits(32).withName("elem")
          )
      )

      Now, when we derive a VarHandle for this, we can get two free variables, for the two sequence indices - these values will be used to determine the final offset calculation.

      But there's no way to do this with offsets - e.g. there's no way to pass an open-ended layout path to MemoryLayout::byteOffset - because that method wants the layout to be fully specified.

      To improve usability in this cases, it would be nice to consider adding an extra method:

      MethodHandle MemoryLayout::byteOffsetHandle

      Which returns a MethodHandle whose signature is:

      J(J...J)

      where the long parameters correspond to one or more free dimensions in the layout path. This would add some symmetry to the API, since now both VarHandles and offsets can be computed in the same way.

      Attachments

        Issue Links

          Activity

            People

              jvernee Jorn Vernee
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: