The code flow of zygote initialization is rather complicated, especially when the JNIs are extensively involved. My IDE often fails to cross reference between them. So I log the code flow here and the location they are defined as well.
Showing posts with label jni. Show all posts
Showing posts with label jni. Show all posts
Sunday, February 06, 2011
Sunday, June 20, 2010
Log of instructions for JNI
Reference:
Edit HelloWorld.java
HelloWorld.javaCompile the JAVA class -- HelloWorld.class
class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } }
Generate the NATIVE header file -- HelloWorld.h$ javac HelloWorld.java
$ javah -jni HelloWorld
HelloWorld.hImplement the NATIVE method -- HelloWorld.c
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: print * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif
HelloWorld.cCompile the NATIVE source code and build the NATIVE library
#include <stdio.h> #include <jni.h> #include "HelloWorld.h" JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *env, jobject obj) { printf("Hello World\n"); return; }
Add "current" directory to the search path of share libraries$ gcc -c -fPIC HelloWorld.c -I$JAVA_HOME/include -I$JAVA_HOME/include/linux $ gcc -shared HelloWorld.o -o libHelloWorld.so
Run the HelloWorld JAVA program$ export LD_LIBRARY_PATH=.
$ java HelloWorld
Hello World
Subscribe to:
Posts (Atom)