赞
踩
<dependency> <groupId>org.javadelight</groupId> <artifactId>delight-nashorn-sandbox</artifactId> <version>0.1.31</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.graalvm.sdk</groupId> <artifactId>graal-sdk</artifactId> <version>${graalvm.js.version}</version> </dependency> <dependency> <groupId>org.graalvm.js</groupId> <artifactId>js</artifactId> <version>${graalvm.js.version}</version> </dependency> <dependency> <groupId>org.graalvm.regex</groupId> <artifactId>regex</artifactId> <version>${graalvm.js.version}</version> </dependency> <dependency> <groupId>org.graalvm.truffle</groupId> <artifactId>truffle-api</artifactId> <version>${graalvm.js.version}</version> </dependency> <dependency> <groupId>org.graalvm.js</groupId> <artifactId>js-scriptengine</artifactId> <version>${graalvm.js.version}</version> </dependency> <dependency> <groupId>org.javadelight</groupId> <artifactId>delight-graaljs-sandbox</artifactId> <version>0.1.2</version> <exclusions> <exclusion> <groupId>org.javadelight</groupId> <artifactId>delight-nashorn-sandbox</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> <exclusion> <groupId>org.graalvm.sdk</groupId> <artifactId>graal-sdk</artifactId> </exclusion> <exclusion> <groupId>org.graalvm.js</groupId> <artifactId>js</artifactId> </exclusion> <exclusion> <groupId>org.graalvm.regex</groupId> <artifactId>regex</artifactId> </exclusion> <exclusion> <groupId>org.graalvm.truffle</groupId> <artifactId>truffle-api</artifactId> </exclusion> <exclusion> <groupId>org.graalvm.js</groupId> <artifactId>js-scriptengine</artifactId> </exclusion> <exclusion> <groupId>org.webjars.bower</groupId> <artifactId>js-beautify</artifactId> </exclusion> </exclusions> </dependency>
注意事项1:java 8只能使用delight-nashorn-sandbox的0.1.x版本,0.2.x版本适用于java 11以上,github上面有讲
注意事项2:打包成springboot fatjar时,需要unpack
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <requiresUnpack> <dependency> <groupId>org.graalvm.js</groupId> <artifactId>js</artifactId> </dependency> <dependency> <groupId>org.graalvm.js</groupId> <artifactId>js-scriptengine</artifactId> </dependency> <dependency> <groupId>org.graalvm.regex</groupId> <artifactId>regex</artifactId> </dependency> <dependency> <groupId>org.graalvm.sdk</groupId> <artifactId>graal-sdk</artifactId> </dependency> <dependency> <groupId>org.graalvm.truffle</groupId> <artifactId>truffle-api</artifactId> </dependency> </requiresUnpack> </configuration> </plugin>
理由:
注意事项3:graalvm js的版本不要使用最新的,20.3.5或21.2.0是一个比较稳定的版本,在各操作系统及cpu上都可用。比如arm64
注意事项4:多线程问题,可参考以下文章或demo。
graal javascript thread safety
多线程demo
multithreading
thread issue
async demo
multi threaded java javascript in graalvm
script engine instance problem
注意事项5:graalvm js支持ScriptEngine与Polyglot模式,在delight-graaljs-sandbox沙箱的实现方案中采用的是ScriptEngine,但会面临多线程的问题。按照注意事项4中提到的内容,多线程可以共享graaljs engine,但需使用不同的Context
注意事项6:crash问题,aarch64、openjdk 1.8.0_242会有问题,升级openjdk 1.8.0_332
graalvm release notes
报错如下:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000fffcb1ca7ef8, pid=3561071, tid=0x0000fffca253f1e0
#
# JRE version: OpenJDK Runtime Environment (8.0_242-b08) (build 1.8.0_242-b08)
# Java VM: OpenJDK 64-Bit Server VM (25.242-b08 mixed mode linux-aarch64 compressed oops)
# Problematic frame:
# V [libjvm.so+0x8c7ef8] oopDesc* PSPromotionManager::copy_to_survivor_space<false>(oopDesc*)+0xf8
#
# Core dump written. Default location: /data/dgaxoa/app-document-service/core or core.3561071
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
注意事项7:有些环境下需要使用-XX:+UseG1GC
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。