oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.98k stars 1.6k forks source link

(Espresso) A language with id 'js' is not installed. Installed languages are: [java]. #7680

Open kohlschuetter opened 8 months ago

kohlschuetter commented 8 months ago

Describe GraalVM and your environment :

Have you verified this issue still happens when using the latest snapshot? Yes.

Describe the issue

I'm using the following Maven dependencies in my library project to use GraalJS so I can execute some JavaScript code.

        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>23.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>js</artifactId>
            <version>23.1.1</version>
            <type>pom</type>
        </dependency>

The code is supposed to be compatible with all Java VMs version 17 and above.

It all works fine on regular Hotspot-based VMs, apart from a separate issue on OpenJ9 (tracked in https://github.com/oracle/graal/issues/7679). However, when running on an Espresso JVM, the following exception is thrown when launching the code:

java.lang.IllegalArgumentException: A language with id 'js' is not installed. Installed languages are: [java].

Code snippet or code repository that reproduces the issue

org.graalvm.polyglot.Context.newBuilder("js").engine(org.graalvm.polyglot.Engine.newBuilder().build()).build();

Steps to reproduce the issue

  1. Compile a class that executes the above code snippet.
  2. Run with regular GraalVM (succeeds)
  3. Run with OpenJDK 17 (succeeds)
  4. Run with GraalVM-Espresso (fails with exception)

Expected behavior The code should execute in all three environments.

Additional context Add any other context about the problem here. Specially important are stack traces or log output. Feel free to link to gists or to screenshots if necesary

[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[engine] WARNING: The polyglot engine uses a fallback runtime that does not support runtime compilation to native code.
Execution without runtime compilation will negatively impact the guest application performance.
The following cause was found: JVMCI is not enabled for this JVM. Enable JVMCI using -XX:+EnableJVMCI.
For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/.
To disable this warning use the '--engine.WarnInterpreterOnly=false' option or the '-Dpolyglot.engine.WarnInterpreterOnly=false' system property.
Exception in thread "main" java.lang.IllegalArgumentException: A language with id 'js' is not installed. Installed languages are: [java].
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineException.illegalArgument(PolyglotEngineException.java:129)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.throwNotInstalled(PolyglotEngineImpl.java:1173)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.requirePublicLanguage(PolyglotEngineImpl.java:1180)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.requirePublicLanguage(PolyglotContextImpl.java:1705)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.lookupLanguageContext(PolyglotContextImpl.java:1667)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1676)
    at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:60)
    at org.graalvm.polyglot/org.graalvm.polyglot.Context.eval(Context.java:402)
    at com.kohlschutter...
mukel commented 8 months ago

Thanks for the excellent bug report!

I assume that GraalVM-Espresso refers to the standalone builds listed here. The Espresso standalone is a legacy GraalVM, the issue is not caused by Espresso but from this legacy (before Truffle Unchained) distribution. Running on HotSpot e.g. $ESPRESSO_STANDALONE/bin/java -server ... fails in the same way.

As a workaround you can run with -Dgraalvm.locatorDisabled=true. I tested your snippet and it works fine.

I would advice against running other Truffle languages within Espresso, because these inner languages will run in interpreted mode only. Ideally, you'd embed Espresso as a sibling to other languages within the same polyglot context.