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

[lworld] C1 aastore of flattened array needs null and type check

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: repo-valhalla
    • Fix Version/s: repo-valhalla
    • Component/s: hotspot
    • Labels:

      Description

      Normally, javac and the verifier would prevent storing of nullable values into a flattened array. For example, the two commented lines in the program below are illegal.

      public class InlineStore1 {
          static final value class V {
              final int v0 = 0, v1 = 0;
          }
          static final class W {
              final int w0 = 0, w1 = 0;
          }
          static void inline(Object[] oa, Object n) {
              oa[0] = n;
          }
          static void test(V arr[], W w, boolean donull) {
              if (donull) {
                  w = null;
                  inline(arr, w);
              } else {
                  inline(arr, w);
              }
          }
          public static void main(String args[]) {
              V arr[] = new V[2];
              W w = new W();
              // The following 2 lines are illegal
              // arr[0] = w;
              // arr[0] = null;
              try {
                  test(arr, w, false);
              } catch (Throwable t) {
                  t.printStackTrace();
              }
              try {
                  test(arr, w, true);
              } catch (Throwable t) {
                  t.printStackTrace();
              }
              try {
                  test(arr, null, false);
              } catch (Throwable t) {
                  t.printStackTrace();
              }
          }
      }

      However, when C1 inlines a method, it propagate the types from the caller to the callee, so when the HIR is being built, we effectively see expressions like these

          ((V[])oa)[0] = (W)w;
          ((V[])oa)[0] = null;

      We need to check for these conditions: when aastore tries to store a value whose declared type is not the same as the element type of the flattened array, C1 needs to emit explicit null checks and type checks.

        Attachments

          Activity

            People

            • Assignee:
              iklam Ioi Lam
              Reporter:
              iklam Ioi Lam
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: