[foreign-preview] RFR: 8282070: Drop workaround from memory segment implementation

Jorn Vernee jvernee at openjdk.java.net
Thu Feb 17 22:35:13 UTC 2022


On Thu, 17 Feb 2022 19:07:12 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> Following some preliminary experiments (see [1]) it is now finally time to drop the various workarounds we have in the memory segment implementation. This patch removes two workarounds:
> 
> * special treatment for "small" segments (e.g. segments whose size fits in an int) - see `MemorySegment::isSmall`; these segments were special cased so that bound checks would only involve `int` comparisons. This has now been fixed in JDK-8276116, and special treatment is no longer required.
> 
> * special shortcuts to avoid extra alignment checks. Since when generating var handles from a layout we check most of the alignment constraints (except those involving the base address), in the past we have added a fastpath for these var handles, as C2 had trouble hoisting alignment checks outside of the loops. This has now been fixed in JDK-8277850 and is no longer required.
> 
> I have run benchmarks before and after and got identical results. Some benchmarkks in `ParallelSum` got a boost, but those always have noise, due to multi-threading.

Marked as reviewed by jvernee (Committer).

src/java.base/share/classes/jdk/internal/foreign/Utils.java line 155:

> 153: 
> 154:     @ForceInline
> 155:     public static long scaleOffset(MemorySegment segment, long index, long size) {

Seems like this method is pretty redundant now, and users can just do `index * size`? (at least I think the segment parameter could be dropped).

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

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


More information about the panama-dev mailing list