address NativeLookup::lookup_critical_style(methodHandle method, char* pure_name, const char* long_name, int args_size, bool os_style) { if (!method->has_native_function()) { return NULL; } address current_entry = method->native_function(); char dll_name[JVM_MAXPATHLEN]; int offset; if (os::dll_address_to_library_name(current_entry, dll_name, sizeof(dll_name), &offset)) { char ebuf[32]; void* dll = os::dll_load(dll_name, ebuf, sizeof(ebuf)); if (dll != NULL) { // Compute complete JNI name for style stringStream st; if (os_style) os::print_jni_name_prefix_on(&st, args_size); st.print_raw(pure_name); st.print_raw(long_name); if (os_style) os::print_jni_name_suffix_on(&st, args_size); char* jni_name = st.as_string(); return (address)os::dll_lookup(dll, jni_name); } } return NULL; }
address NativeLookup::lookup(methodHandle method, bool& in_base_library, TRAPS) { if (!method->has_native_function()) { address entry = lookup_base(method, in_base_library, CHECK_NULL); method->set_native_function(entry, Method::native_bind_event_is_interesting); // -verbose:jni printing if (PrintJNIResolving) { ResourceMark rm(THREAD); tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]", method->method_holder()->external_name(), method->name()->as_C_string()); } } return method->native_function(); }
/** * 为给定的本地java方法寻找对应的函数入口地址 */ address NativeLookup::lookup(methodHandle method, bool& in_base_library, TRAPS) { if (!method->has_native_function()) { printf("%s[%d] [tid: %lu]: 试图查找本地方法[%s.%s]..\n", __FILE__, __LINE__, pthread_self(), Klass::cast(method->method_holder())->external_name(), method->name()->as_C_string()); address entry = lookup_base(method, in_base_library, CHECK_NULL); method->set_native_function(entry, methodOopDesc::native_bind_event_is_interesting); // -verbose:jni printing if (PrintJNIResolving) { ResourceMark rm(THREAD); tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]", Klass::cast(method->method_holder())->external_name(), method->name()->as_C_string()); } } return method->native_function(); }