src/share/vm/runtime/os.cpp

Print this page




 426       // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
 427       // explicitly so we have to check for JNI_OnLoad as well
 428       const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
 429       JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
 430           JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
 431       if (JNI_OnLoad != NULL) {
 432         JavaThread* thread = JavaThread::current();
 433         ThreadToNativeFromVM ttn(thread);
 434         HandleMark hm(thread);
 435         jint ver = (*JNI_OnLoad)(&main_vm, NULL);
 436         onLoaded = JNI_TRUE;
 437         if (!Threads::is_supported_jni_version_including_1_1(ver)) {
 438           vm_exit_during_initialization("Unsupported JNI version");
 439         }
 440       }
 441     }
 442   }
 443   return _native_java_library;
 444 }
 445 





























































 446 // --------------------- heap allocation utilities ---------------------
 447 
 448 char *os::strdup(const char *str, MEMFLAGS flags) {
 449   size_t size = strlen(str);
 450   char *dup_str = (char *)malloc(size + 1, flags);
 451   if (dup_str == NULL) return NULL;
 452   strcpy(dup_str, str);
 453   return dup_str;
 454 }
 455 
 456 
 457 
 458 #ifdef ASSERT
 459 #define space_before             (MallocCushion + sizeof(double))
 460 #define space_after              MallocCushion
 461 #define size_addr_from_base(p)   (size_t*)(p + space_before - sizeof(size_t))
 462 #define size_addr_from_obj(p)    ((size_t*)p - 1)
 463 // MallocCushion: size of extra cushion allocated around objects with +UseMallocOnly
 464 // NB: cannot be debug variable, because these aren't set from the command line until
 465 // *after* the first few allocs already happened




 426       // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library
 427       // explicitly so we have to check for JNI_OnLoad as well
 428       const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
 429       JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR(
 430           JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0]));
 431       if (JNI_OnLoad != NULL) {
 432         JavaThread* thread = JavaThread::current();
 433         ThreadToNativeFromVM ttn(thread);
 434         HandleMark hm(thread);
 435         jint ver = (*JNI_OnLoad)(&main_vm, NULL);
 436         onLoaded = JNI_TRUE;
 437         if (!Threads::is_supported_jni_version_including_1_1(ver)) {
 438           vm_exit_during_initialization("Unsupported JNI version");
 439         }
 440       }
 441     }
 442   }
 443   return _native_java_library;
 444 }
 445 
 446 /*
 447  * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists.
 448  * If check_lib == true then we are looking for an
 449  * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if
 450  * this library is statically linked into the image.
 451  * If check_lib == false then we will look for the appropriate symbol in the
 452  * executable if agent_lib->is_static_lib() == true or in the shared library
 453  * referenced by 'handle'.
 454  */
 455 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib,
 456                               const char *syms[], size_t syms_len) {
 457   const char *lib_name;
 458   void *handle = agent_lib->os_lib();
 459   void *entryName = NULL;
 460   char *agent_function_name;
 461   size_t i;
 462 
 463   // If checking then use the agent name otherwise test is_static_lib() to
 464   // see how to process this lookup
 465   lib_name = ((check_lib || agent_lib->is_static_lib()) ? agent_lib->name() : NULL);
 466   for (i = 0; i < syms_len; i++) {
 467     agent_function_name = build_agent_function_name(syms[i], lib_name, agent_lib->is_absolute_path());
 468     if (agent_function_name == NULL) {
 469       break;
 470     }
 471     entryName = dll_lookup(handle, agent_function_name);
 472     FREE_C_HEAP_ARRAY(char, agent_function_name, mtThread);
 473     if (entryName != NULL) {
 474       break;
 475     }
 476   }
 477   return entryName;
 478 }
 479 
 480 // See if the passed in agent is statically linked into the VM image.
 481 bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[],
 482                             size_t syms_len) {
 483   void *ret;
 484   void *proc_handle;
 485   void *save_handle;
 486 
 487   if (agent_lib->name() == NULL) {
 488     return false;
 489   }
 490   proc_handle = get_default_process_handle();
 491   // Check for Agent_OnLoad/Attach_lib_name function
 492   save_handle = agent_lib->os_lib();
 493   // We want to look in this process' symbol table.
 494   agent_lib->set_os_lib(proc_handle);
 495   ret = find_agent_function(agent_lib, true, syms, syms_len);
 496   agent_lib->set_os_lib(save_handle);
 497   if (ret != NULL) {
 498     // Found an entry point like Agent_OnLoad_lib_name so we have a static agent
 499     agent_lib->set_os_lib(proc_handle);
 500     agent_lib->set_valid();
 501     agent_lib->set_static_lib(true);
 502     return true;
 503   }
 504   return false;
 505 }
 506 
 507 // --------------------- heap allocation utilities ---------------------
 508 
 509 char *os::strdup(const char *str, MEMFLAGS flags) {
 510   size_t size = strlen(str);
 511   char *dup_str = (char *)malloc(size + 1, flags);
 512   if (dup_str == NULL) return NULL;
 513   strcpy(dup_str, str);
 514   return dup_str;
 515 }
 516 
 517 
 518 
 519 #ifdef ASSERT
 520 #define space_before             (MallocCushion + sizeof(double))
 521 #define space_after              MallocCushion
 522 #define size_addr_from_base(p)   (size_t*)(p + space_before - sizeof(size_t))
 523 #define size_addr_from_obj(p)    ((size_t*)p - 1)
 524 // MallocCushion: size of extra cushion allocated around objects with +UseMallocOnly
 525 // NB: cannot be debug variable, because these aren't set from the command line until
 526 // *after* the first few allocs already happened