Changes to the Java code looks fine to me - (and the overall approach in
Unsafe seems sensible, but I'll defer to David for that)
Thanks
Maurizio
On 24/01/2020 09:58, Nick Gasson wrote:
Hi David,
On 01/24/20 14:35 pm, David Holmes wrote:
How about we align the size up to ADDRESS_SIZE (== HeapWordSize) in
Unsafe.allocateMemory() before the call to allocateMemoryChecks(). Like:
bytes = ((bytes + ADDRESS_SIZE - 1) & ~(ADDRESS_SIZE - 1));
Then it will throw an IllegalArgumentException if the result is outside
the size_t range. And in the native code we can just assert that the
`size' argument is already aligned:
assert(is_aligned(sz, HeapWordSize), "sz not aligned");
That seems quite reasonable.
I've done this here:
http://cr.openjdk.java.net/~ngasson/8237521/webrev.02/
Need to check bytes >= 0 before aligning up so that allocateMemory(-1)
still throws an IllegalArgumentException.
Tested with jdk_foreign and runtime/Unsafe/.
Thanks,
Nick