本文介绍了如何使用graaljs?有没有地方可以获得.jar文件/文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java 8并使用默认的JavaScript引擎(Nashorn)。

I use Java 8 and I use the default JavaScript Engine (Nashorn).

我想看看它与'高度炒作'的GRAAL JS相比如何。
请参阅:

I would like to see how it compares with the 'highly hyped' GRAAL JS.See:




  • https://github.com/graalvm/graaljs
  • https://www.graalvm.org/

特别是因为我听说他们想弃用nashorn:

particularly because I hear they want to deprecate nashorn:



  • http://openjdk.java.net/jeps/335

有人知道如何(轻松)访问graaljs吗?
我希望找到一个pom.xml或一个下载jar文件的地方
但不是运气

Does anybody know how to get access (easily) to graaljs ?I was hoping to find a pom.xml or a place where to download a jar filebut not luck

推荐答案

目前在GraalVM之外没有预制的Graal.js罐子。要在其他JDK上运行它,您可以从GraalVM中提取jar或者像这样构建它:

At the moment there are no pre-built jars of Graal.js available outside of GraalVM. To run it on an other JDK, you can extract the jars from GraalVM or build it like this:

$ git clone [email protected]:graalvm/graaljs.git
$ git clone [email protected]:graalvm/mx.git
$ export PATH=$PWD/mx:$PATH
$ export JAVA_HOME=/usr/java/jdk1.8.0_161
$ cd graaljs/graal-js
$ mx build

请注意,它在JDK 8中运行良好。它还在JDK 8上运行:

Note that it built fine with JDK 8. It also runs on JDK 8:

$ mx js
> typeof([] + 1)
string
>

shell工作, + 退出它。上一个命令行中的 -v 选项显示了它如何启动它:

The shell works, + exits it. The -v option in the previous command line shows how it launches it:

$ mx -v js
...
env JAVA_HOME=/usr/java/jdk1.8.0_161 ... \
/usr/java/jdk1.8.0_161/bin/java -d64 -cp /tmp/graal-js/graal/sdk/mxbuild/dists/graal-sdk.jar:/tmp/graal-js/graal/truffle/mxbuild/dists/truffle-api.jar:/tmp/graal-js/graal/tools/mxbuild/dists/truffle-profiler.jar:/tmp/graal-js/graal/tools/mxbuild/dists/chromeinspector.jar:/tmp/graal-js/graal/sdk/mxbuild/dists/launcher-common.jar:/tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs-launcher.jar:/tmp/graal-js/graal/regex/mxbuild/dists/tregex.jar:/home/gmdubosc/.mx/cache/ASM_DEBUG_ALL_702b8525fcf81454235e5e2fa2a35f15ffc0ec7e.jar:/home/gmdubosc/.mx/cache/ICU4J_6f06e820cf4c8968bbbaae66ae0b33f6a256b57f.jar:/tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs.jar -Dtruffle.js.BindProgramResult=false -Xms2g -Xmx2g -Xss16m com.oracle.truffle.js.shell.JSLauncher

所以它就是这些类路径上的jar:

So it puts those jars on the classpath:


  • / tmp / graal-js / graal / sdk / mxbuild / dists / graal- sdk.jar

  • /tmp/graal-js/graal/truffle/mxbuild/dists/truffle-api.jar

  • /tmp/graal-js/graal/tools/mxbuild/dists/truffle-profiler.jar

  • /tmp/graal-js/graal/tools/mxbuild/dists/chromeinspector.jar

  • /tmp/graal-js/graal/sdk/mxbuild/dists/launcher-common.jar

  • /tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs-launcher.jar

  • / tmp / graal-js / graal / regex / mxbuild / dists / tregex.jar

  • /home/gmdubosc/.mx/cache/ASM_DEBUG_ALL_702b8525fcf81454235e5e2fa2a35f15ffc0ec7e .jar

  • /home/gmdubosc/.mx/cache/ICU4J_6f06e820cf4c8968bbbaae66ae0b33f6a256b57f.jar

  • /tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs.jar

  • /tmp/graal-js/graal/sdk/mxbuild/dists/graal-sdk.jar
  • /tmp/graal-js/graal/truffle/mxbuild/dists/truffle-api.jar
  • /tmp/graal-js/graal/tools/mxbuild/dists/truffle-profiler.jar
  • /tmp/graal-js/graal/tools/mxbuild/dists/chromeinspector.jar
  • /tmp/graal-js/graal/sdk/mxbuild/dists/launcher-common.jar
  • /tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs-launcher.jar
  • /tmp/graal-js/graal/regex/mxbuild/dists/tregex.jar
  • /home/gmdubosc/.mx/cache/ASM_DEBUG_ALL_702b8525fcf81454235e5e2fa2a35f15ffc0ec7e.jar
  • /home/gmdubosc/.mx/cache/ICU4J_6f06e820cf4c8968bbbaae66ae0b33f6a256b57f.jar
  • /tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs.jar

