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

Java truffle native image #572

Merged
merged 4 commits into from
Jul 11, 2021
Merged

Conversation

mmcgill
Copy link
Contributor

@mmcgill mmcgill commented Jun 6, 2021

This PR addresses #568, fixing issues that prevented the compilation of GraalVM native images
for the java-truffle Mal implementation.

In addition, a make-native.sh convenience script has been provided for those who wish to try building native images themselves. I have not changed the Makefile or run script to use native images, as each step takes almost a minute to build on my machine. There may also be some stability issues with the AOT compilation process; out ~40 compilation attempts, I had 2 SIGSEGV crashes that were not repeatable.

GraalVM native image compilation wasn't working due to
some missing @TruffleBoundary annotations, and calls
from partially evaluated code into methods that are
black-listed for runtime compilation.

With these changes, a GraalVM native image should be
producable from every Mal step.
@wasamasa
Copy link
Collaborator

wasamasa commented Jun 6, 2021

Sorry for the stupid question, but since when are step B to E a thing?

@mmcgill
Copy link
Contributor Author

mmcgill commented Jun 6, 2021

Sorry for the stupid question, but since when are step B to E a thing?

They're totally not :) I was trying to stick with Mal's pedagogical approach, and add some Truffle-specific optimizations in stepwise fashion so that readers could follow along. Hopefully I haven't muddled things too much in the process.

@borkdude
Copy link

borkdude commented Jun 7, 2021

@mmcgill I am trying this out locally. When running gradle build I get:

$ gradle build

> Configure project :
/private/tmp/mal/impls/java-truffle/build/classes/java/main:/private/tmp/mal/impls/java-truffle/build/resources/main:/Users/borkdude/.m2/repository/org/graalvm/truffle/truffle-api/21.1.0/truffle-api-21.1.0.jar:/Users/borkdude/.gradle/caches/modules-2/files-2.1/org.organicdesign/Paguro/3.2.0/c437a15a2eb0a1f3efbdbf995c7ee8c988201963/Paguro-3.2.0.jar

> Task :compileJava FAILED
/private/tmp/mal/impls/java-truffle/src/main/java/truffle/mal/step3_env.java:9: error: package org.graalvm.polyglot does not exist
import org.graalvm.polyglot.Context;

followed by lots of other similar errors. What should I do to fix this?

EDIT: never mind, got it working when setting:

export JAVA_HOME=$GRAALVM_HOME

@borkdude
Copy link

borkdude commented Jun 7, 2021

Confirming the native image works on my machine too!

@mmcgill
Copy link
Contributor Author

mmcgill commented Jun 7, 2021

Confirming the native image works on my machine too!

\o/ Thanks for checking :D

@mmcgill I am trying this out locally. When running gradle build I get:

$ gradle build

> Configure project :
/private/tmp/mal/impls/java-truffle/build/classes/java/main:/private/tmp/mal/impls/java-truffle/build/resources/main:/Users/borkdude/.m2/repository/org/graalvm/truffle/truffle-api/21.1.0/truffle-api-21.1.0.jar:/Users/borkdude/.gradle/caches/modules-2/files-2.1/org.organicdesign/Paguro/3.2.0/c437a15a2eb0a1f3efbdbf995c7ee8c988201963/Paguro-3.2.0.jar

> Task :compileJava FAILED
/private/tmp/mal/impls/java-truffle/src/main/java/truffle/mal/step3_env.java:9: error: package org.graalvm.polyglot does not exist
import org.graalvm.polyglot.Context;

followed by lots of other similar errors. What should I do to fix this?

Apologies, I didn't think through the implications of excluding the graal-sdk dependency of truffle-api, which is there specifically to ensure compilation on JDKs other than Graal. I added that as a hack to work around classpath issues in Eclipse after importing the Gradle project, There's almost certainly a more correct way to accomplish the goal, so I'll remove the exclusion.

I added the exclusion as a hack to work around classpath
issues after importing the project into Eclipse, but this
isn't the right thing to do.

It prevents compilation on JDKs other than Graal, which was
not my intent.
@kanaka
Copy link
Owner

kanaka commented Jul 11, 2021

Finally getting around to merging this. Thanks @mmcgill @borkdude for getting to the bottom of this!

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

Successfully merging this pull request may close these issues.

4 participants