Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM native #358

Open
ccleve opened this issue Sep 7, 2021 · 3 comments
Open

GraalVM native #358

ccleve opened this issue Sep 7, 2021 · 3 comments
Labels

Comments

@ccleve
Copy link

ccleve commented Sep 7, 2021

Is it possible to use the GraalVM native compiler to create a binary, and use that as an extension?

I asked about this on the Graal Slack quite some time ago, and they suggested that yes, it was possible to create a C-compatible .so library, but the instructions for doing so were unclear. They did identify these starting points:

https://github.com/kirillp/graalSamples/tree/master/simpleApp

https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.jvmtiagentbase/src/com/oracle/svm/jvmtiagentbase/AgentIsolate.java

I think that if we could get true native speed from a Postgres extension written in Java, or any polyglot language, it would be a real game-changer.

@jcflack
Copy link
Contributor

jcflack commented Sep 21, 2021

This is a good idea that has been at the back of my mind ever since I made sure PL/Java works with GraalVM, but I have not had time to test the native-image idea or develop a procedure for using it.

More of my effort at the moment is going toward refactoring PL/Java to make GraalVM polyglot languages more naturally accessible.

But native-image building is a worthwhile area to experiment in.

@jcflack
Copy link
Contributor

jcflack commented Oct 5, 2021

oracle/graal#2761 looks relevant, and if I'm reading it correctly, the right stuff should be there now since GrallVM 21.0.

Sounds like it will need some kind of configuration file to say what classes and methods will need to be included for method handles to point to. But that would be trivial to generate from pg_proc if starting with a database with a normal dynamic PL/Java installation and the desired functions already declared. Extra credit would be to generate it by parsing the DDR files in existing PL/Java jars. Or generate it from the annotation processor while compiling PL/Java sources.

@ccleve
Copy link
Author

ccleve commented Oct 5, 2021

I don't know enough to comment. I do know that they were very helpful on the Graal Slack and though this was a cool use of Graal. They seemed to think that this was totally possible. I just had a hard time understanding the syntax for making function calls, and also how to instantiate and manage the "Agent Isolate", which is apparently a giant uber object that manages memory, threads and everything. Somehow you have to create this object, maintain a reference to it, and pass it in as the first parameter on every function call from the outside world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants