问题标签 [graalvm]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
12696 浏览

spring - 将 Spring 应用程序编译为 GraalVM 原生镜像

GraalVM 系统显然无法将 Spring 应用程序编译为原生镜像。

我们是否可以编译 Spring 应用程序的一个子集——比如说,作为一个单独的库——然后将其与使用通常的 javac 编译器编译的其余部分一起使用?

或者,如果我们从应用程序中遗漏了一些 Spring 特性?

还有其他可能吗?

0 投票
1 回答
610 浏览

graalvm - 如何使用 Graalvm 对 java 进行沙箱处理

graal 可以在创建上下文时对 js、ruby 和其他语言进行沙箱处理,但是如何对动态加载的 jar 进行沙箱处理?例如,在 flink 中作为 udf 使用时如何对自定义上传的 jar 进行沙箱处理。

0 投票
3 回答
9815 浏览

java - GraalVM 和 Jvm-Hotspot 的区别

谁能解释一下 GraalVM 和 Jvm-Hotspot 之间的区别,以及 GraalVM 与 OpenJDK 的 HotSpot 的关系。

0 投票
1 回答
128 浏览

java - 递归程序执行期间的松露语言运行时错误

我目前正在编写自己的 simplelanguage 实现(https://github.com/graalvm/simplelanguage/),以学习如何使用 Truffle。

我编写了一些程序来测试我的实现,例如斐波那契算法的以下实现。

虽然非递归版本可以使用任何大的参数值(例如 10000)来执行,但递归版本很快就会引发运行时错误。

例如,我开发了一个简单的测试,它使用增量值执行递归 fib 函数,我得到以下结果:

我试图将我自己的实现与官方的 simplelanguage 实现进行比较,但没有找到确定问题根源的方法。

所以我的问题是,我怎样才能找到问题的根本原因?

PS:到目前为止,我没有足够的信息来确定要包含在此问题中的相关片段,但如果需要,请随时询问更多详细信息。谢谢 :)

0 投票
1 回答
810 浏览

java - Graal 不支持垃圾收集器

我正在尝试在 GraalVM Community Edition 1.0 RC4 上运行 Java 程序,该代码适用于最新的 JDK 8 版本。代码以与 GraalVM 相同的方式运行,但相同的错误消息每秒在控制台中打印 100 次(我认为每次需要/使用垃圾收集器):

该程序似乎因打印和/或可能缺少垃圾收集而减慢了速度,并且永远不会结束。

我用一个简单的 HelloWorld 进行了测试,并且不断出现相同的错误消息。程序结束,因为它足够短,并且可以编译。

我使用 GraalVM 社区版按照官方网站上的教程进行操作。我在Graal Github上发现了类似的错误,但我不知道如何设置垃圾收集器,使用的命令行似乎是 Java 10 独有的。

编辑和解决方案:我在 Ubuntu 上使用 Oracle VM VirtualBox,似乎 VM 设置太低。如果您遇到同样的问题,请增加您的 RAM 和 CPU,它应该可以解决它。

0 投票
1 回答
803 浏览

graalvm - GraalVM - 在没有上下文的情况下使用多语言值

我正在 Graal 之上编写一个应用程序,它将能够以不同的语言执行小脚本。

我正在尝试为用于将 Context.eval() 调用(类型:值)的结果转换/处理为 Java 对象的类编写一些单元测试。我从文档中知道 Value 实例始终绑定到 Context,所以当我尝试编写如下内容时:

我收到以下错误:

我想从概念上讲,没有相关的来宾代码的“值”实例是没有意义的,所以我的问题是:

如何测试我的 GuestLanguageResultProcessor 类?我是否必须通过创建上下文来“膨胀”我的单元测试?

专家的附带问题:我也在使用这个类 (GuestLanguageResultProcessor) 从多语言值实例中提取 Java 值,以便我可以关闭上下文。换句话说,在我看来,在能够执行 Context.close() 之前,我需要调用 [value instance].asString() 或 .asWhatever() 以获取结果并能够在没有得到一个 IllegalStateException 正如它在文档中所说的那样。

我做对了吗?有没有更好的方法来处理获取结果并安全地关闭上下文?

谢谢!

0 投票
1 回答
654 浏览

java - 在 GraalVM native-image 中从 Java 代码运行 JS 脚本

