comments on performance / foreign-abi

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jan 21 00:44:04 UTC 2020


Btw - quick code comment; I think the best way to squeeze performances 
out of the memory API at the moment (because of the aforementioned C2 
issues) is to use the indexed VarHandle (the commented one), but 
manually hoist the call to baseAddress() outside the loop, as in:

MemoryAddress base = list.baseAddress();
  for (int i=0;i<out.length;i++) {
         MemoryAddress addr = (MemoryAddress)addrVHandle.get(base, (long)i);
         ...
}

This issue also comes up here:
https://bugs.openjdk.java.net/browse/JDK-8237082

Maurizio


On 21/01/2020 00:21, Maurizio Cimadamore wrote:
> try (MemorySegment lenp = MemorySegment.allocateNative(4, 4)) {
>                 int len;
>                 int res;
>
>                 res = (int)clGetPlatformIDs.invokeExact(0, 
> MemoryAddress.NULL, lenp.baseAddress());
>                 len = Native.getInt(lenp.baseAddress());
>                 try (MemorySegment list = 
> MemorySegment.allocateNative(len * 8, 8)) {
>                     res = (int)clGetPlatformIDs.invokeExact(len, 
> list.baseAddress(), lenp.baseAddress());
>
>                     CLPlatform[] out = new CLPlatform[len];
>                     for (int i=0;i<out.length;i++) {
>                         //MemoryAddress addr = 
> (MemoryAddress)addrVHandle.get(list.baseAddress(), (long)i);
>                         MemoryAddress addr = 
> Native.getAddr(list.baseAddress().addOffset(i*8));
>
>                         out[i] = Native.resolve(addr, CLPlatform::new);
>                     }
>
>                     return out;
>                 }
>             } catch (Throwable t) {
>                 throw new RuntimeException(t);
>             }


More information about the panama-dev mailing list