0

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

but can't get my JavaCritical_ method called.

this is the JNI part

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) {
}

and this is Java:

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

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

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

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.

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.

Павел
  • 677
  • 6
  • 21

1 Answers1

1

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

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

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.

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

Павел
  • 677
  • 6
  • 21
  • From the URL you posted, seems like this might be a Windows specific issue? Can you confirm? – Johnny V Apr 22 '19 at 16:19
  • for me it was on windows, I believe it is not an OS issue itself, but rather some class wrapper for windows OS inside JDK. I dont remember the exact place in the code I saw it, somewhere near https://github.com/openjdk/jdk/blob/master/src/hotspot/os/windows/os_windows.cpp – Павел Apr 23 '19 at 20:42