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

[JVMCI] need support for deoptimizing virtual byte arrays encoding non-byte primitives

XMLWordPrintable

    • b20

        Consider a Java based implementation of a Java interpreter that encodes the primitive fields of an object in a byte array. For example:

        class MyClass {
            long l;
            int i;
            boolean b;
        }

        could be encoded as a byte array of length 13:

        byte[] data = {
            l0, l1, l2, l3, l4, l5, l6, l7,
            i0, i1, i2, i3,
            b1
        }

        Implementing access to field i can be done with Unsafe:

        setter: Unsafe.putInt(obj, Unsafe.ARRAY_BYTE_BASE_OFFSET + 8, val);
        getter: Unsafe.getInt(obj, Unsafe.ARRAY_BYTE_BASE_OFFSET + 8);

        A JVMCI compiler (such as Graal) may be able to escape analyze a MyClass object and represent it as registers and stack locations. If such a "virtualized" object is alive at a deoptimization point, the compiler would like to encode info for `data` that indicates how the fields are encoded in the byte array. This can be done in jdk.vm.ci.code.VirtualObject. A primitive value of a kind of n bytes in a byte array at index i results in a VirtualObject instance with its entry at i being the full primitive value, and the n-1 next entries being the illegal constant.
        During deoptimization, materializing the entry at i involves counting the number of following illegals starting from i+1, and from that deducing how many bytes to write at once. The entry at i is then written over said illegals, and the illegals are skipped.
        This allows to craft a compact representation of primitive fields that benefits from escape analysis.

        As an example, the VirtualObject representing for a MyClass instance {l=42, i=7, b=true} would be:

        {42, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, ILLEGAL, 7, ILLEGAL, ILLEGAL, ILLEGAL, true}

              never Tom Rodriguez
              dnsimon Douglas Simon
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: