supporting custom JVM intrinsics
Samuel Audet
samuel.audet at gmail.com
Mon Feb 4 00:53:58 UTC 2019
I think I've finally found what would satisfy me: custom JVM instrincs.
Vladimir's presentation about how linkToNative is implemented with those
is quite enlightening I find, thank you for your time on this:
http://cr.openjdk.java.net/~vlivanov/talks/2016_JVMLS_MachineCodeSnippets.pdf
Since we're creating new intrinsics for these machine code snippets, I'm
thinking, couldn't we extend the JVM and allow users to plug in custom
intrinsics at will? Right now the API isn't public, and varies with the
JVM, but what if it could be standardized and made extensible? I also
understand that they are hard to develop, but when I look at examples
like those below, and given a limited set of features to call native
functions, for starters, it seems like they could be generated without
too much hassle:
https://www.slideshare.net/RednaxelaFX/green-teajug-hotspotintrinsics02232013
https://gist.github.com/rednaxelafx/1986224
https://gist.github.com/rednaxelafx/db03ab15ef8b76246b84
JavaCPP is essentially already doing that with JNI. It could easily
generate code for JVM intrinsics, effectively targeting some mix of
C/C++ API and assembly code. The overall workflow could be something
like this:
- At build time:
1. Take high-level annotated methods from Java, possibly generated
with a tool like jextract
2. For each method, generate C/C++/assembly code for a custom JVM
intrinsic, probably with the help of a C/C++ compiler
3. Use the C/C++ compiler to build a native library that extends
the JVM as a plugin
- At runtime:
4. Load that native library either dynamically, if possible, or as
part of the JVM at boot
I don't see many disadvantages to such an approach:
- needs native wrappers, but Panama will already need those for inline
functions, macros, and C++ templates anyway
- requires a C/C++ compiler, but Panama already bundles Clang, so we can
reuse it when required
But I see many advantages:
- supports C++ just as efficiently as C
- bypasses all the complexities of system/C/C++ ABIs, supporting any C++
compiler, including MSVC
- paves the way to support inlining of native functions/macros/templates
- eventually making it possible for the community to map special CPU
instructions for performance--as third-party libraries
Now *that's* the kind of thing I would be interested in seeing happen!
Any chance of getting something like that out of Panama? If not, maybe
after Graal goes mainstream, it sounds a lot like its support for
"compiler intrinsics"...
http://lafo.ssw.uni-linz.ac.at/papers/2017_PLDI_GraalTutorial.pdf
Samuel
More information about the panama-dev
mailing list