如何使JavaCritical真正在JNI上工作 [英] How to get JavaCritical to really work on JNI

查看:113
本文介绍了如何使JavaCritical真正在JNI上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试实施此处描述的方法(请参阅注释): 可以在没有JNI的情况下使用sun.misc.Unsafe调用C函数吗?

Trying to implement the approach described in there (see comment): Is it possible to use sun.misc.Unsafe to call C functions without JNI?

但是无法调用我的JavaCritical_方法.

but can't get my JavaCritical_ method called.

这是JNI部分

JNIEXPORT void JNICALL JavaCritical_blas_BLAS_a(jint, jdouble *na) {
    printf("!v!\n");
}

JNIEXPORT void JNICALL Java_blas_BLAS_a(JNIEnv *env, jclass, jdoubleArray a) {
}

这是Java:

public class BLAS {
    public static native void a(double[] a);
}

如果我使用-XX:+ TieredCompilation -XX:+ PrintCompilation运行程序,我会得到

if I run my program with -XX:+TieredCompilation -XX:+PrintCompilation, I get this

   3475 1488     n 0       blas.BLAS::a (native)   (static)

和!v!"不打印.据我了解,输出中的"n"表示JVM使用JNI的Java_xx方法的包装器,而不是CriticalJava的包装器.

and "!v!" is not printed. As I understand, "n" in the output means that JVM uses wrapper around Java_xx method of the JNI, not the CriticalJava one.

那么有人可以建议我做错了什么吗? 顺便说一句,我在x64位Windows 10下的JVM v1.8.0_152 x86模式下运行它.

So can anyone suggest what do I do wrong? Btw, I run it under JVM v1.8.0_152 x86 mode under x64 bit Windows 10.

推荐答案

argh.没关系. 我可以通过引入.def文件来使其工作.

argh. nevermind. I was able to get it to work by introducing .def file.

确实存在一个错误: https://bugs.openjdk.java.net/browse/JDK-8167408 仍然在那里.

indeed there is a bug: https://bugs.openjdk.java.net/browse/JDK-8167408 which is still there.

有趣的是:您需要将lib中的所有JNI方法都移到.def文件中,因为如果混合使用修饰的名称和未修饰的名称,则可能不会拾取JavaCritical.

the interesting thing is: you need to move all your JNI methods in lib into .def file, because if you mix decorated and undecorated names, then JavaCritical might not be picked up.

确实适用于复杂的签名方法,例如dgemm,这很酷.

and the thing indeed works with complex signature methods like dgemm, which is cool.

这篇关于如何使JavaCritical真正在JNI上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