您的位置:首页 > 其它

GetByteArrayElements 在DalVik的实现

2012-05-19 22:06 603 查看
今天想看看android 虚拟机 GetByteArrayElements 的实现,一直没发现。分析才知,它被藏在宏里面了。

PRIMITIVE_ARRAY_FUNCTIONS(jbyte, Byte); =》展开了宏包含了一系列函数

PRIMITIVE_ARRAY_FUNCTIONS 宏定义是

#define PRIMITIVE_ARRAY_FUNCTIONS(_ctype, _jname) \

GET_PRIMITIVE_ARRAY_ELEMENTS(_ctype, _jname); \

RELEASE_PRIMITIVE_ARRAY_ELEMENTS(_ctype, _jname); \

GET_PRIMITIVE_ARRAY_REGION(_ctype, _jname); \

SET_PRIMITIVE_ARRAY_REGION(_ctype, _jname);

其中GET_PRIMITIVE_ARRAY_ELEMENTS的定义如下:

#define GET_PRIMITIVE_ARRAY_ELEMENTS(_ctype, _jname) \

static _ctype* Get##_jname##ArrayElements(JNIEnv* env, \

_ctype##Array jarr, jboolean* isCopy) \

{ \

ScopedJniThreadState ts(env); \

ArrayObject* arrayObj = (ArrayObject*) dvmDecodeIndirectRef(env, jarr); \

pinPrimitiveArray(arrayObj); \

_ctype* data = (_ctype*) (void*) arrayObj->contents; \

if (isCopy != NULL) { \

*isCopy = JNI_FALSE; \

} \

return data; \

}

都在jni.cpp 这个文件里。

可以发现是不复制的(*isCopy = JNI_FALSE;)的,是pin来的:pinPrimitiveArray(arrayObj);

pin的中文在这里不知道是怎么说?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: