[foreign-memaccess+abi] RFR: 8299730: Add trivial call linker option [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Jan 24 18:39:44 UTC 2023


On Tue, 24 Jan 2023 16:21:01 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Add a trivial call linker option. This option acts as a hint to the runtime which indicates that a downcall is extremely short live (comparable to calling an empty function), and does not call back into Java.
>> 
>> Some implementations (like ours) might use this information to apply additional optimizations that are only applicable to trivial functions (dropping thread state transitions).
>> 
>> Note that the VM code diff looks kind of messy, but I essentially just put 3 `if` statements around the code that deals with the thread state transitions before and after the call. This also required moving the declarations of the `Label`s around though (so they are accessible from both ifs on the return path), which is probably messing up the diff view.
>
> Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add negative trivial upcall test

src/java.base/share/classes/java/lang/foreign/Linker.java line 319:

> 317: 
> 318:         /**
> 319:          * {@return A linker option used to mark a function as trivial}

Suggestion:

         * {@return A linker option used to mark a foreign function as <em>trivial</em>}

src/java.base/share/classes/java/lang/foreign/Linker.java line 321:

> 319:          * {@return A linker option used to mark a function as trivial}
> 320:          * <p>
> 321:          * A 'trivial' function is a function that has an extremely short running time

Suggestion:

         * A trivial function is a function that has an extremely short running time

src/java.base/share/classes/java/lang/foreign/Linker.java line 322:

> 320:          * <p>
> 321:          * A 'trivial' function is a function that has an extremely short running time
> 322:          * in all cases (similar to calling an empty function), and does not call back into Java.

Suggestion:

         * in all cases (similar to calling an empty function), and does not call back into Java (e.g. using an upcall stub).

src/java.base/share/classes/java/lang/foreign/Linker.java line 324:

> 322:          * in all cases (similar to calling an empty function), and does not call back into Java.
> 323:          * <p>
> 324:          * Marking a function using this linker option is a hint which some implementations may use to apply

Suggestion:

         * Using this linker option is a hint which some implementations may use to apply

src/java.base/share/classes/java/lang/foreign/Linker.java line 327:

> 325:          * optimizations that are only valid for trivial functions.
> 326:          * <p>
> 327:          * Marking a function that is not trivial using this linker option is likely to have adverse effects,

Suggestion:

         * Using this linker option when linking non trivial functions is likely to have adverse effects,

test/jdk/java/foreign/trivial/TestTrivial.java line 46:

> 44: import static org.testng.Assert.assertEquals;
> 45: 
> 46: public class TestTrivial extends NativeTestHelper {

Should we perhaps have another subclass of `TestDowncallBase` to test all combinations - just in case?

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

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


More information about the panama-dev mailing list