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

[lworld][c1] aaload cannot handle unloaded class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • repo-valhalla
    • repo-valhalla
    • hotspot

      If V is an value class, and this method is compiled *before* V is loaded, incorrect code is generated.

          static Object test(int i) {
              V[] arr = new V[i+1];
              int n = arr[1].v1;
              return arr;
          }

        static java.lang.Object test(int);
          Code:
             0: iload_0
             1: iconst_1
             2: iadd
             3: anewarray #3 // class "QV;"
             6: astore_1
             7: aload_1
             8: iconst_1
             9: aaload
            10: getfield #4 // Field V.v1:I
            13: istore_2
            14: aload_1
            15: areturn

      The array type for the aaload instruction is #3 "QV;". When we attempt to get a ciKlass for this symbol using ciEnv::get_klass_by_name_impl, the "Q" is dropped:

      http://hg.openjdk.java.net/valhalla/valhalla/file/f19715f86b32/src/hotspot/share/ci/ciEnv.cpp#l403

      ... and we discover that the "V" class is not yet loaded, so we return a unloaded version of an ciInstanceKlass:

      http://hg.openjdk.java.net/valhalla/valhalla/file/f19715f86b32/src/hotspot/share/ci/ciObjectFactory.cpp#l515

      For GraphBuilder::load_indexed to work properly, we need to return an a unloaded version of an ciValueKlass instead. That way, we can bail out like this:

      void GraphBuilder::load_indexed(BasicType type) {
        ...
        if (array->is_flattened_array()) {
          ciType* array_type = array->declared_type();
          ciValueKlass* elem_klass = array_type->as_value_array_klass()->element_klass()->as_value_klass();
      + if (!elem_klass->is_loaded()) {
      + BAILOUT("Huh");
      + }

      (currently array->is_flattened_array() returns false, despite the "Q" in the signature, so the bailout won't work).

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

              Created:
              Updated:
              Resolved: