src/os/linux/vm/os_linux.cpp

Print this page




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





5992 



























5993   if (p == NULL) {
5994     assert(p != NULL, "failed to get current directory");
5995     return 0;

























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




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