JDK-8231756 : [JVMCI] need support for deoptimizing virtual byte arrays encoding non-byte primitives
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,14
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-10-02
  • Updated: 2022-02-06
  • Resolved: 2020-04-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 15
11.0.9-oracleFixed 15 b20Fixed
Description
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}
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/1086e120d83a User: never Date: 2020-04-17 16:32:11 +0000
17-04-2020

[~never] could you please sponsor this contribution from Thomas Garcia.
02-10-2019

JVMCI-8 implementation: https://github.com/graalvm/graal-jvmci-8/commit/1c923ff8202f03830ba0710671096db586d13937
02-10-2019