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

C2 should optimize explicit range checks

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b64

      Backports

        Description

        See JDK-8042997

        Consider the following code:

           static void setVolatile(ArrayRefHandle handle, Object[] array, int index,
                   Object value) {
               if (index < 0 || index >= array.length) // bounds and null check
                   throw new ArrayIndexOutOfBoundsException();
               UNSAFE.putObjectVolatile(array,
                                        (((long) index) << handle.ashift) + handle.abase,
                                        castReference(handle.componentType, value));
           }

        For such a user written range test the compiler does fully recognize an array access is going on and so certain optimizations tend not to kick in, such as removing or strength reducing range checks, treating "index" as an unsigned value as opposed to a signed value, or coalescing write barriers when loop unrolling.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                roland Roland Westrelin
                Reporter:
                roland Roland Westrelin
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: