Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*
     18  * JNI specification, as defined by Sun:
     19  * http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html
     20  *
     21  * Everything here is expected to be VM-neutral.
     22  */
     23 
     24 #ifndef JNI_H_
     25 #define JNI_H_
     26 
     27 #include <sys/cdefs.h>
     28 #include <stdarg.h>
     29 
     30 /*
     31  * Primitive types that match up with Java equivalents.
     32  */
     33 #ifdef HAVE_INTTYPES_H
     34 # include <inttypes.h>      /* C99 */
     35 typedef uint8_t         jboolean;       /* unsigned 8 bits */
     36 typedef int8_t          jbyte;          /* signed 8 bits */
     37 typedef uint16_t        jchar;          /* unsigned 16 bits */
     38 typedef int16_t         jshort;         /* signed 16 bits */
     39 typedef int32_t         jint;           /* signed 32 bits */
     40 typedef int64_t         jlong;          /* signed 64 bits */
     41 typedef float           jfloat;         /* 32-bit IEEE 754 */
     42 typedef double          jdouble;        /* 64-bit IEEE 754 */
     43 #else
     44 typedef unsigned char   jboolean;       /* unsigned 8 bits */
     45 typedef signed char     jbyte;          /* signed 8 bits */
     46 typedef unsigned short  jchar;          /* unsigned 16 bits */
     47 typedef short           jshort;         /* signed 16 bits */
     48 typedef int             jint;           /* signed 32 bits */
     49 typedef long long       jlong;          /* signed 64 bits */
     50 typedef float           jfloat;         /* 32-bit IEEE 754 */
     51 typedef double          jdouble;        /* 64-bit IEEE 754 */
     52 #endif
     53 
     54 /* "cardinal indices and sizes" */
     55 typedef jint            jsize;
     56 
     57 #ifdef __cplusplus
     58 /*
     59  * Reference types, in C++
     60  */
     61 class _jobject {};
     62 class _jclass : public _jobject {};
     63 class _jstring : public _jobject {};
     64 class _jarray : public _jobject {};
     65 class _jobjectArray : public _jarray {};
     66 class _jbooleanArray : public _jarray {};
     67 class _jbyteArray : public _jarray {};
     68 class _jcharArray : public _jarray {};
     69 class _jshortArray : public _jarray {};
     70 class _jintArray : public _jarray {};
     71 class _jlongArray : public _jarray {};
     72 class _jfloatArray : public _jarray {};
     73 class _jdoubleArray : public _jarray {};
     74 class _jthrowable : public _jobject {};
     75 
     76 typedef _jobject*       jobject;
     77 typedef _jclass*        jclass;
     78 typedef _jstring*       jstring;
     79 typedef _jarray*        jarray;
     80 typedef _jobjectArray*  jobjectArray;
     81 typedef _jbooleanArray* jbooleanArray;
     82 typedef _jbyteArray*    jbyteArray;
     83 typedef _jcharArray*    jcharArray;
     84 typedef _jshortArray*   jshortArray;
     85 typedef _jintArray*     jintArray;
     86 typedef _jlongArray*    jlongArray;
     87 typedef _jfloatArray*   jfloatArray;
     88 typedef _jdoubleArray*  jdoubleArray;
     89 typedef _jthrowable*    jthrowable;
     90 typedef _jobject*       jweak;
     91 
     92 
     93 #else /* not __cplusplus */
     94 
     95 /*
     96  * Reference types, in C.
     97  */
     98 typedef void*           jobject;
     99 typedef jobject         jclass;
    100 typedef jobject         jstring;
    101 typedef jobject         jarray;
    102 typedef jarray          jobjectArray;
    103 typedef jarray          jbooleanArray;
    104 typedef jarray          jbyteArray;
    105 typedef jarray          jcharArray;
    106 typedef jarray          jshortArray;
    107 typedef jarray          jintArray;
    108 typedef jarray          jlongArray;
    109 typedef jarray          jfloatArray;
    110 typedef jarray          jdoubleArray;
    111 typedef jobject         jthrowable;
    112 typedef jobject         jweak;
    113 
    114 #endif /* not __cplusplus */
    115 
    116 struct _jfieldID;                       /* opaque structure */
    117 typedef struct _jfieldID* jfieldID;     /* field IDs */
    118 
    119 struct _jmethodID;                      /* opaque structure */
    120 typedef struct _jmethodID* jmethodID;   /* method IDs */
    121 
    122 struct JNIInvokeInterface;
    123 
    124 typedef union jvalue {
    125     jboolean    z;
    126     jbyte       b;
    127     jchar       c;
    128     jshort      s;
    129     jint        i;
    130     jlong       j;
    131     jfloat      f;
    132     jdouble     d;
    133     jobject     l;
    134 } jvalue;
    135 
    136 typedef enum jobjectRefType {
    137     JNIInvalidRefType = 0,
    138     JNILocalRefType = 1,
    139     JNIGlobalRefType = 2,
    140     JNIWeakGlobalRefType = 3
    141 } jobjectRefType;
    142 
    143 typedef struct {
    144     const char* name;
    145     const char* signature;
    146     void*       fnPtr;
    147 } JNINativeMethod;
    148 
    149 struct _JNIEnv;
    150 struct _JavaVM;
    151 typedef const struct JNINativeInterface* C_JNIEnv;
    152 
    153 #if defined(__cplusplus)
    154 typedef _JNIEnv JNIEnv;
    155 typedef _JavaVM JavaVM;
    156 #else
    157 typedef const struct JNINativeInterface* JNIEnv;
    158 typedef const struct JNIInvokeInterface* JavaVM;
    159 #endif
    160 
    161 /*
    162  * Table of interface function pointers.
    163  */
    164 struct JNINativeInterface {
    165     void*       reserved0;
    166     void*       reserved1;
    167     void*       reserved2;
    168     void*       reserved3;
    169 
    170     jint        (*GetVersion)(JNIEnv *);
    171 
    172     jclass      (*DefineClass)(JNIEnv*, const char*, jobject, const jbyte*,
    173                         jsize);
    174     jclass      (*FindClass)(JNIEnv*, const char*);
    175 
    176     jmethodID   (*FromReflectedMethod)(JNIEnv*, jobject);
    177     jfieldID    (*FromReflectedField)(JNIEnv*, jobject);
    178     /* spec doesn't show jboolean parameter */
    179     jobject     (*ToReflectedMethod)(JNIEnv*, jclass, jmethodID, jboolean);
    180 
    181     jclass      (*GetSuperclass)(JNIEnv*, jclass);
    182     jboolean    (*IsAssignableFrom)(JNIEnv*, jclass, jclass);
    183 
    184     /* spec doesn't show jboolean parameter */
    185     jobject     (*ToReflectedField)(JNIEnv*, jclass, jfieldID, jboolean);
    186 
    187     jint        (*Throw)(JNIEnv*, jthrowable);
    188     jint        (*ThrowNew)(JNIEnv *, jclass, const char *);
    189     jthrowable  (*ExceptionOccurred)(JNIEnv*);
    190     void        (*ExceptionDescribe)(JNIEnv*);
    191     void        (*ExceptionClear)(JNIEnv*);
    192     void        (*FatalError)(JNIEnv*, const char*);
    193 
    194     jint        (*PushLocalFrame)(JNIEnv*, jint);
    195     jobject     (*PopLocalFrame)(JNIEnv*, jobject);
    196 
    197     jobject     (*NewGlobalRef)(JNIEnv*, jobject);
    198     void        (*DeleteGlobalRef)(JNIEnv*, jobject);
    199     void        (*DeleteLocalRef)(JNIEnv*, jobject);
    200     jboolean    (*IsSameObject)(JNIEnv*, jobject, jobject);
    201 
    202     jobject     (*NewLocalRef)(JNIEnv*, jobject);
    203     jint        (*EnsureLocalCapacity)(JNIEnv*, jint);
    204 
    205     jobject     (*AllocObject)(JNIEnv*, jclass);
    206     jobject     (*NewObject)(JNIEnv*, jclass, jmethodID, ...);
    207     jobject     (*NewObjectV)(JNIEnv*, jclass, jmethodID, va_list);
    208     jobject     (*NewObjectA)(JNIEnv*, jclass, jmethodID, jvalue*);
    209 
    210     jclass      (*GetObjectClass)(JNIEnv*, jobject);
    211     jboolean    (*IsInstanceOf)(JNIEnv*, jobject, jclass);
    212     jmethodID   (*GetMethodID)(JNIEnv*, jclass, const char*, const char*);
    213 
    214     jobject     (*CallObjectMethod)(JNIEnv*, jobject, jmethodID, ...);
    215     jobject     (*CallObjectMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    216     jobject     (*CallObjectMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    217     jboolean    (*CallBooleanMethod)(JNIEnv*, jobject, jmethodID, ...);
    218     jboolean    (*CallBooleanMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    219     jboolean    (*CallBooleanMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    220     jbyte       (*CallByteMethod)(JNIEnv*, jobject, jmethodID, ...);
    221     jbyte       (*CallByteMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    222     jbyte       (*CallByteMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    223     jchar       (*CallCharMethod)(JNIEnv*, jobject, jmethodID, ...);
    224     jchar       (*CallCharMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    225     jchar       (*CallCharMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    226     jshort      (*CallShortMethod)(JNIEnv*, jobject, jmethodID, ...);
    227     jshort      (*CallShortMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    228     jshort      (*CallShortMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    229     jint        (*CallIntMethod)(JNIEnv*, jobject, jmethodID, ...);
    230     jint        (*CallIntMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    231     jint        (*CallIntMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    232     jlong       (*CallLongMethod)(JNIEnv*, jobject, jmethodID, ...);
    233     jlong       (*CallLongMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    234     jlong       (*CallLongMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    235     jfloat      (*CallFloatMethod)(JNIEnv*, jobject, jmethodID, ...) __NDK_FPABI__;
    236     jfloat      (*CallFloatMethodV)(JNIEnv*, jobject, jmethodID, va_list) __NDK_FPABI__;
    237     jfloat      (*CallFloatMethodA)(JNIEnv*, jobject, jmethodID, jvalue*) __NDK_FPABI__;
    238     jdouble     (*CallDoubleMethod)(JNIEnv*, jobject, jmethodID, ...) __NDK_FPABI__;
    239     jdouble     (*CallDoubleMethodV)(JNIEnv*, jobject, jmethodID, va_list) __NDK_FPABI__;
    240     jdouble     (*CallDoubleMethodA)(JNIEnv*, jobject, jmethodID, jvalue*) __NDK_FPABI__;
    241     void        (*CallVoidMethod)(JNIEnv*, jobject, jmethodID, ...);
    242     void        (*CallVoidMethodV)(JNIEnv*, jobject, jmethodID, va_list);
    243     void        (*CallVoidMethodA)(JNIEnv*, jobject, jmethodID, jvalue*);
    244 
    245     jobject     (*CallNonvirtualObjectMethod)(JNIEnv*, jobject, jclass,
    246                         jmethodID, ...);
    247     jobject     (*CallNonvirtualObjectMethodV)(JNIEnv*, jobject, jclass,
    248                         jmethodID, va_list);
    249     jobject     (*CallNonvirtualObjectMethodA)(JNIEnv*, jobject, jclass,
    250                         jmethodID, jvalue*);
    251     jboolean    (*CallNonvirtualBooleanMethod)(JNIEnv*, jobject, jclass,
    252                         jmethodID, ...);
    253     jboolean    (*CallNonvirtualBooleanMethodV)(JNIEnv*, jobject, jclass,
    254                          jmethodID, va_list);
    255     jboolean    (*CallNonvirtualBooleanMethodA)(JNIEnv*, jobject, jclass,
    256                          jmethodID, jvalue*);
    257     jbyte       (*CallNonvirtualByteMethod)(JNIEnv*, jobject, jclass,
    258                         jmethodID, ...);
    259     jbyte       (*CallNonvirtualByteMethodV)(JNIEnv*, jobject, jclass,
    260                         jmethodID, va_list);
    261     jbyte       (*CallNonvirtualByteMethodA)(JNIEnv*, jobject, jclass,
    262                         jmethodID, jvalue*);
    263     jchar       (*CallNonvirtualCharMethod)(JNIEnv*, jobject, jclass,
    264                         jmethodID, ...);
    265     jchar       (*CallNonvirtualCharMethodV)(JNIEnv*, jobject, jclass,
    266                         jmethodID, va_list);
    267     jchar       (*CallNonvirtualCharMethodA)(JNIEnv*, jobject, jclass,
    268                         jmethodID, jvalue*);
    269     jshort      (*CallNonvirtualShortMethod)(JNIEnv*, jobject, jclass,
    270                         jmethodID, ...);
    271     jshort      (*CallNonvirtualShortMethodV)(JNIEnv*, jobject, jclass,
    272                         jmethodID, va_list);
    273     jshort      (*CallNonvirtualShortMethodA)(JNIEnv*, jobject, jclass,
    274                         jmethodID, jvalue*);
    275     jint        (*CallNonvirtualIntMethod)(JNIEnv*, jobject, jclass,
    276                         jmethodID, ...);
    277     jint        (*CallNonvirtualIntMethodV)(JNIEnv*, jobject, jclass,
    278                         jmethodID, va_list);
    279     jint        (*CallNonvirtualIntMethodA)(JNIEnv*, jobject, jclass,
    280                         jmethodID, jvalue*);
    281     jlong       (*CallNonvirtualLongMethod)(JNIEnv*, jobject, jclass,
    282                         jmethodID, ...);
    283     jlong       (*CallNonvirtualLongMethodV)(JNIEnv*, jobject, jclass,
    284                         jmethodID, va_list);
    285     jlong       (*CallNonvirtualLongMethodA)(JNIEnv*, jobject, jclass,
    286                         jmethodID, jvalue*);
    287     jfloat      (*CallNonvirtualFloatMethod)(JNIEnv*, jobject, jclass,
    288                         jmethodID, ...) __NDK_FPABI__;
    289     jfloat      (*CallNonvirtualFloatMethodV)(JNIEnv*, jobject, jclass,
    290                         jmethodID, va_list) __NDK_FPABI__;
    291     jfloat      (*CallNonvirtualFloatMethodA)(JNIEnv*, jobject, jclass,
    292                         jmethodID, jvalue*) __NDK_FPABI__;
    293     jdouble     (*CallNonvirtualDoubleMethod)(JNIEnv*, jobject, jclass,
    294                         jmethodID, ...) __NDK_FPABI__;
    295     jdouble     (*CallNonvirtualDoubleMethodV)(JNIEnv*, jobject, jclass,
    296                         jmethodID, va_list) __NDK_FPABI__;
    297     jdouble     (*CallNonvirtualDoubleMethodA)(JNIEnv*, jobject, jclass,
    298                         jmethodID, jvalue*) __NDK_FPABI__;
    299     void        (*CallNonvirtualVoidMethod)(JNIEnv*, jobject, jclass,
    300                         jmethodID, ...);
    301     void        (*CallNonvirtualVoidMethodV)(JNIEnv*, jobject, jclass,
    302                         jmethodID, va_list);
    303     void        (*CallNonvirtualVoidMethodA)(JNIEnv*, jobject, jclass,
    304                         jmethodID, jvalue*);
    305 
    306     jfieldID    (*GetFieldID)(JNIEnv*, jclass, const char*, const char*);
    307 
    308     jobject     (*GetObjectField)(JNIEnv*, jobject, jfieldID);
    309     jboolean    (*GetBooleanField)(JNIEnv*, jobject, jfieldID);
    310     jbyte       (*GetByteField)(JNIEnv*, jobject, jfieldID);
    311     jchar       (*GetCharField)(JNIEnv*, jobject, jfieldID);
    312     jshort      (*GetShortField)(JNIEnv*, jobject, jfieldID);
    313     jint        (*GetIntField)(JNIEnv*, jobject, jfieldID);
    314     jlong       (*GetLongField)(JNIEnv*, jobject, jfieldID);
    315     jfloat      (*GetFloatField)(JNIEnv*, jobject, jfieldID) __NDK_FPABI__;
    316     jdouble     (*GetDoubleField)(JNIEnv*, jobject, jfieldID) __NDK_FPABI__;
    317 
    318     void        (*SetObjectField)(JNIEnv*, jobject, jfieldID, jobject);
    319     void        (*SetBooleanField)(JNIEnv*, jobject, jfieldID, jboolean);
    320     void        (*SetByteField)(JNIEnv*, jobject, jfieldID, jbyte);
    321     void        (*SetCharField)(JNIEnv*, jobject, jfieldID, jchar);
    322     void        (*SetShortField)(JNIEnv*, jobject, jfieldID, jshort);
    323     void        (*SetIntField)(JNIEnv*, jobject, jfieldID, jint);
    324     void        (*SetLongField)(JNIEnv*, jobject, jfieldID, jlong);
    325     void        (*SetFloatField)(JNIEnv*, jobject, jfieldID, jfloat) __NDK_FPABI__;
    326     void        (*SetDoubleField)(JNIEnv*, jobject, jfieldID, jdouble) __NDK_FPABI__;
    327 
    328     jmethodID   (*GetStaticMethodID)(JNIEnv*, jclass, const char*, const char*);
    329 
    330     jobject     (*CallStaticObjectMethod)(JNIEnv*, jclass, jmethodID, ...);
    331     jobject     (*CallStaticObjectMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    332     jobject     (*CallStaticObjectMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    333     jboolean    (*CallStaticBooleanMethod)(JNIEnv*, jclass, jmethodID, ...);
    334     jboolean    (*CallStaticBooleanMethodV)(JNIEnv*, jclass, jmethodID,
    335                         va_list);
    336     jboolean    (*CallStaticBooleanMethodA)(JNIEnv*, jclass, jmethodID,
    337                         jvalue*);
    338     jbyte       (*CallStaticByteMethod)(JNIEnv*, jclass, jmethodID, ...);
    339     jbyte       (*CallStaticByteMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    340     jbyte       (*CallStaticByteMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    341     jchar       (*CallStaticCharMethod)(JNIEnv*, jclass, jmethodID, ...);
    342     jchar       (*CallStaticCharMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    343     jchar       (*CallStaticCharMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    344     jshort      (*CallStaticShortMethod)(JNIEnv*, jclass, jmethodID, ...);
    345     jshort      (*CallStaticShortMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    346     jshort      (*CallStaticShortMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    347     jint        (*CallStaticIntMethod)(JNIEnv*, jclass, jmethodID, ...);
    348     jint        (*CallStaticIntMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    349     jint        (*CallStaticIntMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    350     jlong       (*CallStaticLongMethod)(JNIEnv*, jclass, jmethodID, ...);
    351     jlong       (*CallStaticLongMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    352     jlong       (*CallStaticLongMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    353     jfloat      (*CallStaticFloatMethod)(JNIEnv*, jclass, jmethodID, ...) __NDK_FPABI__;
    354     jfloat      (*CallStaticFloatMethodV)(JNIEnv*, jclass, jmethodID, va_list) __NDK_FPABI__;
    355     jfloat      (*CallStaticFloatMethodA)(JNIEnv*, jclass, jmethodID, jvalue*) __NDK_FPABI__;
    356     jdouble     (*CallStaticDoubleMethod)(JNIEnv*, jclass, jmethodID, ...) __NDK_FPABI__;
    357     jdouble     (*CallStaticDoubleMethodV)(JNIEnv*, jclass, jmethodID, va_list) __NDK_FPABI__;
    358     jdouble     (*CallStaticDoubleMethodA)(JNIEnv*, jclass, jmethodID, jvalue*) __NDK_FPABI__;
    359     void        (*CallStaticVoidMethod)(JNIEnv*, jclass, jmethodID, ...);
    360     void        (*CallStaticVoidMethodV)(JNIEnv*, jclass, jmethodID, va_list);
    361     void        (*CallStaticVoidMethodA)(JNIEnv*, jclass, jmethodID, jvalue*);
    362 
    363     jfieldID    (*GetStaticFieldID)(JNIEnv*, jclass, const char*,
    364                         const char*);
    365 
    366     jobject     (*GetStaticObjectField)(JNIEnv*, jclass, jfieldID);
    367     jboolean    (*GetStaticBooleanField)(JNIEnv*, jclass, jfieldID);
    368     jbyte       (*GetStaticByteField)(JNIEnv*, jclass, jfieldID);
    369     jchar       (*GetStaticCharField)(JNIEnv*, jclass, jfieldID);
    370     jshort      (*GetStaticShortField)(JNIEnv*, jclass, jfieldID);
    371     jint        (*GetStaticIntField)(JNIEnv*, jclass, jfieldID);
    372     jlong       (*GetStaticLongField)(JNIEnv*, jclass, jfieldID);
    373     jfloat      (*GetStaticFloatField)(JNIEnv*, jclass, jfieldID) __NDK_FPABI__;
    374     jdouble     (*GetStaticDoubleField)(JNIEnv*, jclass, jfieldID) __NDK_FPABI__;
    375 
    376     void        (*SetStaticObjectField)(JNIEnv*, jclass, jfieldID, jobject);
    377     void        (*SetStaticBooleanField)(JNIEnv*, jclass, jfieldID, jboolean);
    378     void        (*SetStaticByteField)(JNIEnv*, jclass, jfieldID, jbyte);
    379     void        (*SetStaticCharField)(JNIEnv*, jclass, jfieldID, jchar);
    380     void        (*SetStaticShortField)(JNIEnv*, jclass, jfieldID, jshort);
    381     void        (*SetStaticIntField)(JNIEnv*, jclass, jfieldID, jint);
    382     void        (*SetStaticLongField)(JNIEnv*, jclass, jfieldID, jlong);
    383     void        (*SetStaticFloatField)(JNIEnv*, jclass, jfieldID, jfloat) __NDK_FPABI__;
    384     void        (*SetStaticDoubleField)(JNIEnv*, jclass, jfieldID, jdouble) __NDK_FPABI__;
    385 
    386     jstring     (*NewString)(JNIEnv*, const jchar*, jsize);
    387     jsize       (*GetStringLength)(JNIEnv*, jstring);
    388     const jchar* (*GetStringChars)(JNIEnv*, jstring, jboolean*);
    389     void        (*ReleaseStringChars)(JNIEnv*, jstring, const jchar*);
    390     jstring     (*NewStringUTF)(JNIEnv*, const char*);
    391     jsize       (*GetStringUTFLength)(JNIEnv*, jstring);
    392     /* JNI spec says this returns const jbyte*, but that's inconsistent */
    393     const char* (*GetStringUTFChars)(JNIEnv*, jstring, jboolean*);
    394     void        (*ReleaseStringUTFChars)(JNIEnv*, jstring, const char*);
    395     jsize       (*GetArrayLength)(JNIEnv*, jarray);
    396     jobjectArray (*NewObjectArray)(JNIEnv*, jsize, jclass, jobject);
    397     jobject     (*GetObjectArrayElement)(JNIEnv*, jobjectArray, jsize);
    398     void        (*SetObjectArrayElement)(JNIEnv*, jobjectArray, jsize, jobject);
    399 
    400     jbooleanArray (*NewBooleanArray)(JNIEnv*, jsize);
    401     jbyteArray    (*NewByteArray)(JNIEnv*, jsize);
    402     jcharArray    (*NewCharArray)(JNIEnv*, jsize);
    403     jshortArray   (*NewShortArray)(JNIEnv*, jsize);
    404     jintArray     (*NewIntArray)(JNIEnv*, jsize);
    405     jlongArray    (*NewLongArray)(JNIEnv*, jsize);
    406     jfloatArray   (*NewFloatArray)(JNIEnv*, jsize);
    407     jdoubleArray  (*NewDoubleArray)(JNIEnv*, jsize);
    408 
    409     jboolean*   (*GetBooleanArrayElements)(JNIEnv*, jbooleanArray, jboolean*);
    410     jbyte*      (*GetByteArrayElements)(JNIEnv*, jbyteArray, jboolean*);
    411     jchar*      (*GetCharArrayElements)(JNIEnv*, jcharArray, jboolean*);
    412     jshort*     (*GetShortArrayElements)(JNIEnv*, jshortArray, jboolean*);
    413     jint*       (*GetIntArrayElements)(JNIEnv*, jintArray, jboolean*);
    414     jlong*      (*GetLongArrayElements)(JNIEnv*, jlongArray, jboolean*);
    415     jfloat*     (*GetFloatArrayElements)(JNIEnv*, jfloatArray, jboolean*);
    416     jdouble*    (*GetDoubleArrayElements)(JNIEnv*, jdoubleArray, jboolean*);
    417 
    418     void        (*ReleaseBooleanArrayElements)(JNIEnv*, jbooleanArray,
    419                         jboolean*, jint);
    420     void        (*ReleaseByteArrayElements)(JNIEnv*, jbyteArray,
    421                         jbyte*, jint);
    422     void        (*ReleaseCharArrayElements)(JNIEnv*, jcharArray,
    423                         jchar*, jint);
    424     void        (*ReleaseShortArrayElements)(JNIEnv*, jshortArray,
    425                         jshort*, jint);
    426     void        (*ReleaseIntArrayElements)(JNIEnv*, jintArray,
    427                         jint*, jint);
    428     void        (*ReleaseLongArrayElements)(JNIEnv*, jlongArray,
    429                         jlong*, jint);
    430     void        (*ReleaseFloatArrayElements)(JNIEnv*, jfloatArray,
    431                         jfloat*, jint);
    432     void        (*ReleaseDoubleArrayElements)(JNIEnv*, jdoubleArray,
    433                         jdouble*, jint);
    434 
    435     void        (*GetBooleanArrayRegion)(JNIEnv*, jbooleanArray,
    436                         jsize, jsize, jboolean*);
    437     void        (*GetByteArrayRegion)(JNIEnv*, jbyteArray,
    438                         jsize, jsize, jbyte*);
    439     void        (*GetCharArrayRegion)(JNIEnv*, jcharArray,
    440                         jsize, jsize, jchar*);
    441     void        (*GetShortArrayRegion)(JNIEnv*, jshortArray,
    442                         jsize, jsize, jshort*);
    443     void        (*GetIntArrayRegion)(JNIEnv*, jintArray,
    444                         jsize, jsize, jint*);
    445     void        (*GetLongArrayRegion)(JNIEnv*, jlongArray,
    446                         jsize, jsize, jlong*);
    447     void        (*GetFloatArrayRegion)(JNIEnv*, jfloatArray,
    448                         jsize, jsize, jfloat*);
    449     void        (*GetDoubleArrayRegion)(JNIEnv*, jdoubleArray,
    450                         jsize, jsize, jdouble*);
    451 
    452     /* spec shows these without const; some jni.h do, some don't */
    453     void        (*SetBooleanArrayRegion)(JNIEnv*, jbooleanArray,
    454                         jsize, jsize, const jboolean*);
    455     void        (*SetByteArrayRegion)(JNIEnv*, jbyteArray,
    456                         jsize, jsize, const jbyte*);
    457     void        (*SetCharArrayRegion)(JNIEnv*, jcharArray,
    458                         jsize, jsize, const jchar*);
    459     void        (*SetShortArrayRegion)(JNIEnv*, jshortArray,
    460                         jsize, jsize, const jshort*);
    461     void        (*SetIntArrayRegion)(JNIEnv*, jintArray,
    462                         jsize, jsize, const jint*);
    463     void        (*SetLongArrayRegion)(JNIEnv*, jlongArray,
    464                         jsize, jsize, const jlong*);
    465     void        (*SetFloatArrayRegion)(JNIEnv*, jfloatArray,
    466                         jsize, jsize, const jfloat*);
    467     void        (*SetDoubleArrayRegion)(JNIEnv*, jdoubleArray,
    468                         jsize, jsize, const jdouble*);
    469 
    470     jint        (*RegisterNatives)(JNIEnv*, jclass, const JNINativeMethod*,
    471                         jint);
    472     jint        (*UnregisterNatives)(JNIEnv*, jclass);
    473     jint        (*MonitorEnter)(JNIEnv*, jobject);
    474     jint        (*MonitorExit)(JNIEnv*, jobject);
    475     jint        (*GetJavaVM)(JNIEnv*, JavaVM**);
    476 
    477     void        (*GetStringRegion)(JNIEnv*, jstring, jsize, jsize, jchar*);
    478     void        (*GetStringUTFRegion)(JNIEnv*, jstring, jsize, jsize, char*);
    479 
    480     void*       (*GetPrimitiveArrayCritical)(JNIEnv*, jarray, jboolean*);
    481     void        (*ReleasePrimitiveArrayCritical)(JNIEnv*, jarray, void*, jint);
    482 
    483     const jchar* (*GetStringCritical)(JNIEnv*, jstring, jboolean*);
    484     void        (*ReleaseStringCritical)(JNIEnv*, jstring, const jchar*);
    485 
    486     jweak       (*NewWeakGlobalRef)(JNIEnv*, jobject);
    487     void        (*DeleteWeakGlobalRef)(JNIEnv*, jweak);
    488 
    489     jboolean    (*ExceptionCheck)(JNIEnv*);
    490 
    491     jobject     (*NewDirectByteBuffer)(JNIEnv*, void*, jlong);
    492     void*       (*GetDirectBufferAddress)(JNIEnv*, jobject);
    493     jlong       (*GetDirectBufferCapacity)(JNIEnv*, jobject);
    494 
    495     /* added in JNI 1.6 */
    496     jobjectRefType (*GetObjectRefType)(JNIEnv*, jobject);
    497 };
    498 
    499 /*
    500  * C++ object wrapper.
    501  *
    502  * This is usually overlaid on a C struct whose first element is a
    503  * JNINativeInterface*.  We rely somewhat on compiler behavior.
    504  */
    505 struct _JNIEnv {
    506     /* do not rename this; it does not seem to be entirely opaque */
    507     const struct JNINativeInterface* functions;
    508 
    509 #if defined(__cplusplus)
    510 
    511     jint GetVersion()
    512     { return functions->GetVersion(this); }
    513 
    514     jclass DefineClass(const char *name, jobject loader, const jbyte* buf,
    515         jsize bufLen)
    516     { return functions->DefineClass(this, name, loader, buf, bufLen); }
    517 
    518     jclass FindClass(const char* name)
    519     { return functions->FindClass(this, name); }
    520 
    521     jmethodID FromReflectedMethod(jobject method)
    522     { return functions->FromReflectedMethod(this, method); }
    523 
    524     jfieldID FromReflectedField(jobject field)
    525     { return functions->FromReflectedField(this, field); }
    526 
    527     jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic)
    528     { return functions->ToReflectedMethod(this, cls, methodID, isStatic); }
    529 
    530     jclass GetSuperclass(jclass clazz)
    531     { return functions->GetSuperclass(this, clazz); }
    532 
    533     jboolean IsAssignableFrom(jclass clazz1, jclass clazz2)
    534     { return functions->IsAssignableFrom(this, clazz1, clazz2); }
    535 
    536     jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic)
    537     { return functions->ToReflectedField(this, cls, fieldID, isStatic); }
    538 
    539     jint Throw(jthrowable obj)
    540     { return functions->Throw(this, obj); }
    541 
    542     jint ThrowNew(jclass clazz, const char* message)
    543     { return functions->ThrowNew(this, clazz, message); }
    544 
    545     jthrowable ExceptionOccurred()
    546     { return functions->ExceptionOccurred(this); }
    547 
    548     void ExceptionDescribe()
    549     { functions->ExceptionDescribe(this); }
    550 
    551     void ExceptionClear()
    552     { functions->ExceptionClear(this); }
    553 
    554     void FatalError(const char* msg)
    555     { functions->FatalError(this, msg); }
    556 
    557     jint PushLocalFrame(jint capacity)
    558     { return functions->PushLocalFrame(this, capacity); }
    559 
    560     jobject PopLocalFrame(jobject result)
    561     { return functions->PopLocalFrame(this, result); }
    562 
    563     jobject NewGlobalRef(jobject obj)
    564     { return functions->NewGlobalRef(this, obj); }
    565 
    566     void DeleteGlobalRef(jobject globalRef)
    567     { functions->DeleteGlobalRef(this, globalRef); }
    568 
    569     void DeleteLocalRef(jobject localRef)
    570     { functions->DeleteLocalRef(this, localRef); }
    571 
    572     jboolean IsSameObject(jobject ref1, jobject ref2)
    573     { return functions->IsSameObject(this, ref1, ref2); }
    574 
    575     jobject NewLocalRef(jobject ref)
    576     { return functions->NewLocalRef(this, ref); }
    577 
    578     jint EnsureLocalCapacity(jint capacity)
    579     { return functions->EnsureLocalCapacity(this, capacity); }
    580 
    581     jobject AllocObject(jclass clazz)
    582     { return functions->AllocObject(this, clazz); }
    583 
    584     jobject NewObject(jclass clazz, jmethodID methodID, ...)
    585     {
    586         va_list args;
    587         va_start(args, methodID);
    588         jobject result = functions->NewObjectV(this, clazz, methodID, args);
    589         va_end(args);
    590         return result;
    591     }
    592 
    593     jobject NewObjectV(jclass clazz, jmethodID methodID, va_list args)
    594     { return functions->NewObjectV(this, clazz, methodID, args); }
    595 
    596     jobject NewObjectA(jclass clazz, jmethodID methodID, jvalue* args)
    597     { return functions->NewObjectA(this, clazz, methodID, args); }
    598 
    599     jclass GetObjectClass(jobject obj)
    600     { return functions->GetObjectClass(this, obj); }
    601 
    602     jboolean IsInstanceOf(jobject obj, jclass clazz)
    603     { return functions->IsInstanceOf(this, obj, clazz); }
    604 
    605     jmethodID GetMethodID(jclass clazz, const char* name, const char* sig)
    606     { return functions->GetMethodID(this, clazz, name, sig); }
    607 
    608 #define CALL_TYPE_METHOD(_jtype, _jname)                                    \
    609     __NDK_FPABI__                                                           \
    610     _jtype Call##_jname##Method(jobject obj, jmethodID methodID, ...)       \
    611     {                                                                       \
    612         _jtype result;                                                      \
    613         va_list args;                                                       \
    614         va_start(args, methodID);                                           \
    615         result = functions->Call##_jname##MethodV(this, obj, methodID,      \
    616                     args);                                                  \
    617         va_end(args);                                                       \
    618         return result;                                                      \
    619     }
    620 #define CALL_TYPE_METHODV(_jtype, _jname)                                   \
    621     __NDK_FPABI__                                                           \
    622     _jtype Call##_jname##MethodV(jobject obj, jmethodID methodID,           \
    623         va_list args)                                                       \
    624     { return functions->Call##_jname##MethodV(this, obj, methodID, args); }
    625 #define CALL_TYPE_METHODA(_jtype, _jname)                                   \
    626     __NDK_FPABI__                                                           \
    627     _jtype Call##_jname##MethodA(jobject obj, jmethodID methodID,           \
    628         jvalue* args)                                                       \
    629     { return functions->Call##_jname##MethodA(this, obj, methodID, args); }
    630 
    631 #define CALL_TYPE(_jtype, _jname)                                           \
    632     CALL_TYPE_METHOD(_jtype, _jname)                                        \
    633     CALL_TYPE_METHODV(_jtype, _jname)                                       \
    634     CALL_TYPE_METHODA(_jtype, _jname)
    635 
    636     CALL_TYPE(jobject, Object)
    637     CALL_TYPE(jboolean, Boolean)
    638     CALL_TYPE(jbyte, Byte)
    639     CALL_TYPE(jchar, Char)
    640     CALL_TYPE(jshort, Short)
    641     CALL_TYPE(jint, Int)
    642     CALL_TYPE(jlong, Long)
    643     CALL_TYPE(jfloat, Float)
    644     CALL_TYPE(jdouble, Double)
    645 
    646     void CallVoidMethod(jobject obj, jmethodID methodID, ...)
    647     {
    648         va_list args;
    649         va_start(args, methodID);
    650         functions->CallVoidMethodV(this, obj, methodID, args);
    651         va_end(args);
    652     }
    653     void CallVoidMethodV(jobject obj, jmethodID methodID, va_list args)
    654     { functions->CallVoidMethodV(this, obj, methodID, args); }
    655     void CallVoidMethodA(jobject obj, jmethodID methodID, jvalue* args)
    656     { functions->CallVoidMethodA(this, obj, methodID, args); }
    657 
    658 #define CALL_NONVIRT_TYPE_METHOD(_jtype, _jname)                            \
    659     __NDK_FPABI__                                                           \
    660     _jtype CallNonvirtual##_jname##Method(jobject obj, jclass clazz,        \
    661         jmethodID methodID, ...)                                            \
    662     {                                                                       \
    663         _jtype result;                                                      \
    664         va_list args;                                                       \
    665         va_start(args, methodID);                                           \
    666         result = functions->CallNonvirtual##_jname##MethodV(this, obj,      \
    667                     clazz, methodID, args);                                 \
    668         va_end(args);                                                       \
    669         return result;                                                      \
    670     }
    671 #define CALL_NONVIRT_TYPE_METHODV(_jtype, _jname)                           \
    672     __NDK_FPABI__                                                           \
    673     _jtype CallNonvirtual##_jname##MethodV(jobject obj, jclass clazz,       \
    674         jmethodID methodID, va_list args)                                   \
    675     { return functions->CallNonvirtual##_jname##MethodV(this, obj, clazz,   \
    676         methodID, args); }
    677 #define CALL_NONVIRT_TYPE_METHODA(_jtype, _jname)                           \
    678     __NDK_FPABI__                                                           \
    679     _jtype CallNonvirtual##_jname##MethodA(jobject obj, jclass clazz,       \
    680         jmethodID methodID, jvalue* args)                                   \
    681     { return functions->CallNonvirtual##_jname##MethodA(this, obj, clazz,   \
    682         methodID, args); }
    683 
    684 #define CALL_NONVIRT_TYPE(_jtype, _jname)                                   \
    685     CALL_NONVIRT_TYPE_METHOD(_jtype, _jname)                                \
    686     CALL_NONVIRT_TYPE_METHODV(_jtype, _jname)                               \
    687     CALL_NONVIRT_TYPE_METHODA(_jtype, _jname)
    688 
    689     CALL_NONVIRT_TYPE(jobject, Object)
    690     CALL_NONVIRT_TYPE(jboolean, Boolean)
    691     CALL_NONVIRT_TYPE(jbyte, Byte)
    692     CALL_NONVIRT_TYPE(jchar, Char)
    693     CALL_NONVIRT_TYPE(jshort, Short)
    694     CALL_NONVIRT_TYPE(jint, Int)
    695     CALL_NONVIRT_TYPE(jlong, Long)
    696     CALL_NONVIRT_TYPE(jfloat, Float)
    697     CALL_NONVIRT_TYPE(jdouble, Double)
    698 
    699     void CallNonvirtualVoidMethod(jobject obj, jclass clazz,
    700         jmethodID methodID, ...)
    701     {
    702         va_list args;
    703         va_start(args, methodID);
    704         functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args);
    705         va_end(args);
    706     }
    707     void CallNonvirtualVoidMethodV(jobject obj, jclass clazz,
    708         jmethodID methodID, va_list args)
    709     { functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args); }
    710     void CallNonvirtualVoidMethodA(jobject obj, jclass clazz,
    711         jmethodID methodID, jvalue* args)
    712     { functions->CallNonvirtualVoidMethodA(this, obj, clazz, methodID, args); }
    713 
    714     jfieldID GetFieldID(jclass clazz, const char* name, const char* sig)
    715     { return functions->GetFieldID(this, clazz, name, sig); }
    716 
    717     jobject GetObjectField(jobject obj, jfieldID fieldID)
    718     { return functions->GetObjectField(this, obj, fieldID); }
    719     jboolean GetBooleanField(jobject obj, jfieldID fieldID)
    720     { return functions->GetBooleanField(this, obj, fieldID); }
    721     jbyte GetByteField(jobject obj, jfieldID fieldID)
    722     { return functions->GetByteField(this, obj, fieldID); }
    723     jchar GetCharField(jobject obj, jfieldID fieldID)
    724     { return functions->GetCharField(this, obj, fieldID); }
    725     jshort GetShortField(jobject obj, jfieldID fieldID)
    726     { return functions->GetShortField(this, obj, fieldID); }
    727     jint GetIntField(jobject obj, jfieldID fieldID)
    728     { return functions->GetIntField(this, obj, fieldID); }
    729     jlong GetLongField(jobject obj, jfieldID fieldID)
    730     { return functions->GetLongField(this, obj, fieldID); }
    731     __NDK_FPABI__
    732     jfloat GetFloatField(jobject obj, jfieldID fieldID)
    733     { return functions->GetFloatField(this, obj, fieldID); }
    734     __NDK_FPABI__
    735     jdouble GetDoubleField(jobject obj, jfieldID fieldID)
    736     { return functions->GetDoubleField(this, obj, fieldID); }
    737 
    738     void SetObjectField(jobject obj, jfieldID fieldID, jobject value)
    739     { functions->SetObjectField(this, obj, fieldID, value); }
    740     void SetBooleanField(jobject obj, jfieldID fieldID, jboolean value)
    741     { functions->SetBooleanField(this, obj, fieldID, value); }
    742     void SetByteField(jobject obj, jfieldID fieldID, jbyte value)
    743     { functions->SetByteField(this, obj, fieldID, value); }
    744     void SetCharField(jobject obj, jfieldID fieldID, jchar value)
    745     { functions->SetCharField(this, obj, fieldID, value); }
    746     void SetShortField(jobject obj, jfieldID fieldID, jshort value)
    747     { functions->SetShortField(this, obj, fieldID, value); }
    748     void SetIntField(jobject obj, jfieldID fieldID, jint value)
    749     { functions->SetIntField(this, obj, fieldID, value); }
    750     void SetLongField(jobject obj, jfieldID fieldID, jlong value)
    751     { functions->SetLongField(this, obj, fieldID, value); }
    752     __NDK_FPABI__
    753     void SetFloatField(jobject obj, jfieldID fieldID, jfloat value)
    754     { functions->SetFloatField(this, obj, fieldID, value); }
    755     __NDK_FPABI__
    756     void SetDoubleField(jobject obj, jfieldID fieldID, jdouble value)
    757     { functions->SetDoubleField(this, obj, fieldID, value); }
    758 
    759     jmethodID GetStaticMethodID(jclass clazz, const char* name, const char* sig)
    760     { return functions->GetStaticMethodID(this, clazz, name, sig); }
    761 
    762 #define CALL_STATIC_TYPE_METHOD(_jtype, _jname)                             \
    763     __NDK_FPABI__                                                           \
    764     _jtype CallStatic##_jname##Method(jclass clazz, jmethodID methodID,     \
    765         ...)                                                                \
    766     {                                                                       \
    767         _jtype result;                                                      \
    768         va_list args;                                                       \
    769         va_start(args, methodID);                                           \
    770         result = functions->CallStatic##_jname##MethodV(this, clazz,        \
    771                     methodID, args);                                        \
    772         va_end(args);                                                       \
    773         return result;                                                      \
    774     }
    775 #define CALL_STATIC_TYPE_METHODV(_jtype, _jname)                            \
    776     __NDK_FPABI__                                                           \
    777     _jtype CallStatic##_jname##MethodV(jclass clazz, jmethodID methodID,    \
    778         va_list args)                                                       \
    779     { return functions->CallStatic##_jname##MethodV(this, clazz, methodID,  \
    780         args); }
    781 #define CALL_STATIC_TYPE_METHODA(_jtype, _jname)                            \
    782     __NDK_FPABI__                                                           \
    783     _jtype CallStatic##_jname##MethodA(jclass clazz, jmethodID methodID,    \
    784         jvalue* args)                                                       \
    785     { return functions->CallStatic##_jname##MethodA(this, clazz, methodID,  \
    786         args); }
    787 
    788 #define CALL_STATIC_TYPE(_jtype, _jname)                                    \
    789     CALL_STATIC_TYPE_METHOD(_jtype, _jname)                                 \
    790     CALL_STATIC_TYPE_METHODV(_jtype, _jname)                                \
    791     CALL_STATIC_TYPE_METHODA(_jtype, _jname)
    792 
    793     CALL_STATIC_TYPE(jobject, Object)
    794     CALL_STATIC_TYPE(jboolean, Boolean)
    795     CALL_STATIC_TYPE(jbyte, Byte)
    796     CALL_STATIC_TYPE(jchar, Char)
    797     CALL_STATIC_TYPE(jshort, Short)
    798     CALL_STATIC_TYPE(jint, Int)
    799     CALL_STATIC_TYPE(jlong, Long)
    800     CALL_STATIC_TYPE(jfloat, Float)
    801     CALL_STATIC_TYPE(jdouble, Double)
    802 
    803     void CallStaticVoidMethod(jclass clazz, jmethodID methodID, ...)
    804     {
    805         va_list args;
    806         va_start(args, methodID);
    807         functions->CallStaticVoidMethodV(this, clazz, methodID, args);
    808         va_end(args);
    809     }
    810     void CallStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args)
    811     { functions->CallStaticVoidMethodV(this, clazz, methodID, args); }
    812     void CallStaticVoidMethodA(jclass clazz, jmethodID methodID, jvalue* args)
    813     { functions->CallStaticVoidMethodA(this, clazz, methodID, args); }
    814 
    815     jfieldID GetStaticFieldID(jclass clazz, const char* name, const char* sig)
    816     { return functions->GetStaticFieldID(this, clazz, name, sig); }
    817 
    818     jobject GetStaticObjectField(jclass clazz, jfieldID fieldID)
    819     { return functions->GetStaticObjectField(this, clazz, fieldID); }
    820     jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID)
    821     { return functions->GetStaticBooleanField(this, clazz, fieldID); }
    822     jbyte GetStaticByteField(jclass clazz, jfieldID fieldID)
    823     { return functions->GetStaticByteField(this, clazz, fieldID); }
    824     jchar GetStaticCharField(jclass clazz, jfieldID fieldID)
    825     { return functions->GetStaticCharField(this, clazz, fieldID); }
    826     jshort GetStaticShortField(jclass clazz, jfieldID fieldID)
    827     { return functions->GetStaticShortField(this, clazz, fieldID); }
    828     jint GetStaticIntField(jclass clazz, jfieldID fieldID)
    829     { return functions->GetStaticIntField(this, clazz, fieldID); }
    830     jlong GetStaticLongField(jclass clazz, jfieldID fieldID)
    831     { return functions->GetStaticLongField(this, clazz, fieldID); }
    832     __NDK_FPABI__
    833     jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID)
    834     { return functions->GetStaticFloatField(this, clazz, fieldID); }
    835     __NDK_FPABI__
    836     jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID)
    837     { return functions->GetStaticDoubleField(this, clazz, fieldID); }
    838 
    839     void SetStaticObjectField(jclass clazz, jfieldID fieldID, jobject value)
    840     { functions->SetStaticObjectField(this, clazz, fieldID, value); }
    841     void SetStaticBooleanField(jclass clazz, jfieldID fieldID, jboolean value)
    842     { functions->SetStaticBooleanField(this, clazz, fieldID, value); }
    843     void SetStaticByteField(jclass clazz, jfieldID fieldID, jbyte value)
    844     { functions->SetStaticByteField(this, clazz, fieldID, value); }
    845     void SetStaticCharField(jclass clazz, jfieldID fieldID, jchar value)
    846     { functions->SetStaticCharField(this, clazz, fieldID, value); }
    847     void SetStaticShortField(jclass clazz, jfieldID fieldID, jshort value)
    848     { functions->SetStaticShortField(this, clazz, fieldID, value); }
    849     void SetStaticIntField(jclass clazz, jfieldID fieldID, jint value)
    850     { functions->SetStaticIntField(this, clazz, fieldID, value); }
    851     void SetStaticLongField(jclass clazz, jfieldID fieldID, jlong value)
    852     { functions->SetStaticLongField(this, clazz, fieldID, value); }
    853     __NDK_FPABI__
    854     void SetStaticFloatField(jclass clazz, jfieldID fieldID, jfloat value)
    855     { functions->SetStaticFloatField(this, clazz, fieldID, value); }
    856     __NDK_FPABI__
    857     void SetStaticDoubleField(jclass clazz, jfieldID fieldID, jdouble value)
    858     { functions->SetStaticDoubleField(this, clazz, fieldID, value); }
    859 
    860     jstring NewString(const jchar* unicodeChars, jsize len)
    861     { return functions->NewString(this, unicodeChars, len); }
    862 
    863     jsize GetStringLength(jstring string)
    864     { return functions->GetStringLength(this, string); }
    865 
    866     const jchar* GetStringChars(jstring string, jboolean* isCopy)
    867     { return functions->GetStringChars(this, string, isCopy); }
    868 
    869     void ReleaseStringChars(jstring string, const jchar* chars)
    870     { functions->ReleaseStringChars(this, string, chars); }
    871 
    872     jstring NewStringUTF(const char* bytes)
    873     { return functions->NewStringUTF(this, bytes); }
    874 
    875     jsize GetStringUTFLength(jstring string)
    876     { return functions->GetStringUTFLength(this, string); }
    877 
    878     const char* GetStringUTFChars(jstring string, jboolean* isCopy)
    879     { return functions->GetStringUTFChars(this, string, isCopy); }
    880 
    881     void ReleaseStringUTFChars(jstring string, const char* utf)
    882     { functions->ReleaseStringUTFChars(this, string, utf); }
    883 
    884     jsize GetArrayLength(jarray array)
    885     { return functions->GetArrayLength(this, array); }
    886 
    887     jobjectArray NewObjectArray(jsize length, jclass elementClass,
    888         jobject initialElement)
    889     { return functions->NewObjectArray(this, length, elementClass,
    890         initialElement); }
    891 
    892     jobject GetObjectArrayElement(jobjectArray array, jsize index)
    893     { return functions->GetObjectArrayElement(this, array, index); }
    894 
    895     void SetObjectArrayElement(jobjectArray array, jsize index, jobject value)
    896     { functions->SetObjectArrayElement(this, array, index, value); }
    897 
    898     jbooleanArray NewBooleanArray(jsize length)
    899     { return functions->NewBooleanArray(this, length); }
    900     jbyteArray NewByteArray(jsize length)
    901     { return functions->NewByteArray(this, length); }
    902     jcharArray NewCharArray(jsize length)
    903     { return functions->NewCharArray(this, length); }
    904     jshortArray NewShortArray(jsize length)
    905     { return functions->NewShortArray(this, length); }
    906     jintArray NewIntArray(jsize length)
    907     { return functions->NewIntArray(this, length); }
    908     jlongArray NewLongArray(jsize length)
    909     { return functions->NewLongArray(this, length); }
    910     jfloatArray NewFloatArray(jsize length)
    911     { return functions->NewFloatArray(this, length); }
    912     jdoubleArray NewDoubleArray(jsize length)
    913     { return functions->NewDoubleArray(this, length); }
    914 
    915     jboolean* GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy)
    916     { return functions->GetBooleanArrayElements(this, array, isCopy); }
    917     jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy)
    918     { return functions->GetByteArrayElements(this, array, isCopy); }
    919     jchar* GetCharArrayElements(jcharArray array, jboolean* isCopy)
    920     { return functions->GetCharArrayElements(this, array, isCopy); }
    921     jshort* GetShortArrayElements(jshortArray array, jboolean* isCopy)
    922     { return functions->GetShortArrayElements(this, array, isCopy); }
    923     jint* GetIntArrayElements(jintArray array, jboolean* isCopy)
    924     { return functions->GetIntArrayElements(this, array, isCopy); }
    925     jlong* GetLongArrayElements(jlongArray array, jboolean* isCopy)
    926     { return functions->GetLongArrayElements(this, array, isCopy); }
    927     jfloat* GetFloatArrayElements(jfloatArray array, jboolean* isCopy)
    928     { return functions->GetFloatArrayElements(this, array, isCopy); }
    929     jdouble* GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy)
    930     { return functions->GetDoubleArrayElements(this, array, isCopy); }
    931 
    932     void ReleaseBooleanArrayElements(jbooleanArray array, jboolean* elems,
    933         jint mode)
    934     { functions->ReleaseBooleanArrayElements(this, array, elems, mode); }
    935     void ReleaseByteArrayElements(jbyteArray array, jbyte* elems,
    936         jint mode)
    937     { functions->ReleaseByteArrayElements(this, array, elems, mode); }
    938     void ReleaseCharArrayElements(jcharArray array, jchar* elems,
    939         jint mode)
    940     { functions->ReleaseCharArrayElements(this, array, elems, mode); }
    941     void ReleaseShortArrayElements(jshortArray array, jshort* elems,
    942         jint mode)
    943     { functions->ReleaseShortArrayElements(this, array, elems, mode); }
    944     void ReleaseIntArrayElements(jintArray array, jint* elems,
    945         jint mode)
    946     { functions->ReleaseIntArrayElements(this, array, elems, mode); }
    947     void ReleaseLongArrayElements(jlongArray array, jlong* elems,
    948         jint mode)
    949     { functions->ReleaseLongArrayElements(this, array, elems, mode); }
    950     void ReleaseFloatArrayElements(jfloatArray array, jfloat* elems,
    951         jint mode)
    952     { functions->ReleaseFloatArrayElements(this, array, elems, mode); }
    953     void ReleaseDoubleArrayElements(jdoubleArray array, jdouble* elems,
    954         jint mode)
    955     { functions->ReleaseDoubleArrayElements(this, array, elems, mode); }
    956 
    957     void GetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len,
    958         jboolean* buf)
    959     { functions->GetBooleanArrayRegion(this, array, start, len, buf); }
    960     void GetByteArrayRegion(jbyteArray array, jsize start, jsize len,
    961         jbyte* buf)
    962     { functions->GetByteArrayRegion(this, array, start, len, buf); }
    963     void GetCharArrayRegion(jcharArray array, jsize start, jsize len,
    964         jchar* buf)
    965     { functions->GetCharArrayRegion(this, array, start, len, buf); }
    966     void GetShortArrayRegion(jshortArray array, jsize start, jsize len,
    967         jshort* buf)
    968     { functions->GetShortArrayRegion(this, array, start, len, buf); }
    969     void GetIntArrayRegion(jintArray array, jsize start, jsize len,
    970         jint* buf)
    971     { functions->GetIntArrayRegion(this, array, start, len, buf); }
    972     void GetLongArrayRegion(jlongArray array, jsize start, jsize len,
    973         jlong* buf)
    974     { functions->GetLongArrayRegion(this, array, start, len, buf); }
    975     void GetFloatArrayRegion(jfloatArray array, jsize start, jsize len,
    976         jfloat* buf)
    977     { functions->GetFloatArrayRegion(this, array, start, len, buf); }
    978     void GetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len,
    979         jdouble* buf)
    980     { functions->GetDoubleArrayRegion(this, array, start, len, buf); }
    981 
    982     void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len,
    983         const jboolean* buf)
    984     { functions->SetBooleanArrayRegion(this, array, start, len, buf); }
    985     void SetByteArrayRegion(jbyteArray array, jsize start, jsize len,
    986         const jbyte* buf)
    987     { functions->SetByteArrayRegion(this, array, start, len, buf); }
    988     void SetCharArrayRegion(jcharArray array, jsize start, jsize len,
    989         const jchar* buf)
    990     { functions->SetCharArrayRegion(this, array, start, len, buf); }
    991     void SetShortArrayRegion(jshortArray array, jsize start, jsize len,
    992         const jshort* buf)
    993     { functions->SetShortArrayRegion(this, array, start, len, buf); }
    994     void SetIntArrayRegion(jintArray array, jsize start, jsize len,
    995         const jint* buf)
    996     { functions->SetIntArrayRegion(this, array, start, len, buf); }
    997     void SetLongArrayRegion(jlongArray array, jsize start, jsize len,
    998         const jlong* buf)
    999     { functions->SetLongArrayRegion(this, array, start, len, buf); }
   1000     void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len,
   1001         const jfloat* buf)
   1002     { functions->SetFloatArrayRegion(this, array, start, len, buf); }
   1003     void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len,
   1004         const jdouble* buf)
   1005     { functions->SetDoubleArrayRegion(this, array, start, len, buf); }
   1006 
   1007     jint RegisterNatives(jclass clazz, const JNINativeMethod* methods,
   1008         jint nMethods)
   1009     { return functions->RegisterNatives(this, clazz, methods, nMethods); }
   1010 
   1011     jint UnregisterNatives(jclass clazz)
   1012     { return functions->UnregisterNatives(this, clazz); }
   1013 
   1014     jint MonitorEnter(jobject obj)
   1015     { return functions->MonitorEnter(this, obj); }
   1016 
   1017     jint MonitorExit(jobject obj)
   1018     { return functions->MonitorExit(this, obj); }
   1019 
   1020     jint GetJavaVM(JavaVM** vm)
   1021     { return functions->GetJavaVM(this, vm); }
   1022 
   1023     void GetStringRegion(jstring str, jsize start, jsize len, jchar* buf)
   1024     { functions->GetStringRegion(this, str, start, len, buf); }
   1025 
   1026     void GetStringUTFRegion(jstring str, jsize start, jsize len, char* buf)
   1027     { return functions->GetStringUTFRegion(this, str, start, len, buf); }
   1028 
   1029     void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy)
   1030     { return functions->GetPrimitiveArrayCritical(this, array, isCopy); }
   1031 
   1032     void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode)
   1033     { functions->ReleasePrimitiveArrayCritical(this, array, carray, mode); }
   1034 
   1035     const jchar* GetStringCritical(jstring string, jboolean* isCopy)
   1036     { return functions->GetStringCritical(this, string, isCopy); }
   1037 
   1038     void ReleaseStringCritical(jstring string, const jchar* carray)
   1039     { functions->ReleaseStringCritical(this, string, carray); }
   1040 
   1041     jweak NewWeakGlobalRef(jobject obj)
   1042     { return functions->NewWeakGlobalRef(this, obj); }
   1043 
   1044     void DeleteWeakGlobalRef(jweak obj)
   1045     { functions->DeleteWeakGlobalRef(this, obj); }
   1046 
   1047     jboolean ExceptionCheck()
   1048     { return functions->ExceptionCheck(this); }
   1049 
   1050     jobject NewDirectByteBuffer(void* address, jlong capacity)
   1051     { return functions->NewDirectByteBuffer(this, address, capacity); }
   1052 
   1053     void* GetDirectBufferAddress(jobject buf)
   1054     { return functions->GetDirectBufferAddress(this, buf); }
   1055 
   1056     jlong GetDirectBufferCapacity(jobject buf)
   1057     { return functions->GetDirectBufferCapacity(this, buf); }
   1058 
   1059     /* added in JNI 1.6 */
   1060     jobjectRefType GetObjectRefType(jobject obj)
   1061     { return functions->GetObjectRefType(this, obj); }
   1062 #endif /*__cplusplus*/
   1063 };
   1064 
   1065 
   1066 /*
   1067  * JNI invocation interface.
   1068  */
   1069 struct JNIInvokeInterface {
   1070     void*       reserved0;
   1071     void*       reserved1;
   1072     void*       reserved2;
   1073 
   1074     jint        (*DestroyJavaVM)(JavaVM*);
   1075     jint        (*AttachCurrentThread)(JavaVM*, JNIEnv**, void*);
   1076     jint        (*DetachCurrentThread)(JavaVM*);
   1077     jint        (*GetEnv)(JavaVM*, void**, jint);
   1078     jint        (*AttachCurrentThreadAsDaemon)(JavaVM*, JNIEnv**, void*);
   1079 };
   1080 
   1081 /*
   1082  * C++ version.
   1083  */
   1084 struct _JavaVM {
   1085     const struct JNIInvokeInterface* functions;
   1086 
   1087 #if defined(__cplusplus)
   1088     jint DestroyJavaVM()
   1089     { return functions->DestroyJavaVM(this); }
   1090     jint AttachCurrentThread(JNIEnv** p_env, void* thr_args)
   1091     { return functions->AttachCurrentThread(this, p_env, thr_args); }
   1092     jint DetachCurrentThread()
   1093     { return functions->DetachCurrentThread(this); }
   1094     jint GetEnv(void** env, jint version)
   1095     { return functions->GetEnv(this, env, version); }
   1096     jint AttachCurrentThreadAsDaemon(JNIEnv** p_env, void* thr_args)
   1097     { return functions->AttachCurrentThreadAsDaemon(this, p_env, thr_args); }
   1098 #endif /*__cplusplus*/
   1099 };
   1100 
   1101 struct JavaVMAttachArgs {
   1102     jint        version;    /* must be >= JNI_VERSION_1_2 */
   1103     const char* name;       /* NULL or name of thread as modified UTF-8 str */
   1104     jobject     group;      /* global ref of a ThreadGroup object, or NULL */
   1105 };
   1106 typedef struct JavaVMAttachArgs JavaVMAttachArgs;
   1107 
   1108 /*
   1109  * JNI 1.2+ initialization.  (As of 1.6, the pre-1.2 structures are no
   1110  * longer supported.)
   1111  */
   1112 typedef struct JavaVMOption {
   1113     const char* optionString;
   1114     void*       extraInfo;
   1115 } JavaVMOption;
   1116 
   1117 typedef struct JavaVMInitArgs {
   1118     jint        version;    /* use JNI_VERSION_1_2 or later */
   1119 
   1120     jint        nOptions;
   1121     JavaVMOption* options;
   1122     jboolean    ignoreUnrecognized;
   1123 } JavaVMInitArgs;
   1124 
   1125 #ifdef __cplusplus
   1126 extern "C" {
   1127 #endif
   1128 /*
   1129  * VM initialization functions.
   1130  *
   1131  * Note these are the only symbols exported for JNI by the VM.
   1132  */
   1133 #if 0  /* In practice, these are not exported by the NDK so don't declare them */
   1134 jint JNI_GetDefaultJavaVMInitArgs(void*);
   1135 jint JNI_CreateJavaVM(JavaVM**, JNIEnv**, void*);
   1136 jint JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*);
   1137 #endif
   1138 
   1139 #define JNIIMPORT
   1140 #define JNIEXPORT  __attribute__ ((visibility ("default")))
   1141 #define JNICALL __NDK_FPABI__
   1142 
   1143 /*
   1144  * Prototypes for functions exported by loadable shared libs.  These are
   1145  * called by JNI, not provided by JNI.
   1146  */
   1147 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved);
   1148 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved);
   1149 
   1150 #ifdef __cplusplus
   1151 }
   1152 #endif
   1153 
   1154 
   1155 /*
   1156  * Manifest constants.
   1157  */
   1158 #define JNI_FALSE   0
   1159 #define JNI_TRUE    1
   1160 
   1161 #define JNI_VERSION_1_1 0x00010001
   1162 #define JNI_VERSION_1_2 0x00010002
   1163 #define JNI_VERSION_1_4 0x00010004
   1164 #define JNI_VERSION_1_6 0x00010006
   1165 
   1166 #define JNI_OK          (0)         /* no error */
   1167 #define JNI_ERR         (-1)        /* generic error */
   1168 #define JNI_EDETACHED   (-2)        /* thread detached from the VM */
   1169 #define JNI_EVERSION    (-3)        /* JNI version error */
   1170 
   1171 #define JNI_COMMIT      1           /* copy content, do not free buffer */
   1172 #define JNI_ABORT       2           /* free buffer w/o copying back */
   1173 
   1174 #endif  /* JNI_H_ */
   1175