Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraalVM + Nashorn Cannot extend classes

I'm attempting to use graal + nashorn interop to write nodejs that interacts with Java. I'm starting graal with node --jvm --jvm.Xss2m --jvm.Dtruffle.js.NashornJavaInterop=true --jvm.classpath=libs/ --polyglot app.js. I cannot extend a class though. The javascript code is

const GraaljsgrpcServiceImpl = Java.type('com.thing.GraaljsgrpcServiceImpl');
const HelloReply = Java.type('com.thing.HelloReply');
var GrpcImpl = Java.extend(GraaljsgrpcServiceImpl, {
    sayHello: function(request, responseObserver) {
        responseObserver.onNext(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
        responseObserver.onCompleted();
    }
});

and my error is TypeError: Could not determine a class loader with access to the JS engine and class com.thing.GraaljsgrpcServiceImpl This seems to point to a classloader issue with the java code I'm referencing and where the javascript is running(i.e. 2 different classloaders). Is there a way to pull this off when using graal/nodejs?

like image 700
William Thurston Avatar asked Mar 07 '26 19:03

William Thurston


1 Answers

Thanks for reporting this classloader problem. We are looking into that and should be able to fix that with our next release (0.32 expected early March).

Regarding the --jvm.Dtruffle.js.NashornJavaInterop=true flag: we strongly encourage not using that, but depending on the built-in interoperability of GraalVM. However, in this mode Graal.js is not 100% compatible with Nashorn/Rhino; for instance, we are not supporting Java.extend in that mode. Is Java.extend the only reason why you set the NashornJavaInterop flag?

Thanks, Christian

like image 54
Christian Wirth Avatar answered Mar 10 '26 13:03

Christian Wirth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!