src/os/posix/vm/os_posix.cpp

Print this page




  34 #include <sys/resource.h>
  35 #include <sys/utsname.h>
  36 #include <pthread.h>
  37 #include <signal.h>
  38 
  39 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  40 
  41 // Todo: provide a os::get_max_process_id() or similar. Number of processes
  42 // may have been configured, can be read more accurately from proc fs etc.
  43 #ifndef MAX_PID
  44 #define MAX_PID INT_MAX
  45 #endif
  46 #define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
  47 
  48 // Check core dump limit and report possible place where core can be found
  49 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
  50   int n;
  51   struct rlimit rlim;
  52   bool success;
  53 
  54   n = get_core_path(buffer, bufferSize);






  55 
  56   if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
  57     jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id());








  58     success = true;
  59   } else {
  60     switch(rlim.rlim_cur) {
  61       case RLIM_INFINITY:
  62         jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id());
  63         success = true;
  64         break;
  65       case 0:
  66         jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
  67         success = false;
  68         break;
  69       default:
  70         jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", current_process_id(), (unsigned long)(rlim.rlim_cur >> 10));
  71         success = true;
  72         break;
  73     }
  74   }


  75   VMError::report_coredump_status(buffer, success);
  76 }
  77 
  78 int os::get_native_stack(address* stack, int frames, int toSkip) {
  79 #ifdef _NMT_NOINLINE_
  80   toSkip++;
  81 #endif
  82 
  83   int frame_idx = 0;
  84   int num_of_frames;  // number of frames captured
  85   frame fr = os::current_frame();
  86   while (fr.pc() && frame_idx < frames) {
  87     if (toSkip > 0) {
  88       toSkip --;
  89     } else {
  90       stack[frame_idx ++] = fr.pc();
  91     }
  92     if (fr.fp() == NULL || os::is_first_C_frame(&fr)
  93         ||fr.sender_pc() == NULL || fr.cb() != NULL) break;
  94 




  34 #include <sys/resource.h>
  35 #include <sys/utsname.h>
  36 #include <pthread.h>
  37 #include <signal.h>
  38 
  39 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  40 
  41 // Todo: provide a os::get_max_process_id() or similar. Number of processes
  42 // may have been configured, can be read more accurately from proc fs etc.
  43 #ifndef MAX_PID
  44 #define MAX_PID INT_MAX
  45 #endif
  46 #define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
  47 
  48 // Check core dump limit and report possible place where core can be found
  49 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
  50   int n;
  51   struct rlimit rlim;
  52   bool success;
  53 
  54   char *core_path = (char *)os::malloc(PATH_MAX, mtInternal);
  55   if (core_path == NULL) {
  56     VMError::report_coredump_status("", false);
  57     return;
  58   }
  59 
  60   n = get_core_path(core_path, PATH_MAX);
  61 
  62   if (n <= 0) {
  63     jio_snprintf(buffer, bufferSize, "core.%d (may not exist)", current_process_id());
  64     success = true;
  65 #ifdef LINUX
  66   } else if (core_path[0] == '"') { // redirect to user process
  67     jio_snprintf(buffer, bufferSize, "Core dumps may be processed with %s", core_path);
  68     success = true;
  69 #endif
  70   } else if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
  71     jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path);
  72     success = true;
  73   } else {
  74     switch(rlim.rlim_cur) {
  75       case RLIM_INFINITY:
  76         jio_snprintf(buffer, bufferSize, "%s", core_path);
  77         success = true;
  78         break;
  79       case 0:
  80         jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
  81         success = false;
  82         break;
  83       default:
  84         jio_snprintf(buffer, bufferSize, "%s (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", core_path, (unsigned long)(rlim.rlim_cur >> 10));
  85         success = true;
  86         break;
  87     }
  88   }
  89 
  90   os::free(core_path);
  91   VMError::report_coredump_status(buffer, success);
  92 }
  93 
  94 int os::get_native_stack(address* stack, int frames, int toSkip) {
  95 #ifdef _NMT_NOINLINE_
  96   toSkip++;
  97 #endif
  98 
  99   int frame_idx = 0;
 100   int num_of_frames;  // number of frames captured
 101   frame fr = os::current_frame();
 102   while (fr.pc() && frame_idx < frames) {
 103     if (toSkip > 0) {
 104       toSkip --;
 105     } else {
 106       stack[frame_idx ++] = fr.pc();
 107     }
 108     if (fr.fp() == NULL || os::is_first_C_frame(&fr)
 109         ||fr.sender_pc() == NULL || fr.cb() != NULL) break;
 110