[lworld] RFR: 8348606: [lworld] Substitutability test may perform heap allocations [v2]

Quan Anh Mai qamai at openjdk.org
Wed Apr 9 10:09:27 UTC 2025


On Thu, 13 Feb 2025 01:17:07 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Update substitutability test to use MethodHandles that access independent primitive/pointer instead heap reallocated copies of inlined values with an object header. Need long-term solution for user MethodHandle that accesses nested values in the future; hope the intrinsics can help in the future.
>> 
>> Testing: test/jdk/valhalla and test/hotspot/jtreg/*/valhalla, tier 1-3 tests running.
>
> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix redundant debug and failing IO test

The reason you are seeing the failures is that you are using `Unsafe` incorrectly. Note this paragraph:

     * The results are undefined unless one of the following cases is true:
     * <ul>
     * <li>The offset was obtained from {@link #objectFieldOffset} on
     * the {@link java.lang.reflect.Field} of some Java field and the object
     * referred to by {@code o} is of a class compatible with that
     * field's class.
     *
     * <li>The offset and object reference {@code o} (either null or
     * non-null) were both obtained via {@link #staticFieldOffset}
     * and {@link #staticFieldBase} (respectively) from the
     * reflective {@link Field} representation of some Java field.
     *
     * <li>The object referred to by {@code o} is an array, and the offset
     * is an integer of the form {@code B+N*S}, where {@code N} is
     * a valid index into the array, and {@code B} and {@code S} are
     * the values obtained by {@link #arrayBaseOffset} and {@link
     * #arrayIndexScale} (respectively) from the array's class.  The value
     * referred to is the {@code N}<em>th</em> element of the array.
     *
     * </ul>

The wording here is albeit bad, it is not only the result that is undefined, the behaviour itself is undefined.

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/1364#issuecomment-2656802521


More information about the valhalla-dev mailing list