src/os/linux/vm/os_linux.cpp

Print this page




5974   } else {
5975     *p = '\0';
5976   }
5977 
5978   // check xawt/libmawt.so
5979   strcpy(libmawtpath, buf);
5980   strcat(libmawtpath, xawtstr);
5981   if (::stat(libmawtpath, &statbuf) == 0) return false;
5982 
5983   // check libawt_xawt.so
5984   strcpy(libmawtpath, buf);
5985   strcat(libmawtpath, new_xawtstr);
5986   if (::stat(libmawtpath, &statbuf) == 0) return false;
5987 
5988   return true;
5989 }
5990 
5991 // Get the default path to the core file
5992 // Returns the length of the string
5993 int os::get_core_path(char* buffer, size_t bufferSize) {
5994   const char* p = get_current_directory(buffer, bufferSize);





5995 





























5996   if (p == NULL) {
5997     assert(p != NULL, "failed to get current directory");
5998     return 0;




























5999   }
6000 
6001   return strlen(buffer);
6002 }
6003 
6004 /////////////// Unit tests ///////////////
6005 
6006 #ifndef PRODUCT
6007 
6008 #define test_log(...)              \
6009   do {                             \
6010     if (VerboseInternalVMTests) {  \
6011       tty->print_cr(__VA_ARGS__);  \
6012       tty->flush();                \
6013     }                              \
6014   } while (false)
6015 
6016 class TestReserveMemorySpecial : AllStatic {
6017  public:
6018   static void small_page_write(void* addr, size_t size) {




5974   } else {
5975     *p = '\0';
5976   }
5977 
5978   // check xawt/libmawt.so
5979   strcpy(libmawtpath, buf);
5980   strcat(libmawtpath, xawtstr);
5981   if (::stat(libmawtpath, &statbuf) == 0) return false;
5982 
5983   // check libawt_xawt.so
5984   strcpy(libmawtpath, buf);
5985   strcat(libmawtpath, new_xawtstr);
5986   if (::stat(libmawtpath, &statbuf) == 0) return false;
5987 
5988   return true;
5989 }
5990 
5991 // Get the default path to the core file
5992 // Returns the length of the string
5993 int os::get_core_path(char* buffer, size_t bufferSize) {
5994   /*
5995    * Max length of /proc/sys/kernel/core_pattern is 128 characters.
5996    * See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
5997    */
5998   const int core_pattern_len = 129;
5999   char core_pattern[core_pattern_len] = {0};
6000 
6001   int core_pattern_file = ::open("/proc/sys/kernel/core_pattern", O_RDONLY);
6002   if (core_pattern_file != -1) {
6003     ssize_t ret = ::read(core_pattern_file, core_pattern, core_pattern_len);
6004     ::close(core_pattern_file);
6005 
6006     if (ret > 0) {
6007       char *last_char = core_pattern + strlen(core_pattern) - 1;
6008 
6009       if (*last_char == '\n') {
6010         *last_char = '\0';
6011       }
6012 
6013     }
6014 
6015   }
6016 
6017   if (strlen(core_pattern) == 0) {
6018     return 0;
6019   }
6020 
6021   char *pid_pos = strstr(core_pattern, "%p");
6022   size_t written;
6023 
6024   if (core_pattern[0] == '/') {
6025     written = jio_snprintf(buffer, bufferSize, core_pattern);
6026   } else {
6027     char cwd[PATH_MAX];
6028 
6029     const char* p = get_current_directory(cwd, PATH_MAX);
6030     if (p == NULL) {
6031       assert(p != NULL, "failed to get current directory");
6032       return 0;
6033     }
6034 
6035     if (core_pattern[0] == '|') {
6036       written = jio_snprintf(buffer, bufferSize,
6037                         "\"%s\" (or dumping to %s/core.%d)",
6038                                      &core_pattern[1], p, current_process_id());
6039     } else {
6040       written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
6041     }
6042 
6043   }
6044 
6045   if ((written >= 0) && (written < bufferSize)
6046             && (pid_pos == NULL) && (core_pattern[0] != '|')) {
6047     int core_uses_pid_file = ::open("/proc/sys/kernel/core_uses_pid", O_RDONLY);
6048 
6049     if (core_uses_pid_file != -1) {
6050       char core_uses_pid = 0;
6051       ssize_t ret = ::read(core_uses_pid_file, &core_uses_pid, 1);
6052       ::close(core_uses_pid_file);
6053 
6054       if (core_uses_pid == '1'){
6055         jio_snprintf(buffer + written, bufferSize - written,
6056                                           ".%d", current_process_id());
6057       }
6058 
6059     }
6060 
6061   }
6062 
6063   return strlen(buffer);
6064 }
6065 
6066 /////////////// Unit tests ///////////////
6067 
6068 #ifndef PRODUCT
6069 
6070 #define test_log(...)              \
6071   do {                             \
6072     if (VerboseInternalVMTests) {  \
6073       tty->print_cr(__VA_ARGS__);  \
6074       tty->flush();                \
6075     }                              \
6076   } while (false)
6077 
6078 class TestReserveMemorySpecial : AllStatic {
6079  public:
6080   static void small_page_write(void* addr, size_t size) {