我正在尝试从 GraalVM 本机映像中的 Java 代码运行 JS 脚本。

Java 代码如下所示:

JS 代码只是尝试response通过调用对象的方法来使用对象,例如:

这在 GraalVM 中运行时有效,但是在创建本机映像时,它会失败并出现以下错误:

如果我只是打印中的对象print("Response: " + response);,它不会失败。但是,如果我尝试在 上调用任何方法response,我会收到此错误(甚至toString()hashCode())。

我还有什么需要做的吗,或者这只是 SubstractVM native-image 中的一个错误,目前?

我的 GraalVM 版本:

我正在使用的 native-image 命令:

0 投票
2 回答
1203 浏览

graalvm - 将成员从宿主语言注入到访客语言作为访客语言类型

这个问题有点相关: GraalVM - Using Polyglot Value without a context

在我的应用程序中,以来宾语言运行的代码片段不需要知道注入的参数(通过绑定的成员)是 Java 参数。相反,对于使用客户语言开发的人来说,论点应该看起来只是客户语言本身的另一个论点。

例如,我想要一个从我的 Java 宿主语言注入到 JS 来宾脚本的数组,以这种方式:

以 JS 数组的形式“到达”来宾语言,而不是现在发生的 java.util.ArrayList。

目前,我通过将每个非原始类型(我注意到 String、int 等作为 JS“类型”到达 JS)转换为 JSON 并转换回来宾语言来解决这个问题。

这可行,但我想知道是否有更合适的方法来做到这一点,或者是否确实使用绑定是正确的方法?

谢谢!

0 投票
1 回答
502 浏览

java - 使用graal python从java获取外部环境参数

我在 GraalVM 中运行 Java 以使用它来执行 python。

问题是 python 代码应该如何接收“参数”。graal 文档指出,如果这是 JS,我会做这样的事情:

确实,这行得通。python等价物可能是:

这失败了,因为没有这样的模块。我找不到关于如何从外部语言层获取这些参数的文档,只有关于 pythongraal 的文档以及如何使用 python 传递给其他东西。

0 投票
0 回答
529 浏览

graalvm - 通过 Polyglot API 执行 Python 始终需要完整的系统 IO 访问权限

我正在尝试通过 polyglot API 执行一些非常简单的 python 代码。当尝试运行以下简单的测试时:

或者:

我收到此错误(下面的堆栈跟踪):

如果我在构建上下文时将 allowIO 更改为 true,则代码运行良好并给出预期结果。我还尝试了更复杂的代码,结果相同。

为什么要执行 Python 代码需要 IO 访问?

在 JS 中编写和执行的等效代码不需要将 allowIO 设置为 true,所以在我看来,它是 Python 特有的东西。

谢谢你的帮助。

更新

我也一直在用 R 作为客人语言进行测试。运行以下测试:

我收到以下错误:

FastR 意外失败:从 /Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/R/lib/libR.dylib 加载 libR 时出错。如果在 NFI 后端运行,您是否提供了 libtrufflenfi.so 的位置作为系统属性“truffle.nfi.library”的值?当前值为“空”。您的系统上是否存在 OpenMP 运行时库 (libgomp.so)?例如,这个库通常是 GCC 包的一部分。详细信息:宿主环境不允许访问本机代码。

但是,通过将“allowNativeAccess”设置为 true,代码可以正常运行而不会出错。

不同的语言是否需要不同类型的访问权限才能运行?

在我的用例中,我试图尽可能地对执行进行沙箱化。我希望脚本,无论它们是用什么语言编写的,都只能访问提供给它们的数据。以来宾语言运行的脚本不应该对主机系统有任何访问权限。这是可以实现的吗?

部分堆栈跟踪(如果需要调试,我可以提供完整的堆栈跟踪):

