src/os/bsd/vm/os_bsd.cpp

Print this page




 281 #ifdef __APPLE__
 282 static const char *get_home() {
 283   const char *home_dir = ::getenv("HOME");
 284   if ((home_dir == NULL) || (*home_dir == '\0')) {
 285     struct passwd *passwd_info = getpwuid(geteuid());
 286     if (passwd_info != NULL) {
 287       home_dir = passwd_info->pw_dir;
 288     }
 289   }
 290 
 291   return home_dir;
 292 }
 293 #endif
 294 
 295 void os::init_system_properties_values() {
 296 //  char arch[12];
 297 //  sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
 298 
 299   // The next steps are taken in the product version:
 300   //
 301   // Obtain the JAVA_HOME value from the location of libjvm[_g].so.
 302   // This library should be located at:
 303   // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm[_g].so.
 304   //
 305   // If "/jre/lib/" appears at the right place in the path, then we
 306   // assume libjvm[_g].so is installed in a JDK and we use this path.
 307   //
 308   // Otherwise exit with message: "Could not create the Java virtual machine."
 309   //
 310   // The following extra steps are taken in the debugging version:
 311   //
 312   // If "/jre/lib/" does NOT appear at the right place in the path
 313   // instead of exit check for $JAVA_HOME environment variable.
 314   //
 315   // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
 316   // then we append a fake suffix "hotspot/libjvm[_g].so" to this path so
 317   // it looks like libjvm[_g].so is installed there
 318   // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm[_g].so.
 319   //
 320   // Otherwise exit.
 321   //
 322   // Important note: if the location of libjvm.so changes this
 323   // code needs to be changed accordingly.
 324 
 325   // The next few definitions allow the code to be verbatim:
 326 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
 327 #define getenv(n) ::getenv(n)
 328 
 329 /*
 330  * See ld(1):
 331  *      The linker uses the following search paths to locate required
 332  *      shared libraries:
 333  *        1: ...
 334  *        ...
 335  *        7: The default directories, normally /lib and /usr/lib.
 336  */
 337 #ifndef DEFAULT_LIBPATH
 338 #define DEFAULT_LIBPATH "/lib:/usr/lib"


1211     // release the storage
1212     for (int i = 0 ; i < n ; i++) {
1213       if (pelements[i] != NULL) {
1214         FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
1215       }
1216     }
1217     if (pelements != NULL) {
1218       FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
1219     }
1220   } else {
1221     snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, pname, fname);
1222     retval = true;
1223   }
1224   return retval;
1225 }
1226 
1227 const char* os::get_current_directory(char *buf, int buflen) {
1228   return getcwd(buf, buflen);
1229 }
1230 
1231 // check if addr is inside libjvm[_g].so
1232 bool os::address_is_in_vm(address addr) {
1233   static address libjvm_base_addr;
1234   Dl_info dlinfo;
1235 
1236   if (libjvm_base_addr == NULL) {
1237     dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo);
1238     libjvm_base_addr = (address)dlinfo.dli_fbase;
1239     assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
1240   }
1241 
1242   if (dladdr((void *)addr, &dlinfo)) {
1243     if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
1244   }
1245 
1246   return false;
1247 }
1248 
1249 
1250 #define MACH_MAXSYMLEN 256
1251 


