< prev index next >

src/hotspot/share/prims/nativeLookup.cpp

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "memory/oopFactory.hpp"
  31 #include "memory/resourceArea.hpp"

  32 #include "oops/instanceKlass.hpp"
  33 #include "oops/method.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "oops/symbol.hpp"
  36 #include "prims/jvm_misc.hpp"
  37 #include "prims/nativeLookup.hpp"
  38 #include "prims/unsafe.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/javaCalls.hpp"
  42 #include "runtime/os.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/signature.hpp"
  45 #include "utilities/macros.hpp"
  46 #include "utilities/utf8.hpp"
  47 #if INCLUDE_JFR
  48 #include "jfr/jfr.hpp"
  49 #endif
  50 
  51 static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {


 363       }
 364     }
 365   }
 366 #endif // INCLUDE_JVMTI
 367   return NULL;
 368 }
 369 
 370 address NativeLookup::lookup_base(const methodHandle& method, bool& in_base_library, TRAPS) {
 371   address entry = NULL;
 372   ResourceMark rm(THREAD);
 373 
 374   entry = lookup_entry(method, in_base_library, THREAD);
 375   if (entry != NULL) return entry;
 376 
 377   // standard native method resolution has failed.  Check if there are any
 378   // JVM TI prefixes which have been applied to the native method name.
 379   entry = lookup_entry_prefixed(method, in_base_library, THREAD);
 380   if (entry != NULL) return entry;
 381 
 382   // Native function not found, throw UnsatisfiedLinkError
 383   stringStream ss;
 384   ss.print("'");
 385   method->print_external_name(&ss);
 386   ss.print("'");
 387   THROW_MSG_0(vmSymbols::java_lang_UnsatisfiedLinkError(), ss.as_string());
 388 }
 389 
 390 
 391 address NativeLookup::lookup(const methodHandle& method, bool& in_base_library, TRAPS) {
 392   if (!method->has_native_function()) {
 393     address entry = lookup_base(method, in_base_library, CHECK_NULL);
 394     method->set_native_function(entry,
 395       Method::native_bind_event_is_interesting);
 396     // -verbose:jni printing
 397     if (PrintJNIResolving) {
 398       ResourceMark rm(THREAD);
 399       tty->print_cr("[Dynamic-linking native method %s.%s ... JNI]",
 400         method->method_holder()->external_name(),
 401         method->name()->as_C_string());
 402     }
 403   }
 404   return method->native_function();
 405 }
 406 
 407 address NativeLookup::base_library_lookup(const char* class_name, const char* method_name, const char* signature) {
 408   EXCEPTION_MARK;
 409   bool in_base_library = true;  // SharedRuntime inits some math methods.
 410   TempNewSymbol c_name = SymbolTable::new_symbol(class_name);
 411   TempNewSymbol m_name = SymbolTable::new_symbol(method_name);
 412   TempNewSymbol s_name = SymbolTable::new_symbol(signature);
 413 
 414   // Find the class
 415   Klass* k = SystemDictionary::resolve_or_fail(c_name, true, CATCH);
 416   InstanceKlass* klass  = InstanceKlass::cast(k);
 417 
 418   // Find method and invoke standard lookup
 419   methodHandle method (THREAD,
 420                        klass->uncached_lookup_method(m_name, s_name, Klass::find_overpass));
 421   address result = lookup(method, in_base_library, CATCH);
 422   assert(in_base_library, "must be in basic library");
 423   guarantee(result != NULL, "must be non NULL");
 424   return result;
 425 }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"

  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "memory/oopFactory.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "memory/universe.hpp"
  32 #include "oops/instanceKlass.hpp"
  33 #include "oops/method.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "oops/symbol.hpp"
  36 #include "prims/jvm_misc.hpp"
  37 #include "prims/nativeLookup.hpp"
  38 #include "prims/unsafe.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/javaCalls.hpp"
  42 #include "runtime/os.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/signature.hpp"
  45 #include "utilities/macros.hpp"
  46 #include "utilities/utf8.hpp"
  47 #if INCLUDE_JFR
  48 #include "jfr/jfr.hpp"
  49 #endif
  50 
  51 static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {


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



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