1

我有一个键值数据库,它是用 C 语言编写的,具有以下功能来设置和获取值。

typedef uint64_t ARK;
#define ARC ARK

int ark_set(ARK *ark, uint64_t klen, void *key, uint64_t vlen, void *val, int64_t *rval)

int ark_get(ARK *ark, uint64_t klen, void *key, uint64_t vbuflen, 
            void *vbuf, uint64_t voff, int64_t *res);

以及其他一些函数来创建 ARK、计数、分配和使用字节。但是,每当我尝试设置或获取值时,它们都会按预期工作 JVM 崩溃。

这是我的 JNR 界面

public interface ARKInterface {
    int ark_create(String file, @u_int64_t Pointer ark, long flags);

    int ark_count(@u_int64_t Pointer ark, @Out NumberByReference count);

    int ark_set(@u_int64_t Pointer ark, @u_int64_t NativeLong klen, Pointer key, 
       @u_int64_t NativeLong vlen, Pointer val, @Out NumberByReference res);

   int ark_get(@u_int64_t Pointer ark, long klen, Pointer key, long vbuflen, 
       Pointer vbuf, long voff, @Out NumberByReference res);
}

这就是我要设置的值

public static void main(String[] args) {
        ARKInterface libc = LibraryLoader.create(ARKInterface.class).load("arkdb-0");

        Pointer ark = Memory.allocateDirect(Runtime.getRuntime(libc), TypeAlias.u_int64_t);
        int _create = libc.ark_create(null, ark, 1);

        System.out.println("ARK Creation return " + _create);
        System.out.println(ark.toString());

        NumberByReference count = new NumberByReference(TypeAlias.int64_t);
        int _count = libc.ark_count(ark, count);

        System.out.println("Count method return value " + _count);

        System.out.println("Total Count is " + count.longValue());

        byte[] _key = "key".getBytes();
        byte[] _value = "value".getBytes();


        Pointer kp = Memory.allocateDirect(Runtime.getRuntime(libc), _key.length);
        kp.put(0, _key, 0, _key.length);

        Pointer vp = Memory.allocateDirect(Runtime.getRuntime(libc), _value.length);
        vp.put(0, _value, 0, _value.length);

        int set_result = libc.ark_set(ark, new NativeLong(_key.length), kp, new NativeLong(_value.length), vp, count);
        System.out.println("ARK Sets and the result is - " + set_result);
}

运行 jar 后,我遇到了致命错误,核心转储中没有什么。

ARK Creation return 0
jnr.ffi.provider.BoundedMemoryIO[address=0x7f12e8026000 size=8]
Count method return value 0
Total Count is 0
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGFPE (0x8) at pc=0x00007f12b1886133, pid=83423, tid=0x00007f12ec663700
#
# JRE version: OpenJDK Runtime Environment (8.0_181-b13) (build 1.8.0_181-b13)
# Java VM: OpenJDK 64-Bit Server VM (25.181-b13 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libarkdb-0.so+0x23133]  ark_enq_cmd+0x533
#
# Core dump written. Default location: /tmp/capi/core or core.83423
#
# An error report file with more information is saved as:
# /tmp/capi/hs_err_pid83423.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)

映射或传递值时是否有任何问题。

4

0 回答 0