- You cannot get the native address of arrays in order to pass them to native code.
- Arrays are subject to being moved by the GC, so even if you could get the address they could move.
- Arrays are limited to around 16 GB, and that's if you're packing data into longs.
- Accessing an array involves a bounds check, which may float out of a loop, but may well not.
- Arrays cannot be allocated with memory that is anything except mapped private.
I use Unsafe to put memory into a location where I can get a stable native address in order to make native calls using it. Using an array would not allow that.
It's not a JIT problem, it's a VM problem. Graal uses the same VM with a different (or additional JIT) JIT and inherits the same (intentional) 2 GB limitations.
While J9 can give you larger arrays AFAIK you're not guaranteed to get a single, contiguous memory region. You won't notice in Java but JNI criticals may return copies.
I'm not sure what you're getting at. Why would you want to? The issue was having a big chunk of native memory that you can pack data into on the java side and read contiguously without barriers on the native side and that's what a native allocated byte buffer would get you. Or am I missing something? Not sure what varhandles adds to the situation? Sorry if I'm being dense :o)
- Arrays are subject to being moved by the GC, so even if you could get the address they could move.
- Arrays are limited to around 16 GB, and that's if you're packing data into longs.
- Accessing an array involves a bounds check, which may float out of a loop, but may well not.
- Arrays cannot be allocated with memory that is anything except mapped private.
I use Unsafe to put memory into a location where I can get a stable native address in order to make native calls using it. Using an array would not allow that.