[foreign-memaccess] RFR: 8252770: MemorySegment::allocateNative should honor direct memory limits
Paul Sandoz
psandoz at openjdk.java.net
Thu Sep 3 20:48:40 UTC 2020
On Thu, 3 Sep 2020 14:18:18 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Currently, `MemorySegment::allocateNative` does not honor the memory limits set for direct buffers
> (`-XX:MaxDirectMemorySize` and `-XX:+PageAlignDirectMemory`).This patch rectifies that. The changes are pretty simple,
> the main issue was that most of the methods are defined away in the `Bits` class which belongs to the nio package, so
> the usual access dance was necessary. Since segments can already be allocated with an alignment, I slightly tweaked
> the alignment logic to compute the max between page size and requested alignment, in case the option for aligning
> direct memory chunks to page boundaries is set. Tweak NativeMemorySegmentImpl to respect direct memory settings
Marked as reviewed by psandoz (Committer).
src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/NativeMemorySegmentImpl.java line 89:
> 87: alignmentBytes = Math.max(alignmentBytes, nioAccess.pageSize());
> 88: }
> 89: long alignedSize = alignmentBytes > MAX_ALIGN ?
Minor comment, it might be a little clearer if `MAX_ALIGN` was renamed to `MALLOC_MAX_ALIGN`.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/306
More information about the panama-dev
mailing list