[vector]: Unslice - modification of the argument vector
Yang Zhang (Arm Technology China)
Yang.Zhang at arm.com
Tue Oct 22 02:41:33 UTC 2019
Hi John, Vivek
I propose a fix for this issue. Please check it. http://mail.openjdk.java.net/pipermail/panama-dev/2019-October/006471.html
Regards
Yang
-----Original Message-----
From: panama-dev <panama-dev-bounces at openjdk.java.net> On Behalf Of John Rose
Sent: Friday, September 27, 2019 6:27 AM
To: Deshpande, Vivek R <vivek.r.deshpande at intel.com>
Cc: panama-dev at openjdk.java.net
Subject: Re: [vector]: Unslice - modification of the argument vector
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