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

C2 should optimize explicit range checks

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • hotspot
    • None
    • b64

        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.

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

                Created:
                Updated:
                Resolved: