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[PATH_MAX];
  55   n = get_core_path(core_path, PATH_MAX);
  56 
  57   if (n <= 0) {
  58     jio_snprintf(buffer, bufferSize, "core.%d (may not exist)", current_process_id());
  59     success = true;
  60 #ifdef LINUX
  61   } else if (core_path[0] == '"') { // redirect to user process
  62     jio_snprintf(buffer, bufferSize, "Core dumps may be processed with %s", core_path);
  63     success = true;
  64 #endif
  65   } else if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
  66     jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path);
  67     success = true;
  68   } else {
  69     switch(rlim.rlim_cur) {
  70       case RLIM_INFINITY:
  71         jio_snprintf(buffer, bufferSize, "%s", core_path);
  72         success = true;
  73         break;
  74       case 0:
  75         jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
  76         success = false;
  77         break;
  78       default:
  79         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));
  80         success = true;
  81         break;
  82     }
  83   }
  84 
  85   VMError::report_coredump_status(buffer, success);
  86 }
  87 
  88 int os::get_native_stack(address* stack, int frames, int toSkip) {
  89 #ifdef _NMT_NOINLINE_
  90   toSkip++;
  91 #endif
  92 
  93   int frame_idx = 0;
  94   int num_of_frames;  // number of frames captured
  95   frame fr = os::current_frame();
  96   while (fr.pc() && frame_idx < frames) {
  97     if (toSkip > 0) {
  98       toSkip --;
  99     } else {
 100       stack[frame_idx ++] = fr.pc();
 101     }
 102     if (fr.fp() == NULL || os::is_first_C_frame(&fr)
 103         ||fr.sender_pc() == NULL || fr.cb() != NULL) break;
 104