能力值:
( LV3,RANK:20 )
2 楼
1、在dvm创建过程中注册的。dvmStartup->dvmInternalNativeStartup->dvm_dalvik_system_Zygote DalvikNativeFunc dvmLookupInternalNativeMethod(const Method* method)
{
const char* classDescriptor = method->clazz->descriptor;
const DalvikNativeClass* pClass;
u4 hash;
hash = dvmComputeUtf8Hash(classDescriptor);
pClass = gDvmNativeMethodSet;
while (true) {
if (pClass->classDescriptor == NULL)
系统类的接口调用是不一样的。
DalvikBridgeFunc dfunc = (DalvikBridgeFunc) infunc;
dvmSetNativeFunc((Method*) method, dfunc, NULL);
dfunc(args, pResult, method, self);
return;
}
/* now scan any DLLs we have loaded for JNI signatures */
void* func = lookupSharedLibMethod(method);
if (func != NULL) {
/* found it, point it at the JNI bridge and then call it */
dvmUseJNIBridge((Method*) method, func);
(*method->nativeFunc)(args, pResult, method, self);
return;
}
系统接口的是走DalvikBridgeFunc 这个调用方式,普通的native是走下面dvmUseJNIBridge方式。
所以,参数形式是不一样的。
能力值:
( LV4,RANK:40 )
3 楼
非常感谢,看了一下,其实系统的jni函数就是相当于普通jni函数的桥函数 ,系统jni的注册只是初始化一个表 ,以方便 dvmLookupInternalNativeMethod能找到
90 DalvikNativeFunc infunc = dvmLookupInternalNativeMethod(method);
91 if (infunc != NULL) {
92 /* resolution always gets the same answer, so no race here */
93 IF_LOGVV() {
94 char* desc = dexProtoCopyMethodDescriptor(&method->prototype);
95 LOGVV("+++ resolved native %s.%s %s, invoking",
96 clazz->descriptor, method->name, desc);
97 free(desc);
98 }
99 if (dvmIsSynchronizedMethod(method)) {
100 ALOGE("ERROR: internal-native can't be declared 'synchronized'");
101 ALOGE("Failing on %s.%s", method->clazz->descriptor, method->name);
102 dvmAbort(); // harsh, but this is VM-internal problem
103 }
104 DalvikBridgeFunc dfunc = (DalvikBridgeFunc) infunc;
105 dvmSetNativeFunc((Method*) method, dfunc, NULL); //设置下nativefunc 下次再调用 就直接走这个native函数了
106 dfunc(args, pResult, method, self);
107 return;
108 }