查看构建工件,我们可以另请参阅 mxbuild / dists / graaljs-scriptengine.jar ,它负责使用脚本引擎API注册Graal.js.

Looking into the build artifacts we can also see mxbuild/dists/graaljs-scriptengine.jar which is responsible for registering Graal.js with the script engine API.

使用小型测试文件:

import javax.script.*;
import java.util.Arrays;
public class Test {
  public static void main(String... args) throws ScriptException {
    ScriptEngineManager manager = new ScriptEngineManager();
    for (ScriptEngineFactory factory : manager.getEngineFactories()) {
      System.out.printf("%s %s: %s %s%n", factory.getLanguageName(), factory.getLanguageVersion(), factory.getEngineName(), factory.getNames());
    }
    ScriptEngine engine = manager.getEngineByName("Graal.js");
    if (engine != null) {
      Object result = engine.eval("typeof([] + 1)");
      System.out.println(result);
    }
  }
}

编译并运行它股票JDK 8给出:

Compiling and running it on a stock JDK 8 gives:

$ javac Test.java
$ java -cp . Test
ECMAScript ECMA - 262 Edition 5.1: Oracle Nashorn [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]

现在在类路径上使用Graal.js:

Now with Graal.js on the classpath:

$ java -cp /tmp/graal-js/graal/sdk/mxbuild/dists/graal-sdk.jar:/tmp/graal-js/graal/truffle/mxbuild/dists/truffle-api.jar:/tmp/graal-js/graal/regex/mxbuild/dists/tregex.jar:/home/gmdubosc/.mx/cache/ASM_DEBUG_ALL_702b8525fcf81454235e5e2fa2a35f15ffc0ec7e.jar:/home/gmdubosc/.mx/cache/ICU4J_6f06e820cf4c8968bbbaae66ae0b33f6a256b57f.jar:/tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs.jar:/tmp/graal-js/graaljs/graal-js/mxbuild/dists/graaljs-scriptengine.jar:. Test
ECMAScript ECMA - 262 Edition 6: Graal.js [Graal.js, graal.js, Graal-js, graal-js, Graal.JS, Graal-JS, GraalJS, GraalJSPolyglot, js, JS, JavaScript, javascript, ECMAScript, ecmascript]
ECMAScript ECMA - 262 Edition 5.1: Oracle Nashorn [nashorn, Nashorn, null, null, null, null, null, null]
string

(请注意,此命令行忽略 truffle-profiler chromeinspector launcher-common graaljs-launcher 使用Graal时不需要这些。 js通过脚本引擎。)

(note that this command line ignores truffle-profiler, chromeinspector, launcher-common and graaljs-launcher which are not necessary when using Graal.js through the script engine.)

由于标准JDK 8不支持JVMCI和/或Graal编译器,因此JS不会有JIT编译,所以不要在性能方面要求很高。要获得性能,您需要特殊的JDK 8或JDK 9+以及Graal-Truffle绑定。

Since the standard JDK 8 doesn't support JVMCI and/or the Graal compiler, there will be no JIT compilations for JS so don't expect much in terms of performance. To get performance you need a special JDK 8 or JDK 9+ as well as the Graal-Truffle bindings.

这篇关于如何使用graaljs?有没有地方可以获得.jar文件/文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 03:07