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的中文在这里不知道是怎么说?
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的中文在这里不知道是怎么说?
相关文章推荐
- (原)JNI中env->GetByteArrayElements和AndroidBitmap_getInfo的冲突
- jni调用GetByteArrayElements
- C/C++中GetByteArrayElements使用区别
- jni 调用找不到GetByteArrayElements的解决方法
- GetByteArrayElements和ReleaseByteArrayElements
- GetByteArrayElements和ReleaseByteArrayElements
- 用getElementsByName实现复选框的全选、全不选、反选
- 通过document.getElementsByName来实现 复选框的全选,全部选,反选
- 用原生JS实现getElementsByClass
- getByte()和toCharArray()的用法
- getElementsByClassName函数实现获取指定类名的子元素列表
- Dom4j递归解析XML实现JS的getElementsByName类似方法
- js实现单元格没有内容的行隐藏document.getElementsByTagName
- Div使用name属性实现通过getElementsByName获取Div集的方法
- 通过document.getElementsById来实现 复选框的全选,全部选,反选
- 实现ES5以下兼容,Object.create()、getElementsByClassName()
- GetXXXArrayElements和ReleaseXXXArrayElements
- java:getByte()和toCharArray()的用法
- 用lua实现ByteArray和ByteArrayVarint
- document.getElementsByClassName的理想实现