1672                                  char* buf, size_t buflen);
1673 
1674 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
1675   st->print_cr("Signal Handlers:");
1676   print_signal_handler(st, SIGSEGV, buf, buflen);
1677   print_signal_handler(st, SIGBUS , buf, buflen);
1678   print_signal_handler(st, SIGFPE , buf, buflen);
1679   print_signal_handler(st, SIGPIPE, buf, buflen);
1680   print_signal_handler(st, SIGXFSZ, buf, buflen);
1681   print_signal_handler(st, SIGILL , buf, buflen);
1682   print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
1683   print_signal_handler(st, SR_signum, buf, buflen);
1684   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
1685   print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
1686   print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
1687   print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
1688 }
1689 
1690 static char saved_jvm_path[MAXPATHLEN] = {0};
1691 
1692 // Find the full path to the current module, libjvm or libjvm_g
1693 void os::jvm_path(char *buf, jint buflen) {
1694   // Error checking.
1695   if (buflen < MAXPATHLEN) {
1696     assert(false, "must use a large-enough buffer");
1697     buf[0] = '\0';
1698     return;
1699   }
1700   // Lazy resolve the path to current module.
1701   if (saved_jvm_path[0] != 0) {
1702     strcpy(buf, saved_jvm_path);
1703     return;
1704   }
1705 
1706   char dli_fname[MAXPATHLEN];
1707   bool ret = dll_address_to_library_name(
1708                 CAST_FROM_FN_PTR(address, os::jvm_path),
1709                 dli_fname, sizeof(dli_fname), NULL);
1710   assert(ret != 0, "cannot locate libjvm");
1711   char *rp = realpath(dli_fname, buf);
1712   if (rp == NULL)


1715   if (Arguments::created_by_gamma_launcher()) {
1716     // Support for the gamma launcher.  Typical value for buf is
1717     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm".  If "/jre/lib/" appears at
1718     // the right place in the string, then assume we are installed in a JDK and
1719     // we're done.  Otherwise, check for a JAVA_HOME environment variable and
1720     // construct a path to the JVM being overridden.
1721 
1722     const char *p = buf + strlen(buf) - 1;
1723     for (int count = 0; p > buf && count < 5; ++count) {
1724       for (--p; p > buf && *p != '/'; --p)
1725         /* empty */ ;
1726     }
1727 
1728     if (strncmp(p, "/jre/lib/", 9) != 0) {
1729       // Look for JAVA_HOME in the environment.
1730       char* java_home_var = ::getenv("JAVA_HOME");
1731       if (java_home_var != NULL && java_home_var[0] != 0) {
1732         char* jrelib_p;
1733         int len;
1734 
1735         // Check the current module name "libjvm" or "libjvm_g".
1736         p = strrchr(buf, '/');
1737         assert(strstr(p, "/libjvm") == p, "invalid library name");
1738         p = strstr(p, "_g") ? "_g" : "";
1739 
1740         rp = realpath(java_home_var, buf);
1741         if (rp == NULL)
1742           return;
1743 
1744         // determine if this is a legacy image or modules image
1745         // modules image doesn't have "jre" subdirectory
1746         len = strlen(buf);
1747         jrelib_p = buf + len;
1748 
1749         // Add the appropriate library subdir
1750         snprintf(jrelib_p, buflen-len, "/jre/lib");
1751         if (0 != access(buf, F_OK)) {
1752           snprintf(jrelib_p, buflen-len, "/lib");
1753         }
1754 
1755         // Add the appropriate client or server subdir
1756         len = strlen(buf);
1757         jrelib_p = buf + len;
1758         snprintf(jrelib_p, buflen-len, "/%s", COMPILER_VARIANT);
1759         if (0 != access(buf, F_OK)) {
1760           snprintf(jrelib_p, buflen-len, "");
1761         }
1762 
1763         // If the path exists within JAVA_HOME, add the JVM library name
1764         // to complete the path to JVM being overridden.  Otherwise fallback
1765         // to the path to the current library.
1766         if (0 == access(buf, F_OK)) {
1767           // Use current module name "libjvm[_g]" instead of
1768           // "libjvm"debug_only("_g")"" since for fastdebug version
1769           // we should have "libjvm" but debug_only("_g") adds "_g"!
1770           len = strlen(buf);
1771           snprintf(buf + len, buflen-len, "/libjvm%s%s", p, JNI_LIB_SUFFIX);
1772         } else {
1773           // Fall back to path of current library
1774           rp = realpath(dli_fname, buf);
1775           if (rp == NULL)
1776             return;
1777         }
1778       }
1779     }
1780   }
1781 
1782   strcpy(saved_jvm_path, buf);
1783 }
1784 
1785 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1786   // no prefix required, not even "_"
1787 }
1788 
1789 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1790   // no suffix required
1791 }




 281 #ifdef __APPLE__
 282 static const char *get_home() {
 283   const char *home_dir = ::getenv("HOME");
 284   if ((home_dir == NULL) || (*home_dir == '\0')) {
 285     struct passwd *passwd_info = getpwuid(geteuid());
 286     if (passwd_info != NULL) {
 287       home_dir = passwd_info->pw_dir;
 288     }
 289   }
 290 
 291   return home_dir;
 292 }
 293 #endif
 294 
 295 void os::init_system_properties_values() {
 296 //  char arch[12];
 297 //  sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
 298 
 299   // The next steps are taken in the product version:
 300   //
 301   // Obtain the JAVA_HOME value from the location of libjvm.so.
 302   // This library should be located at:
 303   // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so.
 304   //
 305   // If "/jre/lib/" appears at the right place in the path, then we
 306   // assume libjvm.so is installed in a JDK and we use this path.
 307   //
 308   // Otherwise exit with message: "Could not create the Java virtual machine."
 309   //
 310   // The following extra steps are taken in the debugging version:
 311   //
 312   // If "/jre/lib/" does NOT appear at the right place in the path
 313   // instead of exit check for $JAVA_HOME environment variable.
 314   //
 315   // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
 316   // then we append a fake suffix "hotspot/libjvm.so" to this path so
 317   // it looks like libjvm.so is installed there
 318   // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so.
 319   //
 320   // Otherwise exit.
 321   //
 322   // Important note: if the location of libjvm.so changes this
 323   // code needs to be changed accordingly.
 324 
 325   // The next few definitions allow the code to be verbatim:
 326 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
 327 #define getenv(n) ::getenv(n)
 328 
 329 /*
 330  * See ld(1):
 331  *      The linker uses the following search paths to locate required
 332  *      shared libraries:
 333  *        1: ...
 334  *        ...
 335  *        7: The default directories, normally /lib and /usr/lib.
 336  */
 337 #ifndef DEFAULT_LIBPATH
 338 #define DEFAULT_LIBPATH "/lib:/usr/lib"


1211     // release the storage
1212     for (int i = 0 ; i < n ; i++) {
1213       if (pelements[i] != NULL) {
1214         FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
1215       }
1216     }
1217     if (pelements != NULL) {
1218       FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
1219     }
1220   } else {
1221     snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, pname, fname);
1222     retval = true;
1223   }
1224   return retval;
1225 }
1226 
1227 const char* os::get_current_directory(char *buf, int buflen) {
1228   return getcwd(buf, buflen);
1229 }
1230 
1231 // check if addr is inside libjvm.so
1232 bool os::address_is_in_vm(address addr) {
1233   static address libjvm_base_addr;
1234   Dl_info dlinfo;
1235 
1236   if (libjvm_base_addr == NULL) {
1237     dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo);
1238     libjvm_base_addr = (address)dlinfo.dli_fbase;
1239     assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
1240   }
1241 
1242   if (dladdr((void *)addr, &dlinfo)) {
1243     if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
1244   }
1245 
1246   return false;
1247 }
1248 
1249 
1250 #define MACH_MAXSYMLEN 256
1251 


1672                                  char* buf, size_t buflen);
1673 
1674 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
1675   st->print_cr("Signal Handlers:");
1676   print_signal_handler(st, SIGSEGV, buf, buflen);
1677   print_signal_handler(st, SIGBUS , buf, buflen);
1678   print_signal_handler(st, SIGFPE , buf, buflen);
1679   print_signal_handler(st, SIGPIPE, buf, buflen);
1680   print_signal_handler(st, SIGXFSZ, buf, buflen);
1681   print_signal_handler(st, SIGILL , buf, buflen);
1682   print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
1683   print_signal_handler(st, SR_signum, buf, buflen);
1684   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
1685   print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
1686   print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
1687   print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
1688 }
1689 
1690 static char saved_jvm_path[MAXPATHLEN] = {0};
1691 
1692 // Find the full path to the current module, libjvm
1693 void os::jvm_path(char *buf, jint buflen) {
1694   // Error checking.
1695   if (buflen < MAXPATHLEN) {
1696     assert(false, "must use a large-enough buffer");
1697     buf[0] = '\0';
1698     return;
1699   }
1700   // Lazy resolve the path to current module.
1701   if (saved_jvm_path[0] != 0) {
1702     strcpy(buf, saved_jvm_path);
1703     return;
1704   }
1705 
1706   char dli_fname[MAXPATHLEN];
1707   bool ret = dll_address_to_library_name(
1708                 CAST_FROM_FN_PTR(address, os::jvm_path),
1709                 dli_fname, sizeof(dli_fname), NULL);
1710   assert(ret != 0, "cannot locate libjvm");
1711   char *rp = realpath(dli_fname, buf);
1712   if (rp == NULL)


1715   if (Arguments::created_by_gamma_launcher()) {
1716     // Support for the gamma launcher.  Typical value for buf is
1717     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm".  If "/jre/lib/" appears at
1718     // the right place in the string, then assume we are installed in a JDK and
1719     // we're done.  Otherwise, check for a JAVA_HOME environment variable and
1720     // construct a path to the JVM being overridden.
1721 
1722     const char *p = buf + strlen(buf) - 1;
1723     for (int count = 0; p > buf && count < 5; ++count) {
1724       for (--p; p > buf && *p != '/'; --p)
1725         /* empty */ ;
1726     }
1727 
1728     if (strncmp(p, "/jre/lib/", 9) != 0) {
1729       // Look for JAVA_HOME in the environment.
1730       char* java_home_var = ::getenv("JAVA_HOME");
1731       if (java_home_var != NULL && java_home_var[0] != 0) {
1732         char* jrelib_p;
1733         int len;
1734 
1735         // Check the current module name "libjvm"
1736         p = strrchr(buf, '/');
1737         assert(strstr(p, "/libjvm") == p, "invalid library name");

1738 
1739         rp = realpath(java_home_var, buf);
1740         if (rp == NULL)
1741           return;
1742 
1743         // determine if this is a legacy image or modules image
1744         // modules image doesn't have "jre" subdirectory
1745         len = strlen(buf);
1746         jrelib_p = buf + len;
1747 
1748         // Add the appropriate library subdir
1749         snprintf(jrelib_p, buflen-len, "/jre/lib");
1750         if (0 != access(buf, F_OK)) {
1751           snprintf(jrelib_p, buflen-len, "/lib");
1752         }
1753 
1754         // Add the appropriate client or server subdir
1755         len = strlen(buf);
1756         jrelib_p = buf + len;
1757         snprintf(jrelib_p, buflen-len, "/%s", COMPILER_VARIANT);
1758         if (0 != access(buf, F_OK)) {
1759           snprintf(jrelib_p, buflen-len, "");
1760         }
1761 
1762         // If the path exists within JAVA_HOME, add the JVM library name
1763         // to complete the path to JVM being overridden.  Otherwise fallback
1764         // to the path to the current library.
1765         if (0 == access(buf, F_OK)) {
1766           // Use current module name "libjvm"


1767           len = strlen(buf);
1768           snprintf(buf + len, buflen-len, "/libjvm%s", JNI_LIB_SUFFIX);
1769         } else {
1770           // Fall back to path of current library
1771           rp = realpath(dli_fname, buf);
1772           if (rp == NULL)
1773             return;
1774         }
1775       }
1776     }
1777   }
1778 
1779   strcpy(saved_jvm_path, buf);
1780 }
1781 
1782 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1783   // no prefix required, not even "_"
1784 }
1785 
1786 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1787   // no suffix required
1788 }