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

Add utility methods to check long indexes and ranges

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 16
    • 16
    • core-libs
    • None
    • b25

    Description

      This is related to JDK-8135248. The goal is to add a similar set of methods but rather than operate on int arguments, the new methods operate on long arguments.

      The new methods in Objects are:

      public static long checkIndex(long index, long length)
      public static long checkFromToIndex(long fromIndex, long toIndex, long length)
      public static long checkFromIndexSize(long fromIndex, long size, long length)

      They mirror the int utility methods.

      As is the case with the int checkIndex(), the long checkIndex() method will be JIT compiled as an intrinsic. That allows the JIT to compile checkIndex to an unsigned comparison and properly recognize it as range check that then becomes a candidate for the existing range check optimizations. This has proven to be important for panama's MemorySegment and a prototype of this change (with some extra c2 improvements) showed that panama micro benchmark results improve significantly.

      Attachments

        Issue Links

          Activity

            People

              roland Roland Westrelin
              roland Roland Westrelin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: