< prev index next >

src/share/vm/prims/nativeLookup.cpp

Print this page




 158   char* jni_name = st.as_string();
 159 
 160   // If the loader is null we have a system class, so we attempt a lookup in
 161   // the native Java library. This takes care of any bootstrapping problems.
 162   // Note: It is critical for bootstrapping that Java_java_lang_ClassLoader_00024NativeLibrary_find
 163   // gets found the first time around - otherwise an infinite loop can occure. This is
 164   // another VM/library dependency
 165   Handle loader(THREAD, method->method_holder()->class_loader());
 166   if (loader.is_null()) {
 167     entry = lookup_special_native(jni_name);
 168     if (entry == NULL) {
 169        entry = (address) os::dll_lookup(os::native_java_library(), jni_name);
 170     }
 171     if (entry != NULL) {
 172       in_base_library = true;
 173       return entry;
 174     }
 175   }
 176 
 177   // Otherwise call static method findNative in ClassLoader
 178   KlassHandle   klass (THREAD, SystemDictionary::ClassLoader_klass());
 179   Handle name_arg = java_lang_String::create_from_str(jni_name, CHECK_NULL);
 180 
 181   JavaValue result(T_LONG);
 182   JavaCalls::call_static(&result,
 183                          klass,
 184                          vmSymbols::findNative_name(),
 185                          vmSymbols::classloader_string_long_signature(),
 186                          // Arguments
 187                          loader,
 188                          name_arg,
 189                          CHECK_NULL);
 190   entry = (address) (intptr_t) result.get_jlong();
 191 
 192   if (entry == NULL) {
 193     // findNative didn't find it, if there are any agent libraries look in them
 194     AgentLibrary* agent;
 195     for (agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
 196       entry = (address) os::dll_lookup(agent->os_lib(), jni_name);
 197       if (entry != NULL) {
 198         return entry;


 328   ResourceMark rm(THREAD);
 329 
 330   int prefix_count;
 331   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
 332   char* in_name = method->name()->as_C_string();
 333   char* wrapper_name = in_name;
 334   // last applied prefix will be first -- go backwards
 335   for (int i = prefix_count-1; i >= 0; i--) {
 336     char* prefix = prefixes[i];
 337     size_t prefix_len = strlen(prefix);
 338     if (strncmp(prefix, wrapper_name, prefix_len) == 0) {
 339       // has this prefix remove it
 340       wrapper_name += prefix_len;
 341     }
 342   }
 343   if (wrapper_name != in_name) {
 344     // we have a name for a wrapping method
 345     int wrapper_name_len = (int)strlen(wrapper_name);
 346     TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
 347     if (wrapper_symbol != NULL) {
 348       KlassHandle kh(method->method_holder());
 349       Method* wrapper_method = kh()->lookup_method(wrapper_symbol,
 350                                                                   method->signature());
 351       if (wrapper_method != NULL && !wrapper_method->is_native()) {
 352         // we found a wrapper method, use its native entry
 353         method->set_is_prefixed_native();
 354         return lookup_entry(wrapper_method, in_base_library, THREAD);
 355       }
 356     }
 357   }
 358 #endif // INCLUDE_JVMTI
 359   return NULL;
 360 }
 361 
 362 address NativeLookup::lookup_base(const methodHandle& method, bool& in_base_library, TRAPS) {
 363   address entry = NULL;
 364   ResourceMark rm(THREAD);
 365 
 366   entry = lookup_entry(method, in_base_library, THREAD);
 367   if (entry != NULL) return entry;
 368 
 369   // standard native method resolution has failed.  Check if there are any
 370   // JVM TI prefixes which have been applied to the native method name.


 385     // -verbose:jni printing
 386     if (PrintJNIResolving) {
 387       ResourceMark rm(THREAD);
 388       tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
 389         method->method_holder()->external_name(),
 390         method->name()->as_C_string());
 391     }
 392   }
 393   return method->native_function();
 394 }
 395 
 396 address NativeLookup::base_library_lookup(const char* class_name, const char* method_name, const char* signature) {
 397   EXCEPTION_MARK;
 398   bool in_base_library = true;  // SharedRuntime inits some math methods.
 399   TempNewSymbol c_name = SymbolTable::new_symbol(class_name,  CATCH);
 400   TempNewSymbol m_name = SymbolTable::new_symbol(method_name, CATCH);
 401   TempNewSymbol s_name = SymbolTable::new_symbol(signature,   CATCH);
 402 
 403   // Find the class
 404   Klass* k = SystemDictionary::resolve_or_fail(c_name, true, CATCH);
 405   instanceKlassHandle klass (THREAD, k);
 406 
 407   // Find method and invoke standard lookup
 408   methodHandle method (THREAD,
 409                        klass->uncached_lookup_method(m_name, s_name, Klass::find_overpass));
 410   address result = lookup(method, in_base_library, CATCH);
 411   assert(in_base_library, "must be in basic library");
 412   guarantee(result != NULL, "must be non NULL");
 413   return result;
 414 }


 158   char* jni_name = st.as_string();
 159 
 160   // If the loader is null we have a system class, so we attempt a lookup in
 161   // the native Java library. This takes care of any bootstrapping problems.
 162   // Note: It is critical for bootstrapping that Java_java_lang_ClassLoader_00024NativeLibrary_find
 163   // gets found the first time around - otherwise an infinite loop can occure. This is
 164   // another VM/library dependency
 165   Handle loader(THREAD, method->method_holder()->class_loader());
 166   if (loader.is_null()) {
 167     entry = lookup_special_native(jni_name);
 168     if (entry == NULL) {
 169        entry = (address) os::dll_lookup(os::native_java_library(), jni_name);
 170     }
 171     if (entry != NULL) {
 172       in_base_library = true;
 173       return entry;
 174     }
 175   }
 176 
 177   // Otherwise call static method findNative in ClassLoader
 178   Klass*   klass = SystemDictionary::ClassLoader_klass();
 179   Handle name_arg = java_lang_String::create_from_str(jni_name, CHECK_NULL);
 180 
 181   JavaValue result(T_LONG);
 182   JavaCalls::call_static(&result,
 183                          klass,
 184                          vmSymbols::findNative_name(),
 185                          vmSymbols::classloader_string_long_signature(),
 186                          // Arguments
 187                          loader,
 188                          name_arg,
 189                          CHECK_NULL);
 190   entry = (address) (intptr_t) result.get_jlong();
 191 
 192   if (entry == NULL) {
 193     // findNative didn't find it, if there are any agent libraries look in them
 194     AgentLibrary* agent;
 195     for (agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
 196       entry = (address) os::dll_lookup(agent->os_lib(), jni_name);
 197       if (entry != NULL) {
 198         return entry;


 328   ResourceMark rm(THREAD);
 329 
 330   int prefix_count;
 331   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
 332   char* in_name = method->name()->as_C_string();
 333   char* wrapper_name = in_name;
 334   // last applied prefix will be first -- go backwards
 335   for (int i = prefix_count-1; i >= 0; i--) {
 336     char* prefix = prefixes[i];
 337     size_t prefix_len = strlen(prefix);
 338     if (strncmp(prefix, wrapper_name, prefix_len) == 0) {
 339       // has this prefix remove it
 340       wrapper_name += prefix_len;
 341     }
 342   }
 343   if (wrapper_name != in_name) {
 344     // we have a name for a wrapping method
 345     int wrapper_name_len = (int)strlen(wrapper_name);
 346     TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
 347     if (wrapper_symbol != NULL) {
 348       Klass* k = method->method_holder();
 349       Method* wrapper_method = k->lookup_method(wrapper_symbol, method->signature());

 350       if (wrapper_method != NULL && !wrapper_method->is_native()) {
 351         // we found a wrapper method, use its native entry
 352         method->set_is_prefixed_native();
 353         return lookup_entry(wrapper_method, in_base_library, THREAD);
 354       }
 355     }
 356   }
 357 #endif // INCLUDE_JVMTI
 358   return NULL;
 359 }
 360 
 361 address NativeLookup::lookup_base(const methodHandle& method, bool& in_base_library, TRAPS) {
 362   address entry = NULL;
 363   ResourceMark rm(THREAD);
 364 
 365   entry = lookup_entry(method, in_base_library, THREAD);
 366   if (entry != NULL) return entry;
 367 
 368   // standard native method resolution has failed.  Check if there are any
 369   // JVM TI prefixes which have been applied to the native method name.


 384     // -verbose:jni printing
 385     if (PrintJNIResolving) {
 386       ResourceMark rm(THREAD);
 387       tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
 388         method->method_holder()->external_name(),
 389         method->name()->as_C_string());
 390     }
 391   }
 392   return method->native_function();
 393 }
 394 
 395 address NativeLookup::base_library_lookup(const char* class_name, const char* method_name, const char* signature) {
 396   EXCEPTION_MARK;
 397   bool in_base_library = true;  // SharedRuntime inits some math methods.
 398   TempNewSymbol c_name = SymbolTable::new_symbol(class_name,  CATCH);
 399   TempNewSymbol m_name = SymbolTable::new_symbol(method_name, CATCH);
 400   TempNewSymbol s_name = SymbolTable::new_symbol(signature,   CATCH);
 401 
 402   // Find the class
 403   Klass* k = SystemDictionary::resolve_or_fail(c_name, true, CATCH);
 404   InstanceKlass* klass  = InstanceKlass::cast(k);
 405 
 406   // Find method and invoke standard lookup
 407   methodHandle method (THREAD,
 408                        klass->uncached_lookup_method(m_name, s_name, Klass::find_overpass));
 409   address result = lookup(method, in_base_library, CATCH);
 410   assert(in_base_library, "must be in basic library");
 411   guarantee(result != NULL, "must be non NULL");
 412   return result;
 413 }
< prev index next >