我试图了解在 Java 应用程序中运行的 JavaScript 的性能,但我找不到通过 Bindings(在 Nashorn compat 模式下)和 Context 等 Java 接口(interface)传递 Truffle 选项的方法。
具体来说,我正在尝试打开以下内容中提到的编译信息--engine.TraceCompilation: https://www.graalvm.org/22.1/graalvm-as-a-platform/language-implementation-framework/Options/
但我发现的只是这样的例子:
ScriptEngine js = scriptEngineManager.getEngineByName("graal.js");
Bindings bindings = js.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowHostAccess", true);
bindings.put("polyglot.js.nashorn-compat", true);
// ------- I want to do something like this: -----------
bindings.put("polyglot.js.engine.TraceCompilation", true); // <-- does not work
//--------------------------------------------------------
本指南提到了可以通过这种方式传递的选项列表,但没有列出任何 Truffle 选项: https://www.graalvm.org/22.1/reference-manual/js/ScriptEngine/
请注意,由于遗留原因,我需要使用 Nashorn 兼容模式来运行 JavaScript 代码。
最佳答案
正如文档所述,这些是语言启动器选项。您通常会将它们提供给 js、node 或类似的启动器。
$ js --engine.TraceCompilation yourJSFile.js
正如您似乎从 Java 开始一样,您还可以通过系统属性将它们提供给 Java 进程(通过预先考虑 polyglot 并为 boolean 选项显式提供 true):
$ java -Dpolyglot.engine.TraceCompilation=true yourJavaClass
我不相信您可以在语言绑定(bind)中提供这些选项,因为它们不应该影响语言,而是影响整个 GraalVM 系统。 (这也是为什么您的 polyglot.js.engine.TraceCompilation 关闭;该选项与 js 无关)
克里斯蒂安·HTH
关于javascript - GraalVM JS : How I do pass Truffle options via Bindings (Nashorn compat mode) and Context in a Java application?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72069844/