Last active
September 13, 2022 08:58
-
-
Save dmikurube/00a22d70d2a0344be29028a16c7818b3 to your computer and use it in GitHub Desktop.
Try Graal on Stock JVM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id "java" | |
id "application" | |
} | |
configurations { | |
compileClasspath.resolutionStrategy.activateDependencyLocking() | |
runtimeClasspath.resolutionStrategy.activateDependencyLocking() | |
// https://github.com/daemontus/gradle-graal-truffle-plugins/blob/4f7268d27c37fef061521c0f6fe94dac625d76fe/src/main/java/com/oracle/truffle/gradle/CompilerPlugin.java | |
graalCompiler { | |
visible = false | |
canBeResolved = true | |
description = "Graal compiler and its dependencies." | |
resolutionStrategy.activateDependencyLocking() | |
} | |
} | |
repositories { | |
mavenCentral() | |
} | |
java { | |
toolchain { | |
languageVersion = JavaLanguageVersion.of(17) | |
} | |
withJavadocJar() | |
withSourcesJar() | |
} | |
tasks.withType(JavaCompile) { | |
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked" | |
options.encoding = "UTF-8" | |
} | |
sourceSets { | |
main { | |
java { | |
srcDir '.' | |
} | |
} | |
} | |
dependencies { | |
implementation "org.graalvm.sdk:graal-sdk:22.2.0" | |
implementation "org.graalvm.js:js:22.2.0" | |
graalCompiler "org.graalvm.compiler:compiler:22.2.0" | |
} | |
task prepareGraalCompiler(type: Copy) { | |
from configurations.graalCompiler | |
into "${buildDir}/graalCompiler" | |
} | |
// Add required JVM options for all Java executing tasks. | |
tasks.withType(JavaForkOptions) { task -> | |
task.dependsOn("prepareGraalCompiler") | |
task.doFirst { t -> | |
// When it is already running on GraalVM, the compiler is already there. | |
if (!System.getProperty("java.vendor.version", "").contains("GraalVM") | |
&& !System.getProperty("java.vm.name", "").contains("GraalVM")) { | |
// Expects running a JVM that supports JVMCI. | |
t.jvmArgs( | |
"-XX:+UnlockExperimentalVMOptions", | |
"-XX:+EnableJVMCI", | |
"--module-path=${buildDir}/graalCompiler", | |
"--upgrade-module-path=${buildDir}/graalCompiler") | |
} | |
} | |
} | |
application { | |
mainClass = "TryGraalOnStockJvm" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a Gradle generated file for dependency locking. | |
# Manual edits can break the build and are not advised. | |
# This file is expected to be part of source control. | |
com.ibm.icu:icu4j:71.1=compileClasspath,runtimeClasspath | |
org.graalvm.compiler:compiler:22.2.0=graalCompiler | |
org.graalvm.js:js:22.2.0=compileClasspath,runtimeClasspath | |
org.graalvm.regex:regex:22.2.0=compileClasspath,runtimeClasspath | |
org.graalvm.sdk:graal-sdk:22.2.0=compileClasspath,graalCompiler,runtimeClasspath | |
org.graalvm.truffle:truffle-api:22.2.0=compileClasspath,graalCompiler,runtimeClasspath | |
empty= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.graalvm.polyglot.Context; | |
public class TryGraalOnStockJvm { | |
public static void main(final String[] args) { | |
final Context context = Context.newBuilder().logHandler(System.err).build(); | |
context.eval("js", "print('Hello, GraalJS!');"); | |
} | |
} |
Author
dmikurube
commented
Sep 13, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment