[External] : RE: Opt-in for trivial native method calls

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Jun 2 17:58:28 UTC 2022


On 02/06/2022 17:11, Jorn Vernee wrote:
>>
>> Could you explain what you mean by "there are much better 
>> solutions."? As I cannot think of any solution other than forking 
>> OpenJDK or using JVMCI
>
> I'm talking about adding a Java API + Intrinsic. Forking OpenJDK and 
> implementing it yourself would be one way to do that. Filing an 
> enhancement request would be another.

Note that in the context of Project Panama, Vlad did some great work on 
this subject; code name is "Machine code snippets"

http://mail.openjdk.java.net/pipermail/panama-dev/2015-December/000225.html

Basically, what this does is to capture a piece of machine code as a 
MethodHandle. You will see in the email that Vlad is referring to the 
same problems you are referring to.

While the technilogy underneat this is solid (and actually very in sync 
with the Linker API, which also produces a method handle out of some 
"foreign" gunk), the main problem is expressing the computation that 
goes in the method handle. Using hardcoded strings is too "raw", and not 
a way to go about this that feels right for the Java language. What we'd 
prefer is some sort of lambda expression which constructs a computation 
tree out of some API; this computation would not be compiled down into 
bytecode, but is instead kept in a more general IR, which the Java 
runtime can then turn into something more suitable, like an intrinsic 
(these techniques are also known as "quoting", and are available in some 
languages such as C# [1], and F# [2] among others).

Maurizio

[1] - 
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/
[2] - 
https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/code-quotations




More information about the panama-dev mailing list