2

I am migrating a Javascript engine from Nashorn to GraalVm and it's failing to instantiate GraalJSScriptEngine/ScriptEngine. I tried different ways of doing it:

GraalJSEngineFactory factory =  new GraalJSEngineFactory();
GraalJSScriptEngine engine = factory.getScriptEngine();
GraalJSScriptEngine engine = GraalJSScriptEngine.create(
            null,
            Context.newBuilder("js")
                .allowHostAccess(HostAccess.ALL)
                .allowHostClassLookup(s -> true)
        );

I am getting following errors for above:

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.oracle.truffle.js.scriptengine.GraalJSEngineFactory could not be instantiated

java.lang.AbstractMethodError: Receiver class com.oracle.truffle.polyglot.PolyglotImpl does not define or inherit an implementation of the resolved method abstract buildEngine(Ljava/io/OutputStream;Ljava/io/OutputStream;Ljava/io/InputStream;Ljava/util/Map;JLjava/util/concurrent/TimeUnit;ZJZZZLorg/graalvm/polyglot/io/MessageTransport;Ljava/lang/Object;Lorg/graalvm/polyglot/HostAccess;)Lorg/graalvm/polyglot/Engine; of abstract class org.graalvm.polyglot.impl.AbstractPolyglotImpl.
ScriptEngine engine = new ScriptEngineManager().getEngineByName("graal.js");

It returns null while doing like ^. Also I noticed there is only one factory(Nashorn) present in ScriptEngineManager instance.

I have added truffle-api jar in classpath as well as runnning it with VM options: -ea -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Dpolyglot.js.nashorn-compat=true

I'm running it on Java 13 with the following additional dependencies:

         <dependency>
            <groupId>org.graalvm.sdk</groupId>
            <artifactId>graal-sdk</artifactId>
            <version>19.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.graalvm.js/js -->
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>19.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.graalvm.js/js-scriptengine -->
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>19.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.graalvm.compiler/compiler -->
        <dependency>
            <groupId>org.graalvm.compiler</groupId>
            <artifactId>compiler</artifactId>
            <version>19.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.graalvm.truffle</groupId>
            <artifactId>truffle-api</artifactId>
        </dependency>
rajnikant7008
  • 76
  • 2
  • 10
  • Is it safe to assume you are working of https://github.com/graalvm/graal-js-jdk11-maven-demo as a starting point? – BoriS Nov 05 '19 at 21:07
  • Yeah, I have started with that but the instantiation of GraalJSScriptEngine/ScriptEngine is failing, do I need specific JDK? – rajnikant7008 Nov 06 '19 at 08:49
  • 2
    Ah, I just noticed that you are running on JDK13. There are some issues already reported with running on JDK13 (https://github.com/oracle/graal/issues/1751). Should work with JDK11 or 12. – BoriS Nov 06 '19 at 15:52
  • facing the same issue on JDK8. did you find the solution? – z3r0 Oct 06 '20 at 14:07
  • Yes! I was able to proceed with GraalJSEngineFactory factory = new GraalJSEngineFactory(); GraalJSScriptEngine engine = GraalJSScriptEngine.create( null, Context.newBuilder("js") .allowHostAccess(HostAccess.ALL) .allowHostClassLookup(s -> true) .allowAllAccess(true) ); – rajnikant7008 Oct 07 '20 at 15:25
  • But still waiting on https://github.com/graalvm/graaljs/issues/143 as it's not fully ready yet. – rajnikant7008 Oct 07 '20 at 15:26

0 Answers0