JDK-8255150 : Add utility methods to check long indexes and ranges
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-10-21
  • Updated: 2024-02-06
  • Resolved: 2020-11-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b25Fixed
Related Reports
CSR :  
Relates :  
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.
Comments
Changeset: a7422ac2 Author: Roland Westrelin <roland@openjdk.org> Date: 2020-11-17 10:37:27 +0000 URL: https://github.com/openjdk/jdk/commit/a7422ac2
17-11-2020