< prev index next >

src/share/vm/runtime/os.cpp

Print this page




 403     }
 404 
 405     // Load java dll
 406     if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
 407                        "java")) {
 408       _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
 409     }
 410     if (_native_java_library == NULL) {
 411       vm_exit_during_initialization("Unable to load native library", ebuf);
 412     }
 413 
 414 #if defined(__OpenBSD__)
 415     // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
 416     // ignore errors
 417     if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
 418                        "net")) {
 419       dll_load(buffer, ebuf, sizeof(ebuf));
 420     }
 421 #endif
 422   }
 423   static jboolean onLoaded = JNI_FALSE;
 424   if (onLoaded) {
 425     // We may have to wait to fire OnLoad until TLS is initialized.
 426     if (ThreadLocalStorage::is_initialized()) {
 427       // The JNI_OnLoad handling is normally done by method load in
 428       // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
 429       // explicitly so we have to check for JNI_OnLoad as well
 430       const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
 431       JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
 432           JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
 433       if (JNI_OnLoad != NULL) {
 434         JavaThread* thread = JavaThread::current();
 435         ThreadToNativeFromVM ttn(thread);
 436         HandleMark hm(thread);
 437         jint ver = (*JNI_OnLoad)(&main_vm, NULL);
 438         onLoaded = JNI_TRUE;
 439         if (!Threads::is_supported_jni_version_including_1_1(ver)) {
 440           vm_exit_during_initialization("Unsupported JNI version");
 441         }
 442       }
 443     }
 444   }
 445   return _native_java_library;
 446 }
 447 
 448 /*
 449  * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
 450  * If check_lib == true then we are looking for an
 451  * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
 452  * this library is statically linked into the image.
 453  * If check_lib == false then we will look for the appropriate symbol in the
 454  * executable if agent_lib->is_static_lib() == true or in the shared library
 455  * referenced by 'handle'.
 456  */
 457 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
 458                               const char *syms[], size_t syms_len) {
 459   assert(agent_lib != NULL, "sanity check");
 460   const char *lib_name;
 461   void *handle = agent_lib->os_lib();
 462   void *entryName = NULL;
 463   char *agent_function_name;
 464   size_t i;


 557   }
 558   return false;
 559 }
 560 
 561 void* os::malloc(size_t size, MEMFLAGS flags) {
 562   return os::malloc(size, flags, CALLER_PC);
 563 }
 564 
 565 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
 566   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
 567   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
 568 
 569 #ifdef ASSERT
 570   // checking for the WatcherThread and crash_protection first
 571   // since os::malloc can be called when the libjvm.{dll,so} is
 572   // first loaded and we don't have a thread yet.
 573   // try to find the thread after we see that the watcher thread
 574   // exists and has crash protection.
 575   WatcherThread *wt = WatcherThread::watcher_thread();
 576   if (wt != NULL && wt->has_crash_protection()) {
 577     Thread* thread = ThreadLocalStorage::get_thread_slow();
 578     if (thread == wt) {
 579       assert(!wt->has_crash_protection(),
 580           "Can't malloc with crash protection from WatcherThread");
 581     }
 582   }
 583 #endif
 584 
 585   if (size == 0) {
 586     // return a valid pointer if size is zero
 587     // if NULL is returned the calling functions assume out of memory.
 588     size = 1;
 589   }
 590 
 591   // NMT support
 592   NMT_TrackingLevel level = MemTracker::tracking_level();
 593   size_t            nmt_header_size = MemTracker::malloc_header_size(level);
 594 
 595 #ifndef ASSERT
 596   const size_t alloc_size = size + nmt_header_size;
 597 #else




 403     }
 404 
 405     // Load java dll
 406     if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
 407                        "java")) {
 408       _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf));
 409     }
 410     if (_native_java_library == NULL) {
 411       vm_exit_during_initialization("Unable to load native library", ebuf);
 412     }
 413 
 414 #if defined(__OpenBSD__)
 415     // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so
 416     // ignore errors
 417     if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(),
 418                        "net")) {
 419       dll_load(buffer, ebuf, sizeof(ebuf));
 420     }
 421 #endif
 422   }






















 423   return _native_java_library;
 424 }
 425 
 426 /*
 427  * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
 428  * If check_lib == true then we are looking for an
 429  * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
 430  * this library is statically linked into the image.
 431  * If check_lib == false then we will look for the appropriate symbol in the
 432  * executable if agent_lib->is_static_lib() == true or in the shared library
 433  * referenced by 'handle'.
 434  */
 435 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
 436                               const char *syms[], size_t syms_len) {
 437   assert(agent_lib != NULL, "sanity check");
 438   const char *lib_name;
 439   void *handle = agent_lib->os_lib();
 440   void *entryName = NULL;
 441   char *agent_function_name;
 442   size_t i;


 535   }
 536   return false;
 537 }
 538 
 539 void* os::malloc(size_t size, MEMFLAGS flags) {
 540   return os::malloc(size, flags, CALLER_PC);
 541 }
 542 
 543 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
 544   NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
 545   NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
 546 
 547 #ifdef ASSERT
 548   // checking for the WatcherThread and crash_protection first
 549   // since os::malloc can be called when the libjvm.{dll,so} is
 550   // first loaded and we don't have a thread yet.
 551   // try to find the thread after we see that the watcher thread
 552   // exists and has crash protection.
 553   WatcherThread *wt = WatcherThread::watcher_thread();
 554   if (wt != NULL && wt->has_crash_protection()) {
 555     Thread* thread = Thread::current_or_null();
 556     if (thread == wt) {
 557       assert(!wt->has_crash_protection(),
 558           "Can't malloc with crash protection from WatcherThread");
 559     }
 560   }
 561 #endif
 562 
 563   if (size == 0) {
 564     // return a valid pointer if size is zero
 565     // if NULL is returned the calling functions assume out of memory.
 566     size = 1;
 567   }
 568 
 569   // NMT support
 570   NMT_TrackingLevel level = MemTracker::tracking_level();
 571   size_t            nmt_header_size = MemTracker::malloc_header_size(level);
 572 
 573 #ifndef ASSERT
 574   const size_t alloc_size = size + nmt_header_size;
 575 #else


< prev index next >