转载地址:http://blog.csdn.net/shaohuazuo/article/details/42930847
1.jni.h头文件路径:
/usr/lib/jvm/jdk_1.6.0_43/include/jni.h
2.jni.h头文件组成分析图:
![jni.h头文件详解(一) jni.h头文件详解(一)](/default/index/img?u=aHR0cHM6Ly9waWFuc2hlbi5jb20vaW1hZ2VzLzc5Ni8yYjg2OWRlNjczOThiZTQyNzViOTgxZWU4MGZlODhmYy5wbmc=)
3.下面通过上图进行分析讲解jni.h头文件.
一. jni规范中定义的基本数据类型.
-
#define JNIEXPORT
-
#define JNIIMPORT
-
#define JNICALL
-
-
typedef int jint;
-
#ifdef _LP64 /* 64-bit Solaris */
-
typedef long jlong;
-
#else
-
typedef long long jlong;
-
#endif
-
typedef signed char jbyte;
-
typedef unsigned char jboolean;
-
typedef unsigned short jchar;
-
typedef short jshort;
-
typedef float jfloat;
-
typedef double jdouble;
-
typedef jint jsize;</span>
4.jni标准定义的数组类型。
-
struct _jobject;
-
typedef struct _jobject *jobject;
-
typedef jobject jclass;
-
typedef jobject jthrowable;
-
typedef jobject jstring;
-
typedef jobject jarray;
-
typedef jarray jbooleanArray;
-
typedef jarray jbyteArray;
-
typedef jarray jcharArray;
-
typedef jarray jshortArray;
-
typedef jarray jintArray;
-
typedef jarray jlongArray;
-
typedef jarray jfloatArray;
-
typedef jarray jdoubleArray;
-
typedef jarray jobjectArray;
5.方法签名时用到的公共体类型。
-
typedef union jvalue {
-
jboolean z;
-
jbyte b;
-
jchar c;
-
jshort s;
-
jint i;
-
jlong j;
-
jfloat f;
-
jdouble d;
-
jobject l;
-
} jvalue;</span>
6.属性Id的定义。
-
struct _jfieldID;
-
typedef struct _jfieldID *jfieldID; //字段ID类型的
7.方法Id的定义。
-
struct _jmethodID;
-
typedef struct _jmethodID *jmethodID; //方法ID类型的定义。
8.几种不同类型引用的定义。
-
Return values from jobjectRefType
-
typedef enum _jobjectType {
-
JNIInvalidRefType = 0,
-
JNILocalRefType = 1,
-
JNIGlobalRefType = 2,
-
JNIWeakGlobalRefType = 3
-
} jobjectRefType;</span>
9.错误类型定义。
-
/*
-
* jboolean constants
-
*/
-
#define JNI_FALSE 0
-
#define JNI_TRUE 1
-
-
/*
-
* possible return values for JNI functions.
-
*/
-
-
#define JNI_OK 0 /* success */
-
#define JNI_ERR (-1) /* unknown error */
-
#define JNI_EDETACHED (-2) /* thread detached from the VM */
-
#define JNI_EVERSION (-3) /* JNI version error */
-
#define JNI_ENOMEM (-4) /* not enough memory */
-
#define JNI_EEXIST (-5) /* VM already created */
-
#define JNI_EINVAL (-6) /* invalid arguments */
-
-
/*
-
* used in ReleaseScalarArrayElements
-
*/
-
-
#define JNI_COMMIT 1
-
#define JNI_ABORT 2
10 .JNI Native Method Interface.(java本地方法接口定义)
-
struct JNINativeInterface_;
-
struct JNIEnv_;
-
#ifdef __cplusplus
-
typedef JNIEnv_ JNIEnv;
-
#else
-
typedef const struct JNINativeInterface_ *JNIEnv; //我们使用的是这个定义.
-
#endif
11. JNI Invocation Interface. (java虚拟机接口)
-
struct JNIInvokeInterface_;
-
struct JavaVM_;
-
#ifdef __cplusplus
-
typedef JavaVM_ JavaVM;
-
#else
-
typedef const struct JNIInvokeInterface_ *JavaVM;
-
#endif
-