[foreign-memaccess+abi] RFR: Simplify ValueLayouts

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Feb 15 16:41:00 UTC 2023


On Wed, 15 Feb 2023 16:06:21 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes a more shortened and simplified scheme when implementing value layouts. 
> 
> This provides a significant reduction of the code size. A new threeary duplicator is introduced. In the solution below, I sugest using a function (`ValueLayoutDuplicator<V>`) which reduces code but arguably makes it a bit more complicated. Another alternative would be to simply mandate a corresponding abstract method and Implement an explicit delegator to the constructor for each type. 
> 
> Let me know your thoughts around how to balance this.

src/java.base/share/classes/jdk/internal/foreign/layout/ValueLayouts.java line 145:

> 143: 
> 144:         @Override
> 145:         final V dup(long bitAlignment, Optional<String> name) {

question: instead of using a duplicator object, can't we have a new `dup` overload here with the required arguments, rewire the old `dup` to the new one, and then override as appropriate in all the subclasses? That would still allow you to define `withOrder` in a single place (which, AFAICS appears to be the main simplification?)

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

PR: https://git.openjdk.org/panama-foreign/pull/798


More information about the panama-dev mailing list