[foreign-memaccess+abi] RFR: 8268743: Require a better way for copying data between MemorySegments and on-heap arrays

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Jun 15 12:06:36 UTC 2021


After some investigation, it seems that escape analysis is defeated in cases where a new heap segment is created fresh just before performing a bulk copy.

This is caused by the fact that, on segment creation, we perform this test:


static int defaultAccessModes(long size) {
        return (enableSmallSegments && size < Integer.MAX_VALUE) ?
                SMALL : 0;
    }


To make sure that segments whose size fits in an `int` do not incur in penalties associated with lack of optimizations over long loop bound check optimizations.

Unfortunately, this logic is control flow logic, and control flow disables escape analysis optimizations.

For segment wrappers around byte arrays we can workaround by removing the check (all byte segments are small by definition, since there's a 1-1 mapping between logical elements and physical bytes). For other segment kinds we cannot do much.

While it would be possible, in principle, to resort to more complex bound checks for heap segments, we believe the way forward is to eliminate the need for "small" segments, which will be possible once the PR below is completed:

https://github.com/openjdk/jdk/pull/2045

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

Commit messages:
 - Make all byte heap segment "small" by default

Changes: https://git.openjdk.java.net/panama-foreign/pull/560/files
 Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=560&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8268743
  Stats: 115 lines in 2 files changed: 114 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/560.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/560/head:pull/560

PR: https://git.openjdk.java.net/panama-foreign/pull/560


More information about the panama-dev mailing list