src/os/linux/vm/os_linux.cpp

Print this page




 320   // Otherwise exit.
 321   //
 322   // Important note: if the location of libjvm.so changes this
 323   // code needs to be changed accordingly.
 324 
 325   // See ld(1):
 326   //      The linker uses the following search paths to locate required
 327   //      shared libraries:
 328   //        1: ...
 329   //        ...
 330   //        7: The default directories, normally /lib and /usr/lib.
 331 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
 332   #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
 333 #else
 334   #define DEFAULT_LIBPATH "/lib:/usr/lib"
 335 #endif
 336 
 337 // Base path of extensions installed on the system.
 338 #define SYS_EXT_DIR     "/usr/java/packages"
 339 #define EXTENSIONS_DIR  "/lib/ext"
 340 #define ENDORSED_DIR    "/lib/endorsed"
 341 
 342   // Buffer that fits several sprintfs.
 343   // Note that the space for the colon and the trailing null are provided
 344   // by the nulls included by the sizeof operator.
 345   const size_t bufsize =
 346     MAX3((size_t)MAXPATHLEN,  // For dll_dir & friends.
 347          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
 348          (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
 349   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 350 
 351   // sysclasspath, java_home, dll_dir
 352   {
 353     char *pslash;
 354     os::jvm_path(buf, bufsize);
 355 
 356     // Found the full path to libjvm.so.
 357     // Now cut the path to <java_home>/jre if we can.
 358     pslash = strrchr(buf, '/');
 359     if (pslash != NULL) {
 360       *pslash = '\0';            // Get rid of /libjvm.so.
 361     }
 362     pslash = strrchr(buf, '/');
 363     if (pslash != NULL) {
 364       *pslash = '\0';            // Get rid of /{client|server|hotspot}.
 365     }
 366     Arguments::set_dll_dir(buf);
 367 
 368     if (pslash != NULL) {


 393     // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
 394     // should always exist (until the legacy problem cited above is
 395     // addressed).
 396     const char *v = ::getenv("LD_LIBRARY_PATH");
 397     const char *v_colon = ":";
 398     if (v == NULL) { v = ""; v_colon = ""; }
 399     // That's +1 for the colon and +1 for the trailing '\0'.
 400     char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
 401                                                      strlen(v) + 1 +
 402                                                      sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
 403                                                      mtInternal);
 404     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
 405     Arguments::set_library_path(ld_library_path);
 406     FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
 407   }
 408 
 409   // Extensions directories.
 410   sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
 411   Arguments::set_ext_dirs(buf);
 412 
 413   // Endorsed standards default directory.
 414   sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
 415   Arguments::set_endorsed_dirs(buf);
 416 
 417   FREE_C_HEAP_ARRAY(char, buf, mtInternal);
 418 
 419 #undef DEFAULT_LIBPATH
 420 #undef SYS_EXT_DIR
 421 #undef EXTENSIONS_DIR
 422 #undef ENDORSED_DIR
 423 }
 424 
 425 ////////////////////////////////////////////////////////////////////////////////
 426 // breakpoint support
 427 
 428 void os::breakpoint() {
 429   BREAKPOINT;
 430 }
 431 
 432 extern "C" void breakpoint() {
 433   // use debugger to set breakpoint here
 434 }
 435 
 436 ////////////////////////////////////////////////////////////////////////////////
 437 // signal support
 438 
 439 debug_only(static bool signal_sets_initialized = false);
 440 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
 441 
 442 bool os::Linux::is_sig_ignored(int sig) {


3766 
3767   for (int j = 0; j < i; ++j) {
3768     if (base[j] != NULL) {
3769       unmap_memory(base[j], size[j]);
3770     }
3771   }
3772 
3773   if (i < max_tries) {
3774     _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
3775     return requested_addr;
3776   } else {
3777     _highest_vm_reserved_address = old_highest;
3778     return NULL;
3779   }
3780 }
3781 
3782 size_t os::read(int fd, void *buf, unsigned int nBytes) {
3783   return ::read(fd, buf, nBytes);
3784 }
3785 




3786 // Short sleep, direct OS call.
3787 //
3788 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
3789 // sched_yield(2) will actually give up the CPU:
3790 //
3791 //   * Alone on this pariticular CPU, keeps running.
3792 //   * Before the introduction of "skip_buddy" with "compat_yield" disabled
3793 //     (pre 2.6.39).
3794 //
3795 // So calling this with 0 is an alternative.
3796 //
3797 void os::naked_short_sleep(jlong ms) {
3798   struct timespec req;
3799 
3800   assert(ms < 1000, "Un-interruptable sleep, short time use only");
3801   req.tv_sec = 0;
3802   if (ms > 0) {
3803     req.tv_nsec = (ms % 1000) * 1000000;
3804   } else {
3805     req.tv_nsec = 1;




 320   // Otherwise exit.
 321   //
 322   // Important note: if the location of libjvm.so changes this
 323   // code needs to be changed accordingly.
 324 
 325   // See ld(1):
 326   //      The linker uses the following search paths to locate required
 327   //      shared libraries:
 328   //        1: ...
 329   //        ...
 330   //        7: The default directories, normally /lib and /usr/lib.
 331 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
 332   #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
 333 #else
 334   #define DEFAULT_LIBPATH "/lib:/usr/lib"
 335 #endif
 336 
 337 // Base path of extensions installed on the system.
 338 #define SYS_EXT_DIR     "/usr/java/packages"
 339 #define EXTENSIONS_DIR  "/lib/ext"

 340 
 341   // Buffer that fits several sprintfs.
 342   // Note that the space for the colon and the trailing null are provided
 343   // by the nulls included by the sizeof operator.
 344   const size_t bufsize =
 345     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
 346          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir

 347   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 348 
 349   // sysclasspath, java_home, dll_dir
 350   {
 351     char *pslash;
 352     os::jvm_path(buf, bufsize);
 353 
 354     // Found the full path to libjvm.so.
 355     // Now cut the path to <java_home>/jre if we can.
 356     pslash = strrchr(buf, '/');
 357     if (pslash != NULL) {
 358       *pslash = '\0';            // Get rid of /libjvm.so.
 359     }
 360     pslash = strrchr(buf, '/');
 361     if (pslash != NULL) {
 362       *pslash = '\0';            // Get rid of /{client|server|hotspot}.
 363     }
 364     Arguments::set_dll_dir(buf);
 365 
 366     if (pslash != NULL) {


 391     // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
 392     // should always exist (until the legacy problem cited above is
 393     // addressed).
 394     const char *v = ::getenv("LD_LIBRARY_PATH");
 395     const char *v_colon = ":";
 396     if (v == NULL) { v = ""; v_colon = ""; }
 397     // That's +1 for the colon and +1 for the trailing '\0'.
 398     char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
 399                                                      strlen(v) + 1 +
 400                                                      sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
 401                                                      mtInternal);
 402     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
 403     Arguments::set_library_path(ld_library_path);
 404     FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
 405   }
 406 
 407   // Extensions directories.
 408   sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
 409   Arguments::set_ext_dirs(buf);
 410 




 411   FREE_C_HEAP_ARRAY(char, buf, mtInternal);
 412 
 413 #undef DEFAULT_LIBPATH
 414 #undef SYS_EXT_DIR
 415 #undef EXTENSIONS_DIR

 416 }
 417 
 418 ////////////////////////////////////////////////////////////////////////////////
 419 // breakpoint support
 420 
 421 void os::breakpoint() {
 422   BREAKPOINT;
 423 }
 424 
 425 extern "C" void breakpoint() {
 426   // use debugger to set breakpoint here
 427 }
 428 
 429 ////////////////////////////////////////////////////////////////////////////////
 430 // signal support
 431 
 432 debug_only(static bool signal_sets_initialized = false);
 433 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
 434 
 435 bool os::Linux::is_sig_ignored(int sig) {


3759 
3760   for (int j = 0; j < i; ++j) {
3761     if (base[j] != NULL) {
3762       unmap_memory(base[j], size[j]);
3763     }
3764   }
3765 
3766   if (i < max_tries) {
3767     _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
3768     return requested_addr;
3769   } else {
3770     _highest_vm_reserved_address = old_highest;
3771     return NULL;
3772   }
3773 }
3774 
3775 size_t os::read(int fd, void *buf, unsigned int nBytes) {
3776   return ::read(fd, buf, nBytes);
3777 }
3778 
3779 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
3780   return ::pread(fd, buf, nBytes, offset);
3781 }
3782 
3783 // Short sleep, direct OS call.
3784 //
3785 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
3786 // sched_yield(2) will actually give up the CPU:
3787 //
3788 //   * Alone on this pariticular CPU, keeps running.
3789 //   * Before the introduction of "skip_buddy" with "compat_yield" disabled
3790 //     (pre 2.6.39).
3791 //
3792 // So calling this with 0 is an alternative.
3793 //
3794 void os::naked_short_sleep(jlong ms) {
3795   struct timespec req;
3796 
3797   assert(ms < 1000, "Un-interruptable sleep, short time use only");
3798   req.tv_sec = 0;
3799   if (ms > 0) {
3800     req.tv_nsec = (ms % 1000) * 1000000;
3801   } else {
3802     req.tv_nsec = 1;