RFR: 8300258: C2: vectorization fails on simple ByteBuffer loop [v2]
Vladimir Kozlov
kvn at openjdk.org
Thu Mar 2 17:33:21 UTC 2023
On Thu, 2 Mar 2023 09:05:28 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
> I think the reason we used `same_velt_type` was that we were confused. Or maybe we did that before we had memory slices, and using `same_velt_type` was at least already an improvemnt? At any rate: it was confused and leads to Bugs in conjunction with `Unsafe`, as my example showed.
I did not consider using memory slices (or unsafe access) when worked on this code. Same element type was easy choice for this check.
> I also don't think we should spend too much time making sure every possible combinations of unsafe accesses optimize well or even correctly if it's too much work. Once people start using unsafe, they are on their own. I think we should stick with whatever feels reasonable or is used in the core libraries (hopefully the second category is included in the first category).
Yes, even without vectorization we can construct a Java test with Unsafe access which has cyclic dependencies and overwrite elements intentionally or by mistake. I remember one such case in system libraries several years ago which was fixed.
JIT optimization should not introduce wrong behavior if Java code does not have it. But if we can correctly detect and reject cyclic dependency we can vectorize it. Original Roland's example and last Emanuel's `StoreI(farr, i)` example don't have "bad" cyclic dependency - at worst they store the same values to the same elements. So it is all about cyclic dependency detection and assumption that we may accessing the same array.
-------------
PR: https://git.openjdk.org/jdk/pull/12440
More information about the hotspot-compiler-dev
mailing list