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

📄 kni.c

📁 Nucleus_2_kvm_Hello 是kvm移植到Nucleus系统的源代码。。。好东西啊
💻 C
📖 第 1 页 / 共 4 页
字号:
 * FUNCTION:       KNI_SetStatic<Type>Field() * OVERVIEW:       Set the value of a primitive static field. *                 No type checking is performed. * INTERFACE: *   parameter(s): classHandle: handle to an class *                 fid: a fieldID *                 value: the value to be assigned *   returns:      <nothing> * NOTE:           The KVM implementation of KNI does not need the *                 'classHandle' parameter. *=======================================================================*/voidKNI_SetStaticBooleanField(jclass classHandle, jfieldID fid, jboolean value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jint*)fid->u.staticAddress) = value;}voidKNI_SetStaticByteField(jclass classHandle, jfieldID fid, jbyte value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jint*)fid->u.staticAddress) = value;}voidKNI_SetStaticCharField(jclass classHandle, jfieldID fid, jchar value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jint*)fid->u.staticAddress) = value;}voidKNI_SetStaticShortField(jclass classHandle, jfieldID fid, jshort value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jint*)fid->u.staticAddress) = value;}voidKNI_SetStaticIntField(jclass classHandle, jfieldID fid, jint value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jint*)fid->u.staticAddress) = value;}voidKNI_SetStaticLongField(jclass classHandle, jfieldID fid, jlong value) {    union {        jlong j; /* Platform dependent */        cell v[2];    } tmp;    tmp.j = value;    *((cell*)fid->u.staticAddress    ) = tmp.v[0];    *((cell*)fid->u.staticAddress + 1) = tmp.v[1];}#if IMPLEMENTS_FLOATvoidKNI_SetStaticFloatField(jclass classHandle, jfieldID fid, jfloat value) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *((jfloat*)fid->u.staticAddress) = value;}voidKNI_SetStaticDoubleField(jclass classHandle, jfieldID fid, jdouble value) {    union {        jdouble d; /* Platform dependent */        cell v[2];    } tmp;    tmp.d = value;    *((cell*)fid->u.staticAddress    ) = tmp.v[0];    *((cell*)fid->u.staticAddress + 1) = tmp.v[1];}#endif/*======================================================================= * FUNCTION:       KNI_SetStaticObjectField() * OVERVIEW:       Set the value of a static field containing *                 an object.  No type checking is performed. * INTERFACE: *   parameter(s): classHandle: a handle to a class whose field *                 is to be changed. *                 fid: a fieldID *                 fromHandle: a handle to an object that is to be *                 to be assigned to 'classHandle'. *   returns:      <nothing> * NOTE:           The KVM implementation of KNI does not need the *                 'classHandle' parameter. *=======================================================================*/void KNI_SetStaticObjectField(jclass classHandle, jfieldID fid, jobject fromHandle) {    if (INCLUDEDEBUGCODE && fid == 0) return;    *(cell*)fid->u.staticAddress = (cell)KNI_UNHAND(fromHandle);}/*========================================================================= * String operations *=======================================================================*//*======================================================================= * FUNCTION:       KNI_GetStringLength() * OVERVIEW:       Returns the number of Unicode characters in a *                 java.lang.String object.  No type checking is *                 performed. * INTERFACE: *   parameter(s): stringHandle: a handle to a java.lang.String object. *   returns:      Length of the string as jsize, or -1 if the  *                 string handle was empty. *=======================================================================*/jsize KNI_GetStringLength(jstring stringHandle) {    STRING_INSTANCE string = (STRING_INSTANCE)KNI_UNHAND(stringHandle);    if (string == 0) return -1;    return string->length;}/*======================================================================= * FUNCTION:       KNI_GetStringRegion() * OVERVIEW:       Copies a region of the contents of a java.lang.String  *                 object into a native buffer.  Characters are returned  *                 as Unicode, i.e., each character is 16 bits wide. *                 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): stringHandle: a handle to a java.lang.String object *                 offset: offset from which the copy region begins *                 n: the number of characters to copy *                 jcharbuf: pointer to a native buffer *   returns:      nothing directly, but copies the string region *                 to the user-supplied buffer. *=======================================================================*/void KNI_GetStringRegion(jstring stringHandle, jsize offset, jsize n, jchar* jcharbuf) {    STRING_INSTANCE string = (STRING_INSTANCE)KNI_UNHAND(stringHandle);    SHORTARRAY stringContents;    long stroffset;    long strlength;    long i;    if (INCLUDEDEBUGCODE && string == 0) return;    stringContents = string->array;    stroffset      = string->offset;    strlength      = string->length;    /*     * Invariants:     *   1) offset >= 0,     *   2) n > 0, and     *   3) offset + n <= strlength     *     * Boundary conditions:     *   1) offset == 0 and n == strlength, and     *   2) offset == strlength and n == 0     *     *   Note: 2) should not return any data, by definition (e.g.,     *   a region of zero length is just that)     */    if (offset >= 0 && n > 0 && (offset + n) <= strlength) {        for (i = 0; i < n; i++) {            jcharbuf[i] = ((unsigned short*)stringContents->sdata)[i + stroffset + offset];        }    }}/*======================================================================= * FUNCTION:       KNI_NewString() * OVERVIEW:       Creates a java.lang.String object. * INTERFACE: *   parameter(s): uchars: a Unicode string (each character is 16 bits *                 wide, no terminating zero assumed) *                 length: the number of characters in the Unicode string *                 stringHandle: a handle to which the new string *                 object will be assigned. *   returns:      nothing directly, but 'stringHandle' will contain *                 the new string or NULL if no string could be created. * NOTE:           This operation may cause a garbage collection! *=======================================================================*/void KNI_NewString(const jchar* uchars, jsize length, jstring stringHandle) {    STRING_INSTANCE newString;    int i;    int arraySize = SIZEOF_ARRAY((length * 2 + (CELL - 1)) >> log2CELL);    START_TEMPORARY_ROOTS        /*  Allocate a character array */        DECLARE_TEMPORARY_ROOT(SHORTARRAY, newArray,             (SHORTARRAY)callocObject(arraySize, GCT_ARRAY));        newArray->ofClass = PrimitiveArrayClasses[T_CHAR];        newArray->length  = length;        /*  Initialize the character array with string contents */        for (i = 0; i < length; i++) {             newArray->sdata[i] = uchars[i];        }        /* Allocate a new string object (no temporary roots used, */        /* so we must not garbage collect after this call) */        newString = (STRING_INSTANCE)instantiate(JavaLangString);        newString->offset = 0;        newString->length = length;        newString->array  = newArray;    END_TEMPORARY_ROOTS    KNI_SETHAND(stringHandle, newString);}/*======================================================================= * FUNCTION:       KNI_NewStringUTF() * OVERVIEW:       Creates a java.lang.String object. * INTERFACE: *   parameter(s): utf8chars: the string contents as a UTF8 string *                 stringHandle: a handle to which the new string *                 object will be assigned. *   returns:      nothing directly, but 'stringHandle' will contain *                 the new string or NULL if no string could be created. * NOTE:           This operation may cause a garbage collection! *=======================================================================*/void KNI_NewStringUTF(const char* utf8chars, jstring stringHandle) {    KNI_SETHAND(stringHandle, instantiateString(utf8chars, strlen(utf8chars)));}/*========================================================================= * Array operations *=======================================================================*//*======================================================================= * FUNCTION:       KNI_GetArrayLength() * OVERVIEW:       Returns the number of elements in an array * INTERFACE: *   parameter(s): arrayHandle: a handle to an array object. *   returns:      Length of the array as jsize, or -1 if the  *                 array handle was empty. *=======================================================================*/jsize KNI_GetArrayLength(jstring arrayHandle) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (array == 0) return -1;    return array->length;}/*========================================================================= * FUNCTION:       KNI_Get<Type>ArrayElement() * OVERVIEW:       Return an element of a primitive 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 *   returns:      The value of the requested element in the array. *=======================================================================*/jboolean KNI_GetBooleanArrayElement(jbooleanArray arrayHandle, jint index) {    BYTEARRAY array = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;    return (jboolean)array->bdata[index];}jbyte KNI_GetByteArrayElement(jbyteArray arrayHandle, jint index) {    BYTEARRAY array = (BYTEARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;    return (jbyte)array->bdata[index];}jchar KNI_GetCharArrayElement(jcharArray arrayHandle, jint index) {    SHORTARRAY array = (SHORTARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;    return (jchar)array->sdata[index];}jshort KNI_GetShortArrayElement(jshortArray arrayHandle, jint index) {    SHORTARRAY array = (SHORTARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;    return (jshort)array->sdata[index];}jint KNI_GetIntArrayElement(jintArray arrayHandle, jint index) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;    return (jint)array->data[index].cell;}jlong KNI_GetLongArrayElement(jlongArray arrayHandle, jint index) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    union {        jlong j; /* 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.j;}#if IMPLEMENTS_FLOATjfloat KNI_GetFloatArrayElement(jfloatArray arrayHandle, jint index) {    ARRAY array = (ARRAY)KNI_UNHAND(arrayHandle);    if (INCLUDEDEBUGCODE && array == 0) return 0;

⌨️ 快捷键说明

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