Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过graalvm本机映像中的Unsafe.allocateInstance注册要实例化的类_Java_Graalvm_Graalvm Native Image - Fatal编程技术网

Java 通过graalvm本机映像中的Unsafe.allocateInstance注册要实例化的类

Java 通过graalvm本机映像中的Unsafe.allocateInstance注册要实例化的类,java,graalvm,graalvm-native-image,Java,Graalvm,Graalvm Native Image,我的应用程序的Graalvm本机映像在以下方法调用的运行时失败: Unsafe.allocateInstance(org.lwjgl.PointerBuffer.class); 除此之外: java.lang.IllegalArgumentException: Class org.lwjgl.PointerBuffer is instantiated reflectively but was never registered. Register the class by using org.g

我的应用程序的Graalvm本机映像在以下方法调用的运行时失败:

Unsafe.allocateInstance(org.lwjgl.PointerBuffer.class);
除此之外:

java.lang.IllegalArgumentException: Class org.lwjgl.PointerBuffer is instantiated reflectively but was never registered. Register the class by using org.graalvm.nativeimage.hosted.RuntimeReflection
    at com.oracle.svm.core.graal.snippets.SubstrateAllocationSnippets.hubErrorStub(SubstrateAllocationSnippets.java:246)
在生成本机映像之前,我使用
native image agent
启动了应用程序,它生成了graalvm配置json,但是
reflect config.json
没有
org.lwjgl.PointerBuffer
的条目

即使我手动添加到
reflect config.json

{
  "name":"org.lwjgl.PointerBuffer",
  "allDeclaredFields":true,
  "allPublicConstructors" : true
  "allPublicFields": true,
  "allDeclaredMethods": true,
  "allPublicMethods": true
}

本机映像仍然失败,出现上述异常。有没有办法使
不安全。allocateInstance
在本机映像中工作?

我不确定它是否能帮助您。该类与“CustomBuffer”非常相似。尝试将此配置添加到reflection.json中,并测试它是否有效

{
  "name" : "org.lwjgl.PointerBuffer",
  "fields":[
    {"name":"capacity", "allowUnsafeAccess":true}, 
    {"name":"container", "allowUnsafeAccess":true}, 
    {"name":"limit", "allowUnsafeAccess":true}, 
    {"name":"mark", "allowUnsafeAccess":true}, 
    {"name":"position", "allowUnsafeAccess":true}
  ]
}

我在我的代码中测试它,它可以工作。我希望它能帮助你。

我不确定它是否能帮助你。该类与“CustomBuffer”非常相似。尝试将此配置添加到reflection.json中,并测试它是否有效

{
  "name" : "org.lwjgl.PointerBuffer",
  "fields":[
    {"name":"capacity", "allowUnsafeAccess":true}, 
    {"name":"container", "allowUnsafeAccess":true}, 
    {"name":"limit", "allowUnsafeAccess":true}, 
    {"name":"mark", "allowUnsafeAccess":true}, 
    {"name":"position", "allowUnsafeAccess":true}
  ]
}
我在我的代码中测试它,它可以工作。我希望它能帮助你