RFR: 8300258: C2: vectorization fails on simple ByteBuffer loop [v2]
Emanuel Peter
epeter at openjdk.org
Thu Mar 2 08:33:13 UTC 2023
On Tue, 21 Feb 2023 16:05:27 GMT, Roland Westrelin <roland at openjdk.org> wrote:
>> Roland Westrelin has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
>>
>> - comments
>> - extra test
>> - more
>> - Merge branch 'master' into JDK-8300258
>> - review
>> - more
>> - fix & test
>
> Maybe we should first collect all legal packs and then try to find the best alignment, dropping packs that are unaligned on those platforms that support it.
Hi @rwestrel @vnkozlov .
I have another general question. Should this really vectorize?
@Test
@IR(counts = { IRNode.LOAD_VECTOR, ">=1", IRNode.STORE_VECTOR, ">=1" })
public static void testOffHeapLong1(long dest, long[] src) {
for (int i = 0; i < src.length; i++) {
UNSAFE.putLongUnaligned(null, dest + 8 * i, src[i]);
}
}
I talked with @TobiHartmann about this. It is apparently possible to get the address of an array, and store in a `long`. In that case, we could play with that rawptr a bit, and create a cyclic dependency.
Pseudocode:
long[] arr = new long[1000];
long ptr = unsafe.getTheArrayAddress(arr); // does not exist directly, but it is possible
ptr += 8; // shift it one long forward
testOffHeapLong1(ptr, arr);
This should have different behavior if it is vectorized or not.
But maybe this is expected, and just a bad use of `Unsafe`. Probably we want this to vectorize, for the extra performance, and people who use `Unsafe` just have to be careful not to do such strange things.
-------------
PR: https://git.openjdk.org/jdk/pull/12440
More information about the hotspot-compiler-dev
mailing list