org.graalvm.polyglot.PolyglotException:java.lang.SecurityException:不允许操作:/code/polyglot-test at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) 在 com.oracle.truffle.api.TruffleFile.checkAccess(TruffleFile.java:983) 在 com.oracle.truffle.api。 com.oracle.graal.python.builtins.modules.PosixModuleBuiltins$StatNode.stat(PosixModuleBuiltins.java:404) 上 com.oracle.graal.python.builtins.modules.PosixModuleBuiltins$ 上的 TruffleFile.exists(TruffleFile.java:102) StatNode.doStat(PosixModuleBuiltins.java:397) 在 com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory$StatNodeFactory$StatNodeGen.executeAndSpecialize(PosixModuleBuiltinsFactory.java:855) 在 com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory$StatNodeFactory$StatNodeGen.execute(PosixModuleBuiltinsFactory.java:807) 在 com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode$BuiltinBinaryCallNode.execute(BuiltinFunctionRootNode.java:103) 在com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode.execute(BuiltinFunctionRootNode.java:229) at stat(Unknown) at stat(../../../../../Library/Java/JavaVirtualMachines /graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-graalpython/posix.py:51:2230-2247) 在 _path_stat(../../../../ ../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:82:2759-2772)在_path_is_mode_type( ../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0。0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:88:2901-2916) 在 _path_isdir(../../../../../在 path_hook_for_FileFinder(../ ../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py: 1333:50397-50413) 在 PathFinder._path_hooks(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/ python/lib-python/3/importlib/_bootstrap_external.py:1083:40517-40526) 在 PathFinder._path_importer_cache(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee- 1.0。0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1107:41279-41299) 在 PathFinder._get_spec(../../../../. ./Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap_external.py:1135:42391-42421)在 PathFinder.find_spec (../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/ _bootstrap_external.py:1166:43686-43722) 在 _find_spec(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/语言/python/lib-python/3/importlib/_bootstrap.py:892:28932-28960) 在 _find_and_load_unlocked(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee- 1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib/_bootstrap.py:953:31192-31213) 在 _find_and_load(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib- python/3/importlib/_bootstrap.py:968:31701-31738) 在 _gcd_import(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/内容/主页/jre/languages/python/lib-python/3/importlib/_bootstrap.py:985:32285-32317)在 导入(../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/languages/python/lib-python/3/importlib /_bootstrap.py:1066:35366-35382) 在 (../../../../../Library/Java/JavaVirtualMachines/graalvm-ee-1.0.0-rc4/Contents/Home/jre/语言/python/lib-graalpython/ builtins_patches.py:48:2220-2224) 在 org.graalvm.polyglot.Context.eval(Context.java:313) 在 bolt.tests.BoltEngineGraalTest.helloWorldPythonTest(BoltEngineGraalTest.java:66) 在 sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)在 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.junit.runners.model。 FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 在 org.junit.internal。runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java: 325) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 在 org.junit.runners.ParentRunner$3.run(ParentRunner. java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000 (ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal .junit4.runner。JUnit4TestReference.run(JUnit4TestReference.java:86) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:538) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) 原始内部错误:java.lang.SecurityException:不允许操作:/code/polyglot-test at com。 oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.run(TestExecution.java:38) 处运行(JUnit4TestReference.java:86)。 java:538) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) 原始内部错误:java.lang.SecurityException:不允许操作:com.oracle 的 /code/polyglot-test。 truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.run(TestExecution.java:38) 处运行(JUnit4TestReference.java:86)。 java:538) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) 原始内部错误:java.lang.SecurityException:不允许操作:com.oracle 的 /code/polyglot-test。 truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:760) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 206) 原始内部错误:java.lang.SecurityException:不允许操作:com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) 的 /code/polyglot-test 在 com。 oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:760) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 206) 原始内部错误:java.lang.SecurityException:不允许操作:com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) 的 /code/polyglot-test 在 com。 oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...538) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) 在 org .eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)原始内部错误:java.lang.SecurityException:不允许操作:com.oracle.truffle的/code/polyglot-test。 com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) 处的 api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) ...538) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) 在 org .eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)原始内部错误:java.lang.SecurityException:不允许操作:com.oracle.truffle的/code/polyglot-test。 com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) 处的 api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java:489) ...main(RemoteTestRunner.java:206)原始内部错误:java.lang.SecurityException:不允许操作:/code/polyglot-test at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java :489) 在 com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...main(RemoteTestRunner.java:206)原始内部错误:java.lang.SecurityException:不允许操作:/code/polyglot-test at com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.forbidden(FileSystems.java :489) 在 com.oracle.truffle.api.vm.FileSystems$DeniedIOFileSystem.checkAccess(FileSystems.java:367) ...