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

[lworld] Scalarization of sealed value abstract classes/interfaces in the calling convention

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • hotspot

      It is often infeasible to scalarize an abstract class or interface because they have different scalarization forms and indirection is necessary for virtual dispatches. However, if all concrete value classes in the hierarchy have similar layouts, then it may be possible to scalarize them.

      Consider this hierarchy:

      sealed abstract class Parent {
          abstract int val();
      }

      value class Child1 extends Parent {
          int x1;
          long[] y1;

          int val() {
              return x1 + y1.length;
          }
      }

      value class Child2 extends Parent {
          int x2;
          int[] y2;

          int val() {
              return x2 - y2.length;
          }
      }

      Then both Child1 and Child2 would have similar layouts {int, Object}. As a result, Child1::val would have the ABI similar to:

      int Child1_val(int, void*)

      and Child2::val would have the ABI similar to:

      int Child2_val(int, void*)

      Then a Parent can be scalarized into {int, Object, Klass*}, and a virtual dispatch can be implemented, for example:

      int calculateVal(Parent p) {
          return p.val();
      }

      can be implemented as:

      int calculateVal(int x, void* y, Klass* klass) {
          klass->val(x, y, klass);
      }

      The klass argument is needed in cases where klass->val does not belong to a final value class, in which case we need the klass pointer because we are dealing with another sealed abstract class. This will need to be removed if klass->val is implemented in klass itself before dispatching to the actual method implementation.

      Another approach is to implement it as:

      int calculateVal(int x, void* y, Klass* klass) {
          klass->val(x, y);
      }

      And klass->val will insert the klass parameter if klass does not implement val (it is implemented by a superclass).

            Unassigned Unassigned
            qamai Quan Anh Mai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: