[vector]: Unslice - modification of the argument vector
John Rose
john.r.rose at oracle.com
Thu Sep 26 22:27:29 UTC 2019
On Sep 26, 2019, at 3:22 PM, Deshpande, Vivek R <vivek.r.deshpande at intel.com> wrote:
>
> Hi
>
> I have been experimenting with unslice(int origin, vector w, int part) version.
> I noticed that the vector w gets modified after the execution of the API in the Java implementation.
>
> This stems from usage of getElements() in unslicTemplate() and the res[] array points to the same array in the w vector.
> The line System.arraycopy() causes the actual overwriting.
>
> The code I tried is given below: (Here the values of ev vector are modified after execution of unslice method.)
> IntVector dv = IntVector.fromArray(SPECIES1, d, i);
> IntVector ev = IntVector.fromArray(SPECIES1, e, i);
> IntVector dv_v2 = dv.unslice(2, ev, 1);
> dv_v2.intoArray(f, i);
>
Oops, that’s a bug (my bug). I guess I forgot that getElements returns an unsafely aliased array.
Suggestion: Change the name of getElements() to vec() since that’s what it really is, an access
to the raw “vec” field in the vector implementation. Nobody will mistake it for a high-level API
point, whereas “getElements” looks like something formal and safe.
Then, revisit all uses to see if there are any other bugs like this.
— John
More information about the panama-dev
mailing list