[vectorIntrinsics] RFR: Optimize mem barriers for ByteBuffer cases [v2]

Radoslaw Smogura github.com+7535718+rsmogura at openjdk.java.net
Mon Aug 2 16:29:42 UTC 2021


On Mon, 2 Aug 2021 15:51:30 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> What if we use unsafe to read the BB read only field? we do that for VHs:
> 
> ```
>         @ForceInline
>         static int indexRO(ByteBuffer bb, int index) {
>             if (UNSAFE.getBoolean(bb, BYTE_BUFFER_IS_READ_ONLY))
>                 throw new ReadOnlyBufferException();
>             return index(bb, index);
>         }
> ```
> 
> The virtual method call to `Buffer.isReadOnly` might be complicating matters.
> 
> Logistically, having seen the scope of changes, perhaps it's best to first focus on a smaller changeset for the specific problem, then revisit with better use of the decorators? That way we could integrate this PR to `vectorIntrinsics` then bring into `jdk` then afterwards decide on a refactor, with input from the hotspot reviewers?

Yes, this change looks huge... a bit or even two bits...

I think it's a very good idea to use unsafe with BB to check for read only, that's something I was missing. However, outermost "if" should be a check if a buffer is direct or not and it should take input from immutable memory this way we have more chances to unswitch loop on this what creates the biggest issue: splitting load/store to on-heap or off-heap (otherwise in polluted case, it can be problematic). Here, we should use instanceof, instead of isDirect, as isDirect is virtual call and in most polluted cases this can kick in (unless we can somehow optimize isDirect)

-------------

PR: https://git.openjdk.java.net/panama-vector/pull/104


More information about the panama-dev mailing list