Object 的 registerNatives() 方法的作用
来源:互联网 发布:oracle数据库去重复 编辑:程序博客网 时间:2024/05/01 21:12
Normally, in order for the JVM to find your native functions, they have to be named a certain way. e.g., for java.lang.Object.registerNatives, the corresponding C function is named Java_java_lang_Object_registerNatives. By using registerNatives (or rather, the JNI function RegisterNatives), you can name your C functions whatever you want.
Here’s the associated C code (from OpenJDK 6):
static JNINativeMethod methods[] = {
{“hashCode”, “()I”, (void *)&JVM_IHashCode},
{“wait”, “(J)V”, (void *)&JVM_MonitorWait},
{“notify”, “()V”, (void *)&JVM_MonitorNotify},
{“notifyAll”, “()V”, (void *)&JVM_MonitorNotifyAll},
{“clone”, “()Ljava/lang/Object;”, (void *)&JVM_Clone},
};
JNIEXPORT void JNICALL
Java_java_lang_Object_registerNatives(JNIEnv *env, jclass cls)
{
(*env)->RegisterNatives(env, cls,
methods, sizeof(methods)/sizeof(methods[0]));
}
(Notice that Object.getClass is not in the list; it will still be called by the “standard” name of Java_java_lang_Object_getClass.) For the functions listed, the associated C functions are as listed in that table, which is handier than writing a bunch of forwarding functions.
Registering native functions is also useful if you are embedding Java in your C program and want to link to functions within the application itself (as opposed to within a shared library), or the functions being used aren’t otherwise “exported”, since these would not normally be found by the standard method lookup mechanism. Registering native functions can also be used to “rebind” a native method to another C function (useful if your program supports dynamically loading and unloading modules, for example).
I encourage everybody to read the JNI book, which talks about this and much more.
- Object 的 registerNatives() 方法的作用
- Object 的 registerNatives() 方法的作用
- 关于Object类里的本地方法registerNatives
- JAVA源码分析之---Object类(一)---registerNatives,getClass方法的使用
- JNI_OnLoad方法和RegisterNatives方法的结合
- JNI方法的静态注册和动态注册RegisterNatives
- Object的几种方法及其作用
- object的常用方法及作用
- Object类中各个方法的作用
- 实现JNI的另一种方法:使用RegisterNatives方法传递和使用Java自定义类 (转)
- object 的作用
- (object)$array的作用
- 十八、Object类的各个方法及其作用
- session.merge(object)的作用
- 理解Object.defineProperty的作用
- 理解Object.defineProperty的作用
- 理解Object.defineProperty的作用
- Android中JNI 的一些常用说明 JNI_OnLoad registerNatives registerNativeMethods
- Android 中Native方法是怎样调用的
- HashMap和HashTable的区别和不同
- ExtJS登录例子
- USB-serial 串口测试
- 西西
- Object 的 registerNatives() 方法的作用
- 如何中断线程
- 最常用邮件服务器地址
- STRUTS2获得session和request
- 简述Struts2 Convention零配置
- struts2获取session与request对象
- Struts2中Session的使用方法
- 深入理解Direct3D9
- 管道流