我写了一个 C++ JNI Java Launcher。如果我启动一个不使用 JavaFX 的 java 程序,它会起作用,但如果我尝试用它启动一个 JavaFX 程序,它会创建一个核心转储。这是代码:
仅当我使用本机启动器时才会发生核心转储。如果我在命令行中使用相同的参数运行 JavaFX 程序java
,则没有问题。它按预期运行。
我没有从少数文件中粘贴代码,而是创建了一个包含两个分支的存储库,其中包含完整的可运行示例。
build.sh
您可以通过编辑和run-native.sh
更改行来运行示例,jdk="/usr/lib/jvm/java-11-oracle"
以使其对您的系统准确。然后:
./build.sh #compiles the java program and cpp program
./run-native.sh #Sets LD_LIBRARY_PATH and runs the compiled cpp program
or
./run-with-java.sh #only on "withjfx" branch, runs via java at cli.
如您所见,该No JavaFX
版本运行良好,但该JavaFX
版本仅通过调用java
可执行文件运行,如果通过我的本机启动器执行,它将核心转储。
最后,这是我尝试使用本机启动器运行 JavaFX 版本时得到的转储:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f77513575d8, pid=15281, tid=15301
#
# JRE version: Java(TM) SE Runtime Environment (11.0.1+13) (build 11.0.1+13-LTS)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# j java.util.Arrays$ArrayList.<init>([Ljava/lang/Object;)V+6 java.base@11.0.1
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P" (or dumping to /home/joshua/work/javalaunch/core.15281)
#
# An error report file with more information is saved as:
# /home/joshua/work/javalaunch/hs_err_pid15281.log
Compiled method (c2) 326 208 4 java.util.Objects::requireNonNull (14 bytes)
total in heap [0x00007f7758e10d90,0x00007f7758e10fc8] = 568
relocation [0x00007f7758e10f08,0x00007f7758e10f18] = 16
main code [0x00007f7758e10f20,0x00007f7758e10f60] = 64
stub code [0x00007f7758e10f60,0x00007f7758e10f78] = 24
metadata [0x00007f7758e10f78,0x00007f7758e10f80] = 8
scopes data [0x00007f7758e10f80,0x00007f7758e10f90] = 16
scopes pcs [0x00007f7758e10f90,0x00007f7758e10fc0] = 48
dependencies [0x00007f7758e10fc0,0x00007f7758e10fc8] = 8
Could not load hsdis-amd64.so; library not loadable; PrintAssembly is disabled
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
./run-native.sh: line 6: 15281 Aborted (core dumped) ./bin/launch
根据这里一位用户的推荐,基于之前的崩溃,我将 hsdis-amd64.so 安装到我的系统上并指向LD_LIBRARY_PATH
它。我仍然得到一个核心转储,看起来它所做的只是让核心转储加载反汇编程序:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f9e6e2015d8, pid=17530, tid=17550
#
# JRE version: Java(TM) SE Runtime Environment (11.0.1+13) (build 11.0.1+13-LTS)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# j java.util.Arrays$ArrayList.<init>([Ljava/lang/Object;)V+6 java.base@11.0.1
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P" (or dumping to /home/joshua/work/so-question/core.17530)
#
# An error report file with more information is saved as:
# /home/joshua/work/so-question/hs_err_pid17530.log
Compiled method (c2) 372 187 4 java.util.Objects::requireNonNull (14 bytes)
total in heap [0x00007f9e75cbb890,0x00007f9e75cbbac8] = 568
relocation [0x00007f9e75cbba08,0x00007f9e75cbba18] = 16
main code [0x00007f9e75cbba20,0x00007f9e75cbba60] = 64
stub code [0x00007f9e75cbba60,0x00007f9e75cbba78] = 24
metadata [0x00007f9e75cbba78,0x00007f9e75cbba80] = 8
scopes data [0x00007f9e75cbba80,0x00007f9e75cbba90] = 16
scopes pcs [0x00007f9e75cbba90,0x00007f9e75cbbac0] = 48
dependencies [0x00007f9e75cbbac0,0x00007f9e75cbbac8] = 8
Loaded disassembler from hsdis-amd64.so
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
./run-native.sh: line 6: 17530 Aborted (core dumped) ./bin/launch
更新:我在 Ubuntu 18.04 和 Windows 7 上都重复了这个问题。