hotspot/src/os/linux/vm/os_linux.cpp
changeset 33148 68fa8b6c4340
parent 33105 294e48b4f704
child 33589 7cbd1b2c139b
child 33593 60764a78fa5c
equal deleted inserted replaced
33146:77349b58b4c0 33148:68fa8b6c4340
   104 # include <link.h>
   104 # include <link.h>
   105 # include <stdint.h>
   105 # include <stdint.h>
   106 # include <inttypes.h>
   106 # include <inttypes.h>
   107 # include <sys/ioctl.h>
   107 # include <sys/ioctl.h>
   108 
   108 
   109 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
       
   110 
       
   111 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
   109 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
   112 // getrusage() is prepared to handle the associated failure.
   110 // getrusage() is prepared to handle the associated failure.
   113 #ifndef RUSAGE_THREAD
   111 #ifndef RUSAGE_THREAD
   114   #define RUSAGE_THREAD   (1)               /* only the calling thread */
   112   #define RUSAGE_THREAD   (1)               /* only the calling thread */
   115 #endif
   113 #endif
  1967       char permissions[5];
  1965       char permissions[5];
  1968       char device[6];
  1966       char device[6];
  1969       char name[PATH_MAX + 1];
  1967       char name[PATH_MAX + 1];
  1970 
  1968 
  1971       // Parse fields from line
  1969       // Parse fields from line
  1972       sscanf(line, "%lx-%lx %4s %lx %5s %ld %s", &base, &top, permissions, &offset, device, &inode, name);
  1970       sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %5s " INT64_FORMAT " %s",
       
  1971              &base, &top, permissions, &offset, device, &inode, name);
  1973 
  1972 
  1974       // Filter by device id '00:00' so that we only get file system mapped files.
  1973       // Filter by device id '00:00' so that we only get file system mapped files.
  1975       if (strcmp(device, "00:00") != 0) {
  1974       if (strcmp(device, "00:00") != 0) {
  1976 
  1975 
  1977         // Call callback with the fields of interest
  1976         // Call callback with the fields of interest
  2630 }
  2629 }
  2631 
  2630 
  2632 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
  2631 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
  2633                                     int err) {
  2632                                     int err) {
  2634   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2633   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2635           ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
  2634           ", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
  2636           strerror(err), err);
  2635           strerror(err), err);
  2637 }
  2636 }
  2638 
  2637 
  2639 static void warn_fail_commit_memory(char* addr, size_t size,
  2638 static void warn_fail_commit_memory(char* addr, size_t size,
  2640                                     size_t alignment_hint, bool exec,
  2639                                     size_t alignment_hint, bool exec,
  2641                                     int err) {
  2640                                     int err) {
  2642   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2641   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2643           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", addr, size,
  2642           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", p2i(addr), size,
  2644           alignment_hint, exec, strerror(err), err);
  2643           alignment_hint, exec, strerror(err), err);
  2645 }
  2644 }
  2646 
  2645 
  2647 // NOTE: Linux kernel does not really reserve the pages for us.
  2646 // NOTE: Linux kernel does not really reserve the pages for us.
  2648 //       All it does is to check if there are enough free pages
  2647 //       All it does is to check if there are enough free pages
  4715 
  4714 
  4716   size_t threadStackSizeInBytes = ThreadStackSize * K;
  4715   size_t threadStackSizeInBytes = ThreadStackSize * K;
  4717   if (threadStackSizeInBytes != 0 &&
  4716   if (threadStackSizeInBytes != 0 &&
  4718       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
  4717       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
  4719     tty->print_cr("\nThe stack size specified is too small, "
  4718     tty->print_cr("\nThe stack size specified is too small, "
  4720                   "Specify at least %dk",
  4719                   "Specify at least " SIZE_FORMAT "k",
  4721                   os::Linux::min_stack_allowed/ K);
  4720                   os::Linux::min_stack_allowed/ K);
  4722     return JNI_ERR;
  4721     return JNI_ERR;
  4723   }
  4722   }
  4724 
  4723 
  4725   // Make the stack size a multiple of the page size so that
  4724   // Make the stack size a multiple of the page size so that
  4916 
  4915 
  4917 bool os::find(address addr, outputStream* st) {
  4916 bool os::find(address addr, outputStream* st) {
  4918   Dl_info dlinfo;
  4917   Dl_info dlinfo;
  4919   memset(&dlinfo, 0, sizeof(dlinfo));
  4918   memset(&dlinfo, 0, sizeof(dlinfo));
  4920   if (dladdr(addr, &dlinfo) != 0) {
  4919   if (dladdr(addr, &dlinfo) != 0) {
  4921     st->print(PTR_FORMAT ": ", addr);
  4920     st->print(PTR_FORMAT ": ", p2i(addr));
  4922     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  4921     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  4923       st->print("%s+%#x", dlinfo.dli_sname,
  4922       st->print("%s+" PTR_FORMAT, dlinfo.dli_sname,
  4924                 addr - (intptr_t)dlinfo.dli_saddr);
  4923                 p2i(addr) - p2i(dlinfo.dli_saddr));
  4925     } else if (dlinfo.dli_fbase != NULL) {
  4924     } else if (dlinfo.dli_fbase != NULL) {
  4926       st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
  4925       st->print("<offset " PTR_FORMAT ">", p2i(addr) - p2i(dlinfo.dli_fbase));
  4927     } else {
  4926     } else {
  4928       st->print("<absolute address>");
  4927       st->print("<absolute address>");
  4929     }
  4928     }
  4930     if (dlinfo.dli_fname != NULL) {
  4929     if (dlinfo.dli_fname != NULL) {
  4931       st->print(" in %s", dlinfo.dli_fname);
  4930       st->print(" in %s", dlinfo.dli_fname);
  4932     }
  4931     }
  4933     if (dlinfo.dli_fbase != NULL) {
  4932     if (dlinfo.dli_fbase != NULL) {
  4934       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  4933       st->print(" at " PTR_FORMAT, p2i(dlinfo.dli_fbase));
  4935     }
  4934     }
  4936     st->cr();
  4935     st->cr();
  4937 
  4936 
  4938     if (Verbose) {
  4937     if (Verbose) {
  4939       // decode some bytes around the PC
  4938       // decode some bytes around the PC
  5321 }
  5320 }
  5322 
  5321 
  5323 void os::pause() {
  5322 void os::pause() {
  5324   char filename[MAX_PATH];
  5323   char filename[MAX_PATH];
  5325   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
  5324   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
  5326     jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
  5325     jio_snprintf(filename, MAX_PATH, "%s", PauseAtStartupFile);
  5327   } else {
  5326   } else {
  5328     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
  5327     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
  5329   }
  5328   }
  5330 
  5329 
  5331   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  5330   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  5957 
  5956 
  5958   char *pid_pos = strstr(core_pattern, "%p");
  5957   char *pid_pos = strstr(core_pattern, "%p");
  5959   int written;
  5958   int written;
  5960 
  5959 
  5961   if (core_pattern[0] == '/') {
  5960   if (core_pattern[0] == '/') {
  5962     written = jio_snprintf(buffer, bufferSize, core_pattern);
  5961     written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
  5963   } else {
  5962   } else {
  5964     char cwd[PATH_MAX];
  5963     char cwd[PATH_MAX];
  5965 
  5964 
  5966     const char* p = get_current_directory(cwd, PATH_MAX);
  5965     const char* p = get_current_directory(cwd, PATH_MAX);
  5967     if (p == NULL) {
  5966     if (p == NULL) {
  6093     for (int i = 0; i < num_sizes; i++) {
  6092     for (int i = 0; i < num_sizes; i++) {
  6094       const size_t size = sizes[i];
  6093       const size_t size = sizes[i];
  6095       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6094       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6096         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, NULL, false);
  6095         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, NULL, false);
  6097         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " ->  " PTR_FORMAT " %s",
  6096         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " ->  " PTR_FORMAT " %s",
  6098             size, alignment, p, (p != NULL ? "" : "(failed)"));
  6097                  size, alignment, p2i(p), (p != NULL ? "" : "(failed)"));
  6099         if (p != NULL) {
  6098         if (p != NULL) {
  6100           assert(is_ptr_aligned(p, alignment), "must be");
  6099           assert(is_ptr_aligned(p, alignment), "must be");
  6101           small_page_write(p, size);
  6100           small_page_write(p, size);
  6102           os::Linux::release_memory_special_huge_tlbfs(p, size);
  6101           os::Linux::release_memory_special_huge_tlbfs(p, size);
  6103         }
  6102         }
  6112       const size_t size = sizes[i];
  6111       const size_t size = sizes[i];
  6113       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6112       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6114         char* const req_addr = (char*) align_ptr_up(mapping1, alignment);
  6113         char* const req_addr = (char*) align_ptr_up(mapping1, alignment);
  6115         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false);
  6114         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false);
  6116         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
  6115         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
  6117             size, alignment, req_addr, p,
  6116                  size, alignment, p2i(req_addr), p2i(p),
  6118             ((p != NULL ? (p == req_addr ? "(exact match)" : "") : "(failed)")));
  6117                  ((p != NULL ? (p == req_addr ? "(exact match)" : "") : "(failed)")));
  6119         if (p != NULL) {
  6118         if (p != NULL) {
  6120           assert(p == req_addr, "must be");
  6119           assert(p == req_addr, "must be");
  6121           small_page_write(p, size);
  6120           small_page_write(p, size);
  6122           os::Linux::release_memory_special_huge_tlbfs(p, size);
  6121           os::Linux::release_memory_special_huge_tlbfs(p, size);
  6123         }
  6122         }
  6132       const size_t size = sizes[i];
  6131       const size_t size = sizes[i];
  6133       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6132       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
  6134         char* const req_addr = (char*) align_ptr_up(mapping2, alignment);
  6133         char* const req_addr = (char*) align_ptr_up(mapping2, alignment);
  6135         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false);
  6134         char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false);
  6136         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
  6135         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
  6137             size, alignment, req_addr, p,
  6136                  size, alignment, p2i(req_addr), p2i(p), ((p != NULL ? "" : "(failed)")));
  6138             ((p != NULL ? "" : "(failed)")));
       
  6139         // as the area around req_addr contains already existing mappings, the API should always
  6137         // as the area around req_addr contains already existing mappings, the API should always
  6140         // return NULL (as per contract, it cannot return another address)
  6138         // return NULL (as per contract, it cannot return another address)
  6141         assert(p == NULL, "must be");
  6139         assert(p == NULL, "must be");
  6142       }
  6140       }
  6143     }
  6141     }