[foreign-memaccess] RFR: JDK-8242495: Restructure implementation of memory segments

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Apr 10 16:35:44 UTC 2020


On Fri, 10 Apr 2020 16:05:53 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> There is a trade-off being monomorphic in type or monomorphic in unsafe access. One problem with `Buffer` was all the
> different types would cause profile pollution if many were intermixed in the same code (e.g. on- and off-heap etc).
> There might be a similar issue here, although given the primary target is off-heap there is less risk and i believe the
> intermixing of native and mapped should not be an issue. Still, it might be worth checking how intermixing on- and
> off-heap behaves.

I believe Vlad did some tests in this area and found similar issues.

> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java line 55:
> 
>> 54:     @ForceInline
>> 55:     HeapMemorySegmentImpl(long offset, Supplier<H> baseProvider, long length, int mask, Thread owner, MemoryScope
>> scope) { 56:         super(length, mask, owner, scope);
> 
> Instead of a `Supplier` i wonder if one could pass in `H base, Class<H> baseType` then `base()` becomes:
> 
>   H base() {
>       return Objects.requireNonNull(baseType.cast(base));
>   }
> 
> If that works there is less for the JIT to do.

Just tried this - makes benchmarks revert to old behavior - roughly 10x slower. Worth a try, but I think using
reflection probably makes thing less transparent to the JIT.

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

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


More information about the panama-dev mailing list