[graalvm-users] Migrate from Nashhorn JSR 223 Scripting Engine to Graal

Andreas Mueller am at iit.de
Fri Jun 22 05:05:02 PDT 2018


Hi Christian,

thanks. After adding the jars to the classpath, the engine was available. 

However, I’m getting this while evaluating a script:

javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: INVOKE on JavaObject[IntervalTimer{name='scheduler', millis=0} (com.swiftmq.impl.streams.comp.timer.IntervalTimer)] failed due to: UnsupportedTypeException
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:183)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:155)
	at com.swiftmq.impl.streams.StreamController.evalScript(Unknown Source)
	at com.swiftmq.impl.streams.StreamController.start(Unknown Source)

The script does this:

stream.create().timer("scheduler").interval().seconds(interval).onTimer(function (timer) {
...
}

The Java class “IntervalTimer” has this “seconds” and “onTimer" methods:

public IntervalTimer seconds(int n) {
    millis += (long) n * 1000L;
    return this;
}

    @Override
    public Timer onTimer(TimerCallback callback) {
        this.callback = callback;
        return this;
    }


Any hints?

Thanks,
Andreas

-- 
Andreas Mueller
IIT Software GmbH
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.swiftmq.com&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=TP6vDFIvOwHIJubzP5a3mC1OLNpov_7VuXVjRKUILpY&s=9FM150Blv30fDT3EnnLT4BX13ZpAdhoPfJbyD5QbUwM&e=



> On 22 Jun 2018, at 09:48, Christian Wirth <christian.wirth at oracle.com> wrote:
> 
> Hi Andreas,
> 
> currently, we strongly endorse the use of GraalVM. That guarantees that you use Graal JavaScript with Graal as optimizing compiler.
> 
> What you tried to achieve will work; note, however, that in such a setup (on JDK 8) Graal is NOT used as optimzing compiler (but HotSpot Server Compiler C2 is), thus the performance of Graal JavaScript will likely be much worse than it would be on GraalVM. 
> 
> Your commandline was probably missing the $GRAALVM/jre/lib/boot/graaljs-scriptengine.jar file? I am using a commandline like:
> 
>    GRAALVM=/path/to/GraalVM
>    /path/to/jdk8/bin/java -cp $GRAALVM/jre/languages/js/graaljs.jar:$GRAALVM/jre/lib/truffle/truffle-api.jar:$GRAALVM/jre/lib/boot/graal-sdk.jar:$GRAALVM/jre/lib/boot/graaljs-scriptengine.jar:$GRAALVM/jre/tools/regex/tregex.jar:. MyJavaApp
> 
> In MyJavaApp, you can start Graal JavaScript via ScriptEngine; it registers under several names, including "graal.js". Again, note that performance will be suboptimal this way; use GraalVM for better results.
> 
> For JDK 11 and beyond, you can execute Graal JavaScript with Graal as optimizing compiler on a stock JVM already. We are currently working on improved packaging/modularizing and should be able to publish some documentation on that in the coming weeks.
> 
> Best,
> Christian Wirth
> Graal JavaScript team
> 
> 
> 
> 
>> From: Andreas Mueller <am at iit.de>
>> Subject: [graalvm-users] Migrate from Nashhorn JSR 223 Scripting Engine to Graal
>> Date: 18 June 2018 at 15:05:22 CEST
>> To: graalvm-users at oss.oracle.com
>> 
>> Hi,
>> 
>> I was cold hitted by the announcement that Nashorn might be deprecated in future. Since we have a lot JS scripts implemented that run on the JVM and interact with Java very well, I need an alternative JSR 223 JavaScript engine. So GraalVM comes to mind (and is suggested).
>> 
>> GraalVM seems to me a JDK replacement rather than a scripting engine. I downloaded it but didn’t find a jar file (such as graaljs.jar) that contains the JSR 223 engine and that I just add to the classpath of a legacy JDK 1.8.x and then it is automatically available when I list the engines.
>> 
>> Can anybody tell me how I can achieve this?
>> 
>> Thanks,
>> Andreas
>> 
>> -- 
>> Andreas Mueller
>> IIT Software GmbH
>> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.swiftmq.com&d=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=TP6vDFIvOwHIJubzP5a3mC1OLNpov_7VuXVjRKUILpY&s=9FM150Blv30fDT3EnnLT4BX13ZpAdhoPfJbyD5QbUwM&e=
>> 
>> <swiftmq_logo_positiv.png>
>> 
>> 
>> 
>> IIT Software GmbH
>> Falkenhorst 11, 48155 Münster, Germany
>> Phone: +49 (0)251 39 72 99 00
>> Managing Director: Andreas Müller
>> District Court: Amtsgericht Münster, HRB 16294
>> VAT-No: DE199945912
>> 
>> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
>> _______________________________________________
>> GraalVM-Users mailing list
>> GraalVM-Users at oss.oracle.com
>> https://oss.oracle.com/mailman/listinfo/graalvm-users
> 
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users



IIT Software GmbH
Falkenhorst 11, 48155 Münster, Germany
Phone: +49 (0)251 39 72 99 00
Managing Director: Andreas Müller
District Court: Amtsgericht Münster, HRB 16294
VAT-No: DE199945912

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20180622/03c05bfd/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swiftmq_logo_positiv.png
Type: image/png
Size: 10241 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/graalvm-users/attachments/20180622/03c05bfd/attachment-0001.png 


More information about the GraalVM-Users mailing list