[vector] RFR 8221816: IndexOutOfBoundsException for fromArray/intoArray with unset mask lanes - was: RE: IndexOutOfBoundsException with unset mask lanes

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Fri May 31 22:13:15 UTC 2019


>> I think the problem is, without uncommon trap, VectorBox will be generated in fast path, for example, after blend for fromArray.
> 
> (Without uncommon trap, or loop splitting that creates
> a slow version of the loop to catch bad stuff.)
> 
>> This results in Vector will be stored into memory instead of simd register. Is my understanding correct?
> 
> Vladimir would know for sure but this sounds right.

Yes, as experience shows, scalar code will cause problems: vector values 
have to be boxed first to make existing accessors work. In the worst 
case, it will completely break box elimination for affected values.

But there are some workarounds which can alleviate the effects. In 
particular, aggressive vector reboxing can narrow the scope by splitting 
live ranges and localizing the boxed value around the problematic use site.

I'd expect reboxing should already work for XxxVector.forEach() since it 
uses XxxNnnVector.getElements() to access backing array:

     @Override
     void forEach(FUnCon f) {
         int[] vec = getElements();
         for (int i = 0; i < length(); i++) {
             f.apply(i, vec[i]);
         }
     }

     private int[] getElements() {
         return VectorIntrinsics.maybeRebox(this).vec;
     }

Also, it seems beneficial to migrate away from getElements() & array 
accessors to XxxVector.get() since it is already intrinsified.

(XxxVector.with() looks attractive as well, but it may cause too much 
churn if used in default implementation. So should be used with caution.)

Best regards,
Vladimir Ivanov

> 
> — John
> 
> P.S. What do you ARM experts think about having v.div(w)
> throw ArithmeticException when any lane in w is zero,
> for non-float types only?  I know ARM forces a non-exceptional
> result there, but that's not Java-like at all.  In general, are
> we comfortable with adding exception exits to vector operations,
> like divide-by-zero and AIOOB (array index out of bounds)
> on scatter/gather?
> 


More information about the panama-dev mailing list