[vector]: Unslice - modification of the argument vector

Deshpande, Vivek R vivek.r.deshpande at intel.com
Tue Oct 22 16:42:12 UTC 2019


Thanks Yang

That looks good to me. But wait for John's comment before pushing it.

Regards,
Vivek

-----Original Message-----
From: Yang Zhang (Arm Technology China) [mailto:Yang.Zhang at arm.com] 
Sent: Monday, October 21, 2019 7:42 PM
To: John Rose <john.r.rose at oracle.com>; 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

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
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the panama-dev mailing list