src/share/vm/prims/nativeLookup.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot-npg Sdiff src/share/vm/prims

src/share/vm/prims/nativeLookup.cpp

Print this page




 311 
 312   // 2) Try JNI long style
 313   entry = lookup_critical_style(method, critical_name, long_name, args_size, true);
 314   if (entry != NULL) return entry;
 315 
 316   // 3) Try JNI short style without os prefix/suffix
 317   entry = lookup_critical_style(method, critical_name, "",        args_size, false);
 318   if (entry != NULL) return entry;
 319 
 320   // 4) Try JNI long style without os prefix/suffix
 321   entry = lookup_critical_style(method, critical_name, long_name, args_size, false);
 322 
 323   return entry; // NULL indicates not found
 324 }
 325 
 326 // Check if there are any JVM TI prefixes which have been applied to the native method name.
 327 // If any are found, remove them before attemping the look up of the
 328 // native implementation again.
 329 // See SetNativeMethodPrefix in the JVM TI Spec for more details.
 330 address NativeLookup::lookup_entry_prefixed(methodHandle method, bool& in_base_library, TRAPS) {

 331   ResourceMark rm(THREAD);
 332 
 333   int prefix_count;
 334   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
 335   char* in_name = method->name()->as_C_string();
 336   char* wrapper_name = in_name;
 337   // last applied prefix will be first -- go backwards
 338   for (int i = prefix_count-1; i >= 0; i--) {
 339     char* prefix = prefixes[i];
 340     size_t prefix_len = strlen(prefix);
 341     if (strncmp(prefix, wrapper_name, prefix_len) == 0) {
 342       // has this prefix remove it
 343       wrapper_name += prefix_len;
 344     }
 345   }
 346   if (wrapper_name != in_name) {
 347     // we have a name for a wrapping method
 348     int wrapper_name_len = (int)strlen(wrapper_name);
 349     TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
 350     if (wrapper_symbol != NULL) {
 351       KlassHandle kh(method->method_holder());
 352       Method* wrapper_method = Klass::cast(kh())->lookup_method(wrapper_symbol,
 353                                                                   method->signature());
 354       if (wrapper_method != NULL && !wrapper_method->is_native()) {
 355         // we found a wrapper method, use its native entry
 356         method->set_is_prefixed_native();
 357         return lookup_entry(wrapper_method, in_base_library, THREAD);
 358       }
 359     }
 360   }

 361   return NULL;
 362 }
 363 
 364 address NativeLookup::lookup_base(methodHandle method, bool& in_base_library, TRAPS) {
 365   address entry = NULL;
 366   ResourceMark rm(THREAD);
 367 
 368   entry = lookup_entry(method, in_base_library, THREAD);
 369   if (entry != NULL) return entry;
 370 
 371   // standard native method resolution has failed.  Check if there are any
 372   // JVM TI prefixes which have been applied to the native method name.
 373   entry = lookup_entry_prefixed(method, in_base_library, THREAD);
 374   if (entry != NULL) return entry;
 375 
 376   // Native function not found, throw UnsatisfiedLinkError
 377   THROW_MSG_0(vmSymbols::java_lang_UnsatisfiedLinkError(),
 378               method->name_and_sig_as_C_string());
 379 }
 380 




 311 
 312   // 2) Try JNI long style
 313   entry = lookup_critical_style(method, critical_name, long_name, args_size, true);
 314   if (entry != NULL) return entry;
 315 
 316   // 3) Try JNI short style without os prefix/suffix
 317   entry = lookup_critical_style(method, critical_name, "",        args_size, false);
 318   if (entry != NULL) return entry;
 319 
 320   // 4) Try JNI long style without os prefix/suffix
 321   entry = lookup_critical_style(method, critical_name, long_name, args_size, false);
 322 
 323   return entry; // NULL indicates not found
 324 }
 325 
 326 // Check if there are any JVM TI prefixes which have been applied to the native method name.
 327 // If any are found, remove them before attemping the look up of the
 328 // native implementation again.
 329 // See SetNativeMethodPrefix in the JVM TI Spec for more details.
 330 address NativeLookup::lookup_entry_prefixed(methodHandle method, bool& in_base_library, TRAPS) {
 331 #if INCLUDE_JVMTI
 332   ResourceMark rm(THREAD);
 333 
 334   int prefix_count;
 335   char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
 336   char* in_name = method->name()->as_C_string();
 337   char* wrapper_name = in_name;
 338   // last applied prefix will be first -- go backwards
 339   for (int i = prefix_count-1; i >= 0; i--) {
 340     char* prefix = prefixes[i];
 341     size_t prefix_len = strlen(prefix);
 342     if (strncmp(prefix, wrapper_name, prefix_len) == 0) {
 343       // has this prefix remove it
 344       wrapper_name += prefix_len;
 345     }
 346   }
 347   if (wrapper_name != in_name) {
 348     // we have a name for a wrapping method
 349     int wrapper_name_len = (int)strlen(wrapper_name);
 350     TempNewSymbol wrapper_symbol = SymbolTable::probe(wrapper_name, wrapper_name_len);
 351     if (wrapper_symbol != NULL) {
 352       KlassHandle kh(method->method_holder());
 353       Method* wrapper_method = Klass::cast(kh())->lookup_method(wrapper_symbol,
 354                                                                   method->signature());
 355       if (wrapper_method != NULL && !wrapper_method->is_native()) {
 356         // we found a wrapper method, use its native entry
 357         method->set_is_prefixed_native();
 358         return lookup_entry(wrapper_method, in_base_library, THREAD);
 359       }
 360     }
 361   }
 362 #endif // INCLUDE_JVMTI
 363   return NULL;
 364 }
 365 
 366 address NativeLookup::lookup_base(methodHandle method, bool& in_base_library, TRAPS) {
 367   address entry = NULL;
 368   ResourceMark rm(THREAD);
 369 
 370   entry = lookup_entry(method, in_base_library, THREAD);
 371   if (entry != NULL) return entry;
 372 
 373   // standard native method resolution has failed.  Check if there are any
 374   // JVM TI prefixes which have been applied to the native method name.
 375   entry = lookup_entry_prefixed(method, in_base_library, THREAD);
 376   if (entry != NULL) return entry;
 377 
 378   // Native function not found, throw UnsatisfiedLinkError
 379   THROW_MSG_0(vmSymbols::java_lang_UnsatisfiedLinkError(),
 380               method->name_and_sig_as_C_string());
 381 }
 382 


src/share/vm/prims/nativeLookup.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File