C2 doesn't hoist out flattened value array guard out of loops

Roland Westrelin rwestrel at redhat.com
Fri Mar 29 16:21:25 UTC 2019

Hi Sergey,

> The reason of that that check if arrays is flattened value array was not 
> hoisted out of the loop and checked on each iteration.

It used to be that we didn't support loading/storing elements of a
flattened array if we didn't know the exact type of the elements. So
generated code at aaload/aastore of an Object[] array checked for a
flattened array and caused a deoptimization in that case. Those guards
were easy for c2 to hoist. Now, we support loading/storing from a
flattened array declared as Object[]. We compile a flattened array check
as before but now both branches of the check are expected to be
taken. The flattened array check cannot be hoisted anymore. Instead, we
can use that test to unswitch loop and so make 2 copies of the loop.

That doesn't happen with org.openjdk.array.Array.sum currently but I
have a small change that enables it. With that patch
org.openjdk.array.Array.sum performs the same with or without

That's not sufficient for org.openjdk.array.Array.copyFor and
org.openjdk.array.Array.hash and I'm trying to figure out what can be
done for those 2.


More information about the valhalla-dev mailing list