java-native-interface

JVM crashes with no frame specified, only “timer expired, abort”

杀马特。学长 韩版系。学妹 提交于 2021-02-07 06:28:06
问题 I am running a Java job under Hadoop which is crashing the JVM. I suspect this is due to some JNI code (it uses JBLAS with a multithreaded native BLAS implementation). However, while I expect the crash log to supply the "problematic frame" for debugging, instead the log looks like: # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f204dd6fb27, pid=19570, tid=139776470402816 # # JRE version: 6.0_38-b05 # Java VM: Java HotSpot(TM) 64-Bit Server

Rewriting Java native methods using ASM

*爱你&永不变心* 提交于 2021-02-07 04:55:30
问题 I'm trying to do this by re-writing the bytecode of the class using ASM 4.0 to replace all the native methods with non- native stubs. So far I have this: class ClassAdapter extends ClassVisitor { public ClassAdapter(ClassVisitor cv) { super(Opcodes.ASM4, cv); } @Override public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) { return cv.visitMethod(access & ~Opcodes.ACC_NATIVE, base, desc, signature, exceptions); } } which is executed by

Looking for a convenient way to call Java from C++

自闭症网瘾萝莉.ら 提交于 2021-02-05 12:55:49
问题 It seems most documentation or helper libraries relating to JNI (Java Native Interface) are concerned with calling native code from Java. This seems to be the main use of it, even though it is capable of more. I want to mostly work in the opposite direction: modify an existing (fairly large) portable C++ program by adding some Java libraries to it. For example, I want to make it call databases via JDBC, or message queue systems via JMS, or send emails, or call my own Java classes, etc. But

How to convert a jcharArray to a char[] in c

痞子三分冷 提交于 2021-02-05 12:32:34
问题 I have a jcharArray that is passed into a C program through Java, and I need to know how to use the array in the C program. How do I convert my jcharArray bits into something I can use ( char bits[] )? I tried writing this code using JNI JNIEXPORT jint JNICALL Java_ex_NistStatisticalTestSuite_frequency (JNIEnv *env, jclass cls, jcharArray bits, jint jn) { printf("running frequency test"); int i; double f, s_obs, p_value, sum, sqrt2 = 1.41421356237309504880; int n=jn; char deletethis=(char

JNI - Cannot find native library

元气小坏坏 提交于 2021-02-05 11:11:39
问题 I have a JNI wrapper for a C++ native library. When I try to load the library in my Java code, I see the following exception: java.lang.UnsatisfiedLinkError: no Foo in java.library.path I load the library like this: System.loadLibrary("Foo"); I set java.library.path as follow: java.library.path = /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib I added -XshowSettings:properties to the JVM options and confirmed that the java.library.path is set as shown above. Here's the

JNI - Cannot find native library

一个人想着一个人 提交于 2021-02-05 11:11:20
问题 I have a JNI wrapper for a C++ native library. When I try to load the library in my Java code, I see the following exception: java.lang.UnsatisfiedLinkError: no Foo in java.library.path I load the library like this: System.loadLibrary("Foo"); I set java.library.path as follow: java.library.path = /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib I added -XshowSettings:properties to the JVM options and confirmed that the java.library.path is set as shown above. Here's the

Oop gets corrupted when using in another JNI function

 ̄綄美尐妖づ 提交于 2021-02-05 08:55:28
问题 The question is can we cache jclass and jmethodID across different JNI methods invocation? I faced some strange behavior when trying to create an object of some specific class with cached jclass and jmethodID from another JNI method invocation. Here is a simple example: public class Main { static { System.loadLibrary("test-crash"); } public static void main(String args[]) throws InterruptedException { Thread.sleep(20000); doAnotherAction(doSomeAction()); } private static native long

Android native - How does native code written in jni run with root permission?

一个人想着一个人 提交于 2021-02-02 09:11:44
问题 I have an Android application that call a native shared library by jni. This shared library invokes some loadable kernel modules .ko My app run fail when jni calls the function in shared library that invokes kernel module. But when I write an executable using this shared library, it works fine when call above function. I found that my app run with user name is "u0_axx" and my executable run by command line with root. So maybe it doesn't have permission to invokes kernel module. My question is

Android native - How does native code written in jni run with root permission?

牧云@^-^@ 提交于 2021-02-02 09:11:28
问题 I have an Android application that call a native shared library by jni. This shared library invokes some loadable kernel modules .ko My app run fail when jni calls the function in shared library that invokes kernel module. But when I write an executable using this shared library, it works fine when call above function. I found that my app run with user name is "u0_axx" and my executable run by command line with root. So maybe it doesn't have permission to invokes kernel module. My question is

Android native - How does native code written in jni run with root permission?

ぐ巨炮叔叔 提交于 2021-02-02 09:10:00
问题 I have an Android application that call a native shared library by jni. This shared library invokes some loadable kernel modules .ko My app run fail when jni calls the function in shared library that invokes kernel module. But when I write an executable using this shared library, it works fine when call above function. I found that my app run with user name is "u0_axx" and my executable run by command line with root. So maybe it doesn't have permission to invokes kernel module. My question is