⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kni.c

📁 已经移植好的java虚拟机
💻 C
📖 第 1 页 / 共 4 页
字号:
    return *((jfloat*)&array->data[index].cell);}jdouble KNI_GetDoubleArrayElement(jdoubleArray arrayHandle, jint index) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    union {        jdouble d; /* Platform dependent */        cell v[2];    } tmp;    int offset = index*2;    tmp.v[0] = array->data[offset  ].cell;    tmp.v[1] = array->data[offset+1].cell;    return tmp.d;}#endif/*========================================================================= * FUNCTION:       KNI_GetObjectArrayElement() * OVERVIEW:       Return an element of an object array. *                 No type checking is performed. * INTERFACE: *   parameter(s): arrayHandle: a handle to a primitive array *                 index: the index of the array element to read *                 toHandle: a handle to an object to which  *                 the return value will be assigned. *   returns:      Nothing directly, but assigns the array *                 element to 'objectHandle'. *=======================================================================*/voidKNI_GetObjectArrayElement(jobjectArray arrayHandle, jint index, jobject toHandle) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    KNI_SETHAND(toHandle, array->data[index].cell);}/*========================================================================= * FUNCTION:       KNI_Set<Type>ArrayElement() * OVERVIEW:       Set the element of a primitive array. *                 No type checking is performed. * INTERFACE: *   parameter(s): objectArray: a handle to a primitive array *                 index: the index of the array element *                 value: the value that will be stored *   returns:      <nothing> *=======================================================================*/voidKNI_SetBooleanArrayElement(jbooleanArray arrayHandle, jint index, jboolean value) {    BYTEARRAY array = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->bdata[index] = value;}void KNI_SetByteArrayElement(jbyteArray arrayHandle, jint index, jbyte value) {    BYTEARRAY array = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->bdata[index] = value;}void KNI_SetCharArrayElement(jcharArray arrayHandle, jint index, jchar value) {    SHORTARRAY array = (SHORTARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->sdata[index] = value;}void KNI_SetShortArrayElement(jshortArray arrayHandle, jint index, jshort value) {    SHORTARRAY array = (SHORTARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->sdata[index] = value;}void KNI_SetIntArrayElement(jintArray arrayHandle, jint index, jint value) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->data[index].cell = value;}void KNI_SetLongArrayElement(jlongArray arrayHandle, jint index, jlong value) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    union {        jlong j; /* Platform dependent */        cell v[2];    } tmp;    int offset = index*2;    tmp.j = value;    array->data[offset  ].cell = tmp.v[0];    array->data[offset+1].cell = tmp.v[1];}#if IMPLEMENTS_FLOATvoid KNI_SetFloatArrayElement(jfloatArray arrayHandle, jint index, jfloat value) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    *(jfloat*)&array->data[index].cell = value;}void KNI_SetDoubleArrayElement(jdoubleArray arrayHandle, jint index, jdouble value) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    union {        jdouble d; /* Platform dependent */        cell v[2];    } tmp;    int offset = index*2;    tmp.d = value;    array->data[offset  ].cell = tmp.v[0];    array->data[offset+1].cell = tmp.v[1];}#endif/*======================================================================= * FUNCTION:       KNI_SetObjectArrayElement() * OVERVIEW:       Set the element of an object array. *                 No type checking is performed. * INTERFACE: *   parameter(s): arrayHandle: a handle to a primitive array *                 index: the index of the array element *                 fromHandle: a handle to an object that will *                 be stored to the array *   returns:      <nothing> *=======================================================================*/voidKNI_SetObjectArrayElement(jobjectArray arrayHandle, jint index, jobject fromHandle) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return;    array->data[index].cell = (cell)KNI_UNHAND(fromHandle);}/*======================================================================= * FUNCTION:       KNI_GetRawArrayRegion() * OVERVIEW:       Copies a region of the contents of an array *                 into a native buffer as raw bytes.  No type *                 checking is performed (the actual type of the *                 array is ignored).  It is the responsibility *                 of the native function programmer to allocate *                 the native buffer and to make sure that it is *                 long enough (no buffer overflow checking is *                 performed). * INTERFACE: *   parameter(s): arrayHandle: a handle to an array object *                 offset: offset from which the copy region begins *                 n: the number of bytes to copy *                 dstBuffer: pointer to a native buffer to which *                 data will be copied *   returns:      nothing directly, but copies the array region *                 to the user-supplied buffer. *=======================================================================*/voidKNI_GetRawArrayRegion(jarray arrayHandle, jsize offset, jsize n, jbyte* dstBuffer) {    BYTEARRAY barray = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && (barray == 0 || dstBuffer == 0)) return;    (void)memcpy(dstBuffer, &barray->bdata[offset], n);}/*======================================================================= * FUNCTION:       KNI_SetRawArrayRegion() * OVERVIEW:       Set the contents of a region in a Java array object. *                 The data is copied as bytes from a native buffer *                 provided by the native function programmer.  No *                 type or range checking is performed. * INTERFACE: *   parameter(s): arrayHandle: a handle to an array object *                 offset: offset inside the array to which *                 the data will be copied *                 n: the number of bytes to copy *                 srcBuffer: pointer to a native buffer from which *   returns:      <nothing> *=======================================================================*/voidKNI_SetRawArrayRegion(jarray arrayHandle, jsize offset, jsize n, const jbyte* srcBuffer) {    BYTEARRAY barray = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && (barray == 0 || srcBuffer == 0)) return;    (void)memcpy(&barray->bdata[offset], srcBuffer, n);}/*========================================================================= * Operand stack (parameter) access *=======================================================================*//*========================================================================= * FUNCTION:       KNI_GetParameterAs<Type>() * OVERVIEW:       Returns the primitive value at the given index on *                 the operand stack. Indexing of parameters starts *                 from 1. Note that long and double parameters take *                 up two elements on the stack.  No range or type  *                 checking is performed. * INTERFACE: *   parameter(s): index: The index of a parameter *   returns:      value representing a primitive type *  * IMPORTANT       long and double elements take up two elements *                 on the operand stack. For example, when calling *                 the following native function * *                     native void foo(int a, long b, int c); * *                 the index of parameter 'a' would be 1,  *                 the index of parameter 'b' would be 2, and *                 the index of parameter 'c' would be 4. *=======================================================================*/jboolean KNI_GetParameterAsBoolean(jint index) {    return (jboolean)CurrentThread->nativeLp[index];}jbyte KNI_GetParameterAsByte(jint index) {    return (jbyte)CurrentThread->nativeLp[index];}jchar KNI_GetParameterAsChar(jint index) {    return (jchar)CurrentThread->nativeLp[index];}jshort KNI_GetParameterAsShort(jint index) {    return (jshort)CurrentThread->nativeLp[index];}jint KNI_GetParameterAsInt(jint index) {    return (jint)CurrentThread->nativeLp[index];}jlong KNI_GetParameterAsLong(jint index) {    jlong value;    COPY_LONG(&value, &CurrentThread->nativeLp[index]);    return value;}#if IMPLEMENTS_FLOATjfloat KNI_GetParameterAsFloat(jint index) {    return *(jfloat*)&CurrentThread->nativeLp[index];}jdouble KNI_GetParameterAsDouble(jint index) {    jdouble value;    COPY_DOUBLE(&value, &CurrentThread->nativeLp[index]);    return value;}#endif/*========================================================================= * FUNCTION:       KNI_GetParameterAsObject() * OVERVIEW:       Returns the jobject at the given index on the  *                 operand stack. Indexing of parameters starts *                 from 1. No range or type checking is performed. * INTERFACE: *   parameter(s): - index: The index of a parameter *                 - toHandle: handle to which the return value *                   will be assigned *   returns:      - nothing directly, but toHandle will contain *                   the return value. *=======================================================================*/void KNI_GetParameterAsObject(jint index, jobject toHandle) {    KNI_SETHAND(toHandle, CurrentThread->nativeLp[index]);}/*========================================================================= * FUNCTION:       KNI_GetThisPointer() * OVERVIEW:       Returns the 'this' pointer of an instance method. *                 The value of this function is undefined for static *                 methods. * INTERFACE: *   parameter(s): toHandle: handle to which the return value *                 will be assigned *   return:       nothing directly, but toHandle will contain *                 the return value. *=======================================================================*/void KNI_GetThisPointer(jobject toHandle) {    KNI_SETHAND(toHandle, CurrentThread->nativeLp[0]);}/*========================================================================= * FUNCTION:       KNI_GetClassPointer() * OVERVIEW:       Returns the class pointer (as a handle) of the  *                 class of the currently executing native method. * INTERFACE: *   parameter(s): toHandle: handle to which the return value *                 will be assigned *   return:       nothing directly, but toHandle will contain *                 the return value. *=======================================================================*/void KNI_GetClassPointer(jobject toHandle) {    KNI_SETHAND(toHandle, (cell)(getFP()->thisMethod->ofClass));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -