src/os/posix/vm/os_posix.cpp

Print this page




  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 --;




  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 
  66       case 0:
  67       {
  68         jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
  69 
  70 #ifdef LINUX
  71         /*
  72          * Max length of /proc/sys/kernel/core_pattern is 128 characters.
  73          * See https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
  74          */
  75         const int core_pattern_len = 129;
  76 
  77         char core_pattern[core_pattern_len] = {0};
  78         bool is_redirect = false;
  79         FILE *core_pattern_file = fopen("/proc/sys/kernel/core_pattern", "r");
  80         if(core_pattern_file != NULL){
  81           fgets(core_pattern, core_pattern_len, core_pattern_file);
  82           fclose(core_pattern_file);
  83           is_redirect = core_pattern[0] == '|';
  84         }
  85 
  86         if(is_redirect){
  87           jio_snprintf(buffer, bufferSize,
  88                    "Core dumps may be treated with \"%s\"", &core_pattern[1]);
  89         }
  90 #endif
  91 
  92         success = false;
  93         break;
  94       }
  95 
  96       default:
  97         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));
  98         success = true;
  99         break;
 100     }
 101   }
 102   VMError::report_coredump_status(buffer, success);
 103 }
 104 
 105 int os::get_native_stack(address* stack, int frames, int toSkip) {
 106 #ifdef _NMT_NOINLINE_
 107   toSkip++;
 108 #endif
 109 
 110   int frame_idx = 0;
 111   int num_of_frames;  // number of frames captured
 112   frame fr = os::current_frame();
 113   while (fr.pc() && frame_idx < frames) {
 114     if (toSkip > 0) {
 115       toSkip --;