2025-05-24

typedef const struct JNINativeInterface *JNIEnv;

const struct JNINativeInterface … = {

    NULL,
    NULL,
    NULL,
    NULL,
    GetVersion,             //獲取JNI版本號

    DefineClass,             //通過指定ClassLoader對象加載類
    FindClass,             //獲取指定的Class類對象

    FromReflectedMethod,    //通過指定的java.lang.reflect.Method對象獲取方法ID
    FromReflectedField,    //通過指定的java.lang.reflect.Field對象獲取字段ID
    ToReflectedMethod,    //通過指定的方法ID獲取java.lang.reflect.Method對象

    GetSuperclass,         //獲取指定類的父類
    IsAssignableFrom,         //判斷指定類是否繼承自某類或實現瞭某個接口

    ToReflectedField,         //通過指定的字段ID獲取java.lang.reflect.Field對象

    Throw,                 //拋出指定的Throwable對象
    ThrowNew,             //拋出指定的Throwable對象,並制定消息
    ExceptionOccurred,     //獲取未被清空或捕獲的異常
    ExceptionDescribe,     //同printStackTrace()
    ExceptionClear,         //清除已被拋出的異常
    FatalError,             //拋出致命錯誤

    PushLocalFrame,   //Push/PopLocalFrame函數提供瞭本地引用管理的簡便方法,在該函數對之間的代碼段,所有創建的顯式本地引用無需手動調用DeleteLocalReference函數釋放,PopLocalFrame函數會自動釋放這些本地引用
    PopLocalFrame,

    NewGlobalRef,         //創建全局引用,必須被顯式清除
    DeleteGlobalRef,         //清除全局引用
    DeleteLocalRef,         //清除本地引用,通常本地引用在原生代碼返回時會自動清除,但是對於大數據,比如在循環中頻繁創建Java對象,而該對象的隻在一次循環中有效,這種情況下有必要顯式調用DeleteLocalRef以通知VM盡快釋放該對象。
    IsSameObject,         //判斷是否為同一對象,可通過該方法判斷弱引用是否已被釋放(NULL)
    NewLocalRef,             //創建本地引用
    EnsureLocalCapacity,     //確保當前線程可以創建指定數量的本地引用

    AllocObject,             //創建一個新的對象,隻分配內存,不調用任何構造方法(cdwang:應該是為瞭方便通過CallNonvirtual<Type>Method方法調用父類的構造函數初始化對象)
    NewObject,             //通過指定的構造函數創建對象,變長參數形式
    NewObjectV,             //同上,va_list形式
    NewObjectA,             //同上,數組形式

    GetObjectClass,         //獲取對象的Class類對象
    IsInstanceOf,             //同instanceOf

    GetMethodID,         //獲取實例(非靜態)方法的ID

    CallObjectMethod,     //調用實例方法,object表示返回值類型
    CallObjectMethodV,
    CallObjectMethodA,
    CallBooleanMethod,
    CallBooleanMethodV,
    CallBooleanMethodA,
    CallByteMethod,
    CallByteMethodV,
    CallByteMethodA,
    CallCharMethod,
    CallCharMethodV,
    CallCharMethodA,
    CallShortMethod,
    CallShortMethodV,
    CallShortMethodA,
    CallIntMethod,
    CallIntMethodV,
    CallIntMethodA,
    CallLongMethod,
    CallLongMethodV,
    CallLongMethodA,
    CallFloatMethod,
    CallFloatMethodV,
    CallFloatMethodA,
    CallDoubleMethod,
    CallDoubleMethodV,
    CallDoubleMethodA,
    CallVoidMethod,
    CallVoidMethodV,
    CallVoidMethodA,

    CallNonvirtualObjectMethod, //調用非虛實例方法,通過class對象指定調用哪個類的非虛函數(cdwang:應該是某對象不調用自己的構造類的方法實現,而是調用父類的方法實現,這個方法節省瞭子類對象向父類對象的強制轉換)
    CallNonvirtualObjectMethodV,
    CallNonvirtualObjectMethodA,
    CallNonvirtualBooleanMethod,
    CallNonvirtualBooleanMethodV,
    CallNonvirtualBooleanMethodA,
    CallNonvirtualByteMethod,
    CallNonvirtualByteMethodV,
    CallNonvirtualByteMethodA,
    CallNonvirtualCharMethod,
    CallNonvirtualCharMethodV,
    CallNonvirtualCharMethodA,
    CallNonvirtualShortMethod,
    CallNonvirtualShortMethodV,
    CallNonvirtualShortMethodA,
    CallNonvirtualIntMethod,
    CallNonvirtualIntMethodV,
    CallNonvirtualIntMethodA,
    CallNonvirtualLongMethod,
    CallNonvirtualLongMethodV,
    CallNonvirtualLongMethodA,
    CallNonvirtualFloatMethod,
    CallNonvirtualFloatMethodV,
    CallNonvirtualFloatMethodA,
    CallNonvirtualDoubleMethod,
    CallNonvirtualDoubleMethodV,
    CallNonvirtualDoubleMethodA,
    CallNonvirtualVoidMethod,
    CallNonvirtualVoidMethodV,
    CallNonvirtualVoidMethodA,

    GetFieldID,             //獲取成員字段ID

    GetObjectField,         //獲取字段值
    GetBooleanField,
    GetByteField,
    GetCharField,
    GetShortField,
    GetIntField,
    GetLongField,
    GetFloatField,
    GetDoubleField,
    SetObjectField,         //設置字段值
    SetBooleanField,
    SetByteField,
    SetCharField,
    SetShortField,
    SetIntField,
    SetLongField,
    SetFloatField,
    SetDoubleField,

    GetStaticMethodID,     //獲取靜態方法ID

    CallStaticObjectMethod, //調用靜態方法
    CallStaticObjectMethodV,
    CallStaticObjectMethodA,
    CallStaticBooleanMethod,
    CallStaticBooleanMethodV,
    CallStaticBooleanMethodA,
    CallStaticByteMethod,
    CallStaticByteMethodV,
    CallStaticByteMethodA,
    CallStaticCharMethod,
    CallStaticCharMethodV,
    CallStaticCharMethodA,
    CallStaticShortMethod,
    CallStaticShortMethodV,
    CallStaticShortMethodA,
    CallStaticIntMethod,
    CallStaticIntMethodV,
    CallStaticIntMethodA,
    CallStaticLongMethod,
    CallStaticLongMethodV,
    CallStaticLongMethodA,
    CallStaticFloatMethod,
    CallStaticFloatMethodV,
    CallStaticFloatMethodA,
    CallStaticDoubleMethod,
    CallStaticDoubleMethodV,
    CallStaticDoubleMethodA,
    CallStaticVoidMethod,
    CallStaticVoidMethodV,
    CallStaticVoidMethodA,

    GetStaticFieldID,         //獲取靜態字段ID

    GetStaticObjectField,     //獲取字段值
    GetStaticBooleanField,
    GetStaticByteField,
    GetStaticCharField,
    GetStaticShortField,
    GetStaticIntField,
    GetStaticLongField,
    GetStaticFloatField,
    GetStaticDoubleField,

    SetStaticObjectField,     //設置字段值
    SetStaticBooleanField,
    SetStaticByteField,
    SetStaticCharField,
    SetStaticShortField,
    SetStaticIntField,
    SetStaticLongField,
    SetStaticFloatField,
    SetStaticDoubleField,

    NewString,             //通過指定Unicode格式字符數組構造Java String

    GetStringLength,         //獲取Unicode字符的長度
    GetStringChars,         //獲取字符數組
    ReleaseStringChars,     //通知VM可以釋放String和由GetStringChars獲取的字符數組
 
    NewStringUTF,         //通過指定UTF-8格式字符數組構造Java String
    GetStringUTFLength,
    GetStringUTFChars,
    ReleaseStringUTFChars,
 
    GetArrayLength,         //獲取數組長度www.aiwalls.com
 
    NewObjectArray,         //通過指定的Class類對象和初始元素初始化一個Java對象數組
    GetObjectArrayElement,    //獲取指定索引的對象元素
    SetObjectArrayElement,    //設置指定索引的對象元素
 
    NewBooleanArray,     //構造基本類型的Java數組
    NewByteArray,
    NewCharArray,
    NewShortArray,
    NewIntArray,
    NewLongArray,
    NewFloatArray,
    NewDoubleArray,
 
    GetBooleanArrayElements,    //獲取基本類型元素的C數組
    GetByteArrayElements,
    GetCharArrayElements,
    GetShortArrayElements,
    GetIntArrayElements,
    GetLongArrayElements,
    GetFloatArrayElements,
    GetDoubleArrayElements,
 
    ReleaseBooleanArrayElements,    //通知VM可以釋放Java數組和由前述方法族獲取的C數組
    ReleaseByteArrayElements,
    ReleaseCharArrayElements,
    ReleaseShortArrayElements,
    ReleaseIntArrayElements,
    ReleaseLongArrayElements,
    ReleaseFloatArrayElements,
    ReleaseDoubleArrayElements,
 
    GetBooleanArrayRegion,    //獲取子數組
    GetByteArrayRegion,
    GetCharArrayRegion,
    GetShortArrayRegion,
    GetIntArrayRegion,
    GetLongArrayRegion,
    GetFloatArrayRegion,
    GetDoubleArrayRegion,
    SetBooleanArrayRegion,    //設置子數組
    SetByteArrayRegion,
    SetCharArrayRegion,
    SetShortArrayRegion,
    SetIntArrayRegion,
    SetLongArrayRegion,
    SetFloatArrayRegion,
    SetDoubleArrayRegion,
 
    RegisterNatives,         //映射原生代碼
    UnregisterNatives,
 
    MonitorEnter,
    MonitorExit,
 
    GetJavaVM,             //獲取當前線程關聯的VM

    GetStringRegion,        //獲取子串
    GetStringUTFRegion,

    GetPrimitiveArrayCritical,
    ReleasePrimitiveArrayCritical,

    GetStringCritical,        // Get/ReleaseStringCritical必須成對出現,語義和Get/ReleaseStringChars一樣,但代碼段中不能阻塞當前線程,也不能調用任何其他的JNI函數
    ReleaseStringCritical,   

    NewWeakGlobalRef,
    DeleteWeakGlobalRef,

    ExceptionCheck,        //判斷是否有掛起的異常

    NewDirectByteBuffer,
    GetDirectBufferAddress,
    GetDirectBufferCapacity
}; 

摘自  路不平 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *