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

Vladimir Ivanov vlivanov at openjdk.java.net
Wed Aug 4 21:19:50 UTC 2021


On Wed, 4 Aug 2021 21:00:14 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

>> # Description
>> This change tries to remove mem bars for byte buffer cases.
>> 
>> Previously mem bars were inserted almost unconditionally if attemp to native memory acees where detected. This patch tries to follow up inline_unsafe_access and insert bar only if can't determine if it's heap or off-heap (type missmatch cases are not ported).
>> 
>> # Testing
>> Memory tests should include rollbacking JDK changes, and leaving only hotspot, as intrinsics should be well guarded
>> 
>> # Notes
>> Polluted cases to be addressed later
>> 
>> # Benchmarks
>> 
>> Benchmark                                (size)  Mode  Cnt    Score   Error  Units
>> ByteBufferVectorAccess.arrays              1024  avgt   10   12.585 ? 0.409  ns/op
>> ByteBufferVectorAccess.directBuffers       1024  avgt   10   19.962 ? 0.080  ns/op
>> ByteBufferVectorAccess.heapBuffers         1024  avgt   10   15.878 ? 0.187  ns/op
>> ByteBufferVectorAccess.pollutedBuffers2    1024  avgt   10  123.702 ? 0.723  ns/op
>> ByteBufferVectorAccess.pollutedBuffers3    1024  avgt   10  223.928 ? 1.906  ns/op
>> 
>> Before
>> 
>> Benchmark                                (size)  Mode  Cnt    Score   Error  Units
>> ByteBufferVectorAccess.arrays              1024  avgt   10   14.730 ? 0.061  ns/op
>> ByteBufferVectorAccess.directBuffers       1024  avgt   10   77.707 ? 4.867  ns/op
>> ByteBufferVectorAccess.heapBuffers         1024  avgt   10   76.530 ? 1.076  ns/op
>> ByteBufferVectorAccess.pollutedBuffers2    1024  avgt   10  143.331 ? 1.096  ns/op
>> ByteBufferVectorAccess.pollutedBuffers3    1024  avgt   10  286.645 ? 3.444  ns/op
>
> Radoslaw Smogura has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Code review changes:
>   * make specied final static in test
>   * use Unsafe to check if ByteBuffer is readOnly
>   * remove if in X-ScopedMemory when loading / storing vectors,
>      stay with byte[] cast
>   * inline copyMemory in micro benchmark

`.gitignore` changes are unrelated.

You reverted mismatched access checks. Please, bring them back.

src/hotspot/share/opto/vectorIntrinsics.cpp line 837:

> 835:   const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass);
> 836: 
> 837:   if (mixed_access) {

I suggest the following shapes for the checks:

const bool in_native = (TypePtr::NULL_PTR == base_type);            // base always null
const bool in_heap   = !TypePtr::NULL_PTR->higher_equal(base_type); // base never null

const bool is_mixed_access = !in_heap && !in_native;

const bool is_mismatched_access = in_heap && (addr_type->isa_aryptr() == NULL);

const bool needs_cpu_membar = is_mixed_access || is_mismatched_access;

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

Changes requested by vlivanov (Committer).

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


More information about the panama-dev mailing list