You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [GraalVM Polyglot API](https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/package-summary.html) lets you embed and run code from guest languages in Java host applications.
29
29
30
-
Throughout this section, you will learn how to create a host application in Java that runs on GraalVM and directly calls a guest language.
30
+
Throughout this section, you will learn how to create a host application in Java that runs on GraalVM and directly calls a guest language.
31
31
You can use the tabs beneath each code example to choose between JavaScript, R, Ruby, and Python.
32
32
33
33
> Note: The usage description for polyglot embeddings was revised with GraalVM for JDK 21 and Polyglot API version 23.1.0. If you are still using Polyglot API version older than 23.1.0, ensure the correct version of the documentation is displayed. More information on the change can be found in the [release notes](https://www.graalvm.org/release-notes/JDK_21/#graalvm-for-jdk-21).
@@ -40,23 +40,23 @@ See the [polyglot embedding demonstration](https://github.com/graalvm/polyglot-e
40
40
41
41
Here is an example Maven dependency setup that you can put into your project:
<!-- Select a tool: profiler, inspect, coverage, dap, tools -->
59
-
<artifactId>profiler</artifactId>
59
+
<artifactId>profiler</artifactId>
60
60
<version>${graalvm.polyglot.version}</version>
61
61
<type>pom</type>
62
62
</dependency>
@@ -68,7 +68,7 @@ Language and tool dependencies use the [GraalVM Free Terms and Conditions (GFTC)
68
68
To use community-licensed versions instead, add the `-community` suffix to each artifact (for example, `js-community`).
69
69
To access [polyglot isolate](#polyglot-isolates) artifacts, use the `-isolate` suffix instead (for example, `js-isolate`).
70
70
71
-
The artifacts `languages` and `tools` include all available languages and tools as dependencies.
71
+
The artifacts `languages` and `tools` include all available languages and tools as dependencies.
72
72
This artifact might grow or shrink between major releases.
73
73
We recommend selecting only the needed language(s) for a production deployment.
74
74
@@ -125,13 +125,12 @@ You can use this application with other code examples to demonstrate more advanc
125
125
126
126
Polyglot applications let you take values from one programming language and use them with other languages.
127
127
128
-
Use the code example in this section with your polyglot application to show how the Polyglot API can return JavaScript, Python, or Ruby functions as Java values.
128
+
Use the code example in this section with your polyglot application to show how the Polyglot API can return JavaScriptor Python functions as Java values.
@@ -425,7 +420,7 @@ This table shows the level of optimizations the Java runtimes currently provide:
425
420
***Optimized with additional compiler passes:** Oracle GraalVM implements additional optimizations performed during runtime compilation. For example, it uses a more advanced inlining heuristic. This typically leads to better runtime performance and memory consumption.
426
421
***Optimized via VM option:** Optimization is enabled by specifying `-XX:+EnableJVMCI` to the `java` launcher.
427
422
***Optimized via VM option and `--upgrade-module-path`:** Optimization is enabled by specifying `-XX:+EnableJVMCI` to the `java` launcher. Additionally, the Graal compiler must be downloaded as a JAR file and specified to the `java` launcher with `--upgrade-module-path`. In this mode, the compiler runs as a Java application and may negatively affect the execution performance of the host application.
428
-
***No runtime optimizations:** With no runtime optimizations or if JVMCI is not enabled, the guest application code is executed in interpreter-only mode.
423
+
***No runtime optimizations:** With no runtime optimizations or if JVMCI is not enabled, the guest application code is executed in interpreter-only mode.
429
424
***JVMCI:** Refers to the [Java-Level JVM Compiler Interface](https://openjdk.org/jeps/243) supported by most Java runtimes.
430
425
431
426
A project has been created to enable runtime optimization by default for Oracle JDK and OpenJDK.
@@ -442,8 +437,8 @@ Execution without runtime compilation will negatively impact the guest applicati
442
437
443
438
This indicates that the guest application is executed with no runtime optimizations enabled.
444
439
The warning can be suppressed by either suppressing using the `--engine.WarnInterpreterOnly=false` option or the `-Dpolyglot.engine.WarnInterpreterOnly=false` system property.
445
-
In addition, the `compiler.jar` file and its dependencies must be downloaded from [Maven Central](https://central.sonatype.com/artifact/org.graalvm.compiler/compiler/) and referred to use the option `--upgrade-module-path`.
446
-
Note that `compiler.jar` must *not* be put on the module or class path.
440
+
In addition, the `compiler.jar` file and its dependencies must be downloaded from [Maven Central](https://central.sonatype.com/artifact/org.graalvm.compiler/compiler/) and referred to use the option `--upgrade-module-path`.
441
+
Note that `compiler.jar` must *not* be put on the module or class path.
447
442
Refer to the [polyglot embedding demonstration](https://github.com/graalvm/polyglot-embedding-demo) for an example configuration using Maven or Gradle.
448
443
449
444
### Switching to the Fallback Engine
@@ -736,7 +731,7 @@ public class PolyglotIsolate {
736
731
try (Context context = Context.newBuilder("js")
737
732
.allowHostAccess(HostAccess.SCOPED)
738
733
.option("engine.SpawnIsolate", "true").build()) {
739
-
734
+
740
735
Value function= context.eval("js", "x => x+1");
741
736
assert function.canExecute();
742
737
int x = function.execute(41).asInt();
@@ -1091,7 +1086,7 @@ public final class CHANGE_NAME_EngineFactory implements ScriptEngineFactory {
1091
1086
private static final String LANGUAGE_ID = "<<INSERT LANGUAGE ID HERE>>";
1092
1087
```
1093
1088
1094
-
Rename the class as desired and change the `LANGUAGE_ID` to the desired Truffle language (for example, "python" for GraalPy or "ruby" for TruffleRuby).
1089
+
Rename the class as desired and change the `LANGUAGE_ID` to the desired Truffle language (for example, "python" for GraalPy or "js" for GraalJS).
1095
1090
To use it, include a `META-INF/services/javax.script.ScriptEngineFactory` file in your resources with the chosen class name.
1096
1091
This will allow the default `javax.script.ScriptEngineManager` to discover the language automatically.
1097
1092
Alternatively, the factory can be registered via `javax.script.ScriptEngineManager#registerEngineName` or instantiated and used directly.
GraalVM provides runtimes for JavaScript, Ruby, Python, and a number of other popular languages.
10
+
GraalVM provides runtimes for JavaScript, Python, and a number of other languages.
11
11
GraalVM's polyglot capabilities make it possible to mix multiple programming languages in a single application while eliminating any foreign language call costs.
12
12
13
13
If you are mostly interested in a specific language runtime on GraalVM, see the following:
0 commit comments