quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Quarkus 1.3.0.Final class loader can not load Graal's polyglot framework #8035

Closed oleksiylukin closed 4 years ago

oleksiylukin commented 4 years ago

New class loader of Quarkus 1.3.0 can not load polyglot framework of GraalVM, Previous version (1.2.1) works fine.

Expected behavior JavaScript code works when executed inside of REST resource

Actual behavior Throws exception org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: No language and polyglot implementation was found on the classpath. Make sure the truffle-api.jar is on the classpath.

To Reproduce Create and run following simple resource:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.graalvm.polyglot.*;
import org.graalvm.polyglot.proxy.*;

@Path("/hello")
public class ExampleResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        String out = "From JS:";
        try (Context context = Context.create()) {
            Value function = context.eval("js", "x => x+1");
            assert function.canExecute();
            int x = function.execute(41).asInt();
            out=out+x;
        }
        return out;
    }
}

Configuration Simplest possible

Environment Linux alhp.alhome 5.5.9-200.fc31.x86_64 openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02) OpenJDK 64-Bit Server VM GraalVM CE 20.0.0 (build 11.0.6+9-jvmci-20.0-b02, mixed mode, sharing)

jaikiran commented 4 years ago

Hello @oleksiylukin, Is this a Maven project? What does the pom.xml dependencies look like?

stuartwdouglas commented 4 years ago

Can you share the full reproducer?

hotleave commented 4 years ago

Just got the same error:

MacOS 10.15.3

machi1990 commented 4 years ago

@hotleave can you also share a reproducer? Thanks

hotleave commented 4 years ago

@hotleave can you also share a reproducer? Thanks

Here is the demo: https://github.com/hotleave/code-with-quarkus

MacOS 10.15.3 GraalVM jdk8 20.0

run mvn quarkus:dev to start the project and visit: http://localhost:8080/hello

In ExampleResourceTest, just call the method directly, it works fine.

FYI

hotleave commented 4 years ago

Update: build the artifact build with mvn package, and run with java -jar target/xxxx-runner.jar works fine

stuartwdouglas commented 4 years ago

Even though QuarkusClassLoader delegates to the system class loader and the system class loader can load it fine, there is a check in service loader now that will ignore classes from named modules. Basically it looks like if the TCCL is anything other than the system CL, or a modular CL that exposes this module I don't know if there is any way to get this to work.

stuartwdouglas commented 4 years ago

For now you can work around this to some extent by temporarily setting the thread context classloader to ClassLoader.getSystemClassLoader().

jaikiran commented 4 years ago

Basically it looks like if the TCCL is anything other than the system CL, or a modular CL

I haven't checked the code yet, but all this is in JDK8? (of course leaving out the modular CL bit)

stuartwdouglas commented 4 years ago

I was testing on a JDK11 version of Graal.

alukin commented 4 years ago

Project to reproduce bug is here : https://github.com/alukin/polyglot-test-quarkus

oleksiylukin commented 4 years ago

It is impossible to build native image also. Th same exception occurs

lburgazzoli commented 4 years ago

I have not testes the reproducer but it looks like there some dependencies and set-up missing. Here some set-up I have in a project based on Quarkus 1.3.0.Final that sues JS:

hotleave commented 4 years ago

I have not testes the reproducer but it looks like there some dependencies and set-up missing. Here some set-up I have in a project based on Quarkus 1.3.0.Final that sues JS:

build native image with --language:js arguments works fine

alukin commented 4 years ago

I tried my small reproducer application with 1.3.1-Final and it does not work too as with 1.3.0.Final. I updated reproducer application pom.xml with Quarkus 1.2.1.Final to show that it works with previous 1.2.1.Final fine.

I use GraalVM version is 20.0.0-jdk11 in all cases.

Please see comments in pom.xml how to change version and reproduce this bug https://github.com/alukin/polyglot-test-quarkus

gsmet commented 4 years ago

@stuartwdouglas said https://github.com/quarkusio/quarkus/pull/8998 might fix that one.

jscottnz commented 4 years ago

Hello. I am using quarkus 1.6.0-Final and experiencing this error. I can work around it with the Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); method.

oleksiylukin commented 4 years ago

It is still the problem with Quarkus up to version 1.9.0-Final. Please see my reproducer application at https://github.com/alukin/polyglot-test-quarkus

It works when running it from the "runner" jar but does not work in development mode making it impossible to debug. Please, re-open this bug or any other related

abouhabb commented 3 years ago

@oleksiylukin and @hotleave , just add these lines on your pom.xml inside \ tag and quarkus:dev will work fine :

  <dependency>
      <groupId>org.graalvm.js</groupId>
      <artifactId>js</artifactId>
      <version>${graalvm.version}</version>
      <scope>runtime</scope>
   </dependency>

   <dependency>
      <groupId>org.graalvm.js</groupId>
      <artifactId>js-scriptengine</artifactId>
      <version>${graalvm.version}</version>
   </dependency>

working with quarkus platform version 1.9.0.Final and 1.9.2.Final (maybe other older version too)

I use quarkus with polyglot API in my project and it's working also in native build on Windows/Linux/Docker environment