< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page
rev 9019 : [mq]: format.patch


  89 # include <sys/time.h>
  90 # include <sys/times.h>
  91 # include <sys/utsname.h>
  92 # include <sys/socket.h>
  93 # include <sys/wait.h>
  94 # include <pwd.h>
  95 # include <poll.h>
  96 # include <semaphore.h>
  97 # include <fcntl.h>
  98 # include <string.h>
  99 # include <syscall.h>
 100 # include <sys/sysinfo.h>
 101 # include <gnu/libc-version.h>
 102 # include <sys/ipc.h>
 103 # include <sys/shm.h>
 104 # include <link.h>
 105 # include <stdint.h>
 106 # include <inttypes.h>
 107 # include <sys/ioctl.h>
 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
 112 // getrusage() is prepared to handle the associated failure.
 113 #ifndef RUSAGE_THREAD
 114   #define RUSAGE_THREAD   (1)               /* only the calling thread */
 115 #endif
 116 
 117 #define MAX_PATH    (2 * K)
 118 
 119 #define MAX_SECS 100000000
 120 
 121 // for timer info max values which include all bits
 122 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 123 
 124 #define LARGEPAGES_BIT (1 << 6)
 125 ////////////////////////////////////////////////////////////////////////////////
 126 // global variables
 127 julong os::Linux::_physical_memory = 0;
 128 
 129 address   os::Linux::_initial_thread_stack_bottom = NULL;


1952     st->print("Can not get library information for pid = %d\n", pid);
1953   }
1954 }
1955 
1956 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1957   FILE *procmapsFile = NULL;
1958 
1959   // Open the procfs maps file for the current process
1960   if ((procmapsFile = fopen("/proc/self/maps", "r")) != NULL) {
1961     // Allocate PATH_MAX for file name plus a reasonable size for other fields.
1962     char line[PATH_MAX + 100];
1963 
1964     // Read line by line from 'file'
1965     while (fgets(line, sizeof(line), procmapsFile) != NULL) {
1966       u8 base, top, offset, inode;
1967       char permissions[5];
1968       char device[6];
1969       char name[PATH_MAX + 1];
1970 
1971       // Parse fields from line
1972       sscanf(line, "%lx-%lx %4s %lx %5s %ld %s", &base, &top, permissions, &offset, device, &inode, name);

1973 
1974       // Filter by device id '00:00' so that we only get file system mapped files.
1975       if (strcmp(device, "00:00") != 0) {
1976 
1977         // Call callback with the fields of interest
1978         if(callback(name, (address)base, (address)top, param)) {
1979           // Oops abort, callback aborted
1980           fclose(procmapsFile);
1981           return 1;
1982         }
1983       }
1984     }
1985     fclose(procmapsFile);
1986   }
1987   return 0;
1988 }
1989 
1990 void os::print_os_info_brief(outputStream* st) {
1991   os::Linux::print_distro_info(st);
1992 


2615   switch (err) {
2616   case EBADF:
2617   case EINVAL:
2618   case ENOTSUP:
2619     // let the caller deal with these errors
2620     return true;
2621 
2622   default:
2623     // Any remaining errors on this OS can cause our reserved mapping
2624     // to be lost. That can cause confusion where different data
2625     // structures think they have the same memory mapped. The worst
2626     // scenario is if both the VM and a library think they have the
2627     // same memory mapped.
2628     return false;
2629   }
2630 }
2631 
2632 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
2633                                     int err) {
2634   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
2635           ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
2636           strerror(err), err);
2637 }
2638 
2639 static void warn_fail_commit_memory(char* addr, size_t size,
2640                                     size_t alignment_hint, bool exec,
2641                                     int err) {
2642   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
2643           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", addr, size,
2644           alignment_hint, exec, strerror(err), err);
2645 }
2646 
2647 // NOTE: Linux kernel does not really reserve the pages for us.
2648 //       All it does is to check if there are enough free pages
2649 //       left at the time of mmap(). This could be a potential
2650 //       problem.
2651 int os::Linux::commit_memory_impl(char* addr, size_t size, bool exec) {
2652   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2653   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
2654                                      MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2655   if (res != (uintptr_t) MAP_FAILED) {
2656     if (UseNUMAInterleaving) {
2657       numa_make_global(addr, size);
2658     }
2659     return 0;
2660   }
2661 
2662   int err = errno;  // save errno from mmap() call above
2663 


4700     perror("SR_initialize failed");
4701     return JNI_ERR;
4702   }
4703 
4704   Linux::signal_sets_init();
4705   Linux::install_signal_handlers();
4706 
4707   // Check minimum allowable stack size for thread creation and to initialize
4708   // the java system classes, including StackOverflowError - depends on page
4709   // size.  Add a page for compiler2 recursion in main thread.
4710   // Add in 2*BytesPerWord times page size to account for VM stack during
4711   // class initialization depending on 32 or 64 bit VM.
4712   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4713                                       (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
4714                                       (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
4715 
4716   size_t threadStackSizeInBytes = ThreadStackSize * K;
4717   if (threadStackSizeInBytes != 0 &&
4718       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4719     tty->print_cr("\nThe stack size specified is too small, "
4720                   "Specify at least %dk",
4721                   os::Linux::min_stack_allowed/ K);
4722     return JNI_ERR;
4723   }
4724 
4725   // Make the stack size a multiple of the page size so that
4726   // the yellow/red zones can be guarded.
4727   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4728                                                 vm_page_size()));
4729 
4730   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4731 
4732 #if defined(IA32)
4733   workaround_expand_exec_shield_cs_limit();
4734 #endif
4735 
4736   Linux::libpthread_init();
4737   if (PrintMiscellaneous && (Verbose || WizardMode)) {
4738     tty->print_cr("[HotSpot is running with %s, %s]\n",
4739                   Linux::glibc_version(), Linux::libpthread_version());
4740   }


4901 
4902 // Suspends the target using the signal mechanism and then grabs the PC before
4903 // resuming the target. Used by the flat-profiler only
4904 ExtendedPC os::get_thread_pc(Thread* thread) {
4905   // Make sure that it is called by the watcher for the VMThread
4906   assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
4907   assert(thread->is_VM_thread(), "Can only be called for VMThread");
4908 
4909   PcFetcher fetcher(thread);
4910   fetcher.run();
4911   return fetcher.result();
4912 }
4913 
4914 ////////////////////////////////////////////////////////////////////////////////
4915 // debug support
4916 
4917 bool os::find(address addr, outputStream* st) {
4918   Dl_info dlinfo;
4919   memset(&dlinfo, 0, sizeof(dlinfo));
4920   if (dladdr(addr, &dlinfo) != 0) {
4921     st->print(PTR_FORMAT ": ", addr);
4922     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
4923       st->print("%s+%#x", dlinfo.dli_sname,
4924                 addr - (intptr_t)dlinfo.dli_saddr);
4925     } else if (dlinfo.dli_fbase != NULL) {
4926       st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
4927     } else {
4928       st->print("<absolute address>");
4929     }
4930     if (dlinfo.dli_fname != NULL) {
4931       st->print(" in %s", dlinfo.dli_fname);
4932     }
4933     if (dlinfo.dli_fbase != NULL) {
4934       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
4935     }
4936     st->cr();
4937 
4938     if (Verbose) {
4939       // decode some bytes around the PC
4940       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
4941       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
4942       address       lowest = (address) dlinfo.dli_sname;
4943       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
4944       if (begin < lowest)  begin = lowest;
4945       Dl_info dlinfo2;
4946       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
4947           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
4948         end = (address) dlinfo2.dli_saddr;
4949       }
4950       Disassembler::decode(begin, end, st);
4951     }
4952     return true;
4953   }
4954   return false;


5306   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
5307   info_ptr->may_skip_backward = false;     // elapsed time not wall time
5308   info_ptr->may_skip_forward = false;      // elapsed time not wall time
5309   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
5310 }
5311 
5312 bool os::is_thread_cpu_time_supported() {
5313   return true;
5314 }
5315 
5316 // System loadavg support.  Returns -1 if load average cannot be obtained.
5317 // Linux doesn't yet have a (official) notion of processor sets,
5318 // so just return the system wide load average.
5319 int os::loadavg(double loadavg[], int nelem) {
5320   return ::getloadavg(loadavg, nelem);
5321 }
5322 
5323 void os::pause() {
5324   char filename[MAX_PATH];
5325   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
5326     jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
5327   } else {
5328     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
5329   }
5330 
5331   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
5332   if (fd != -1) {
5333     struct stat buf;
5334     ::close(fd);
5335     while (::stat(filename, &buf) == 0) {
5336       (void)::poll(NULL, 0, 100);
5337     }
5338   } else {
5339     jio_fprintf(stderr,
5340                 "Could not open pause file '%s', continuing immediately.\n", filename);
5341   }
5342 }
5343 
5344 
5345 // Refer to the comments in os_solaris.cpp park-unpark. The next two
5346 // comment paragraphs are worth repeating here:


5942     ssize_t ret = ::read(core_pattern_file, core_pattern, core_pattern_len);
5943     ::close(core_pattern_file);
5944 
5945     if (ret > 0) {
5946       char *last_char = core_pattern + strlen(core_pattern) - 1;
5947 
5948       if (*last_char == '\n') {
5949         *last_char = '\0';
5950       }
5951     }
5952   }
5953 
5954   if (strlen(core_pattern) == 0) {
5955     return -1;
5956   }
5957 
5958   char *pid_pos = strstr(core_pattern, "%p");
5959   int written;
5960 
5961   if (core_pattern[0] == '/') {
5962     written = jio_snprintf(buffer, bufferSize, core_pattern);
5963   } else {
5964     char cwd[PATH_MAX];
5965 
5966     const char* p = get_current_directory(cwd, PATH_MAX);
5967     if (p == NULL) {
5968       return -1;
5969     }
5970 
5971     if (core_pattern[0] == '|') {
5972       written = jio_snprintf(buffer, bufferSize,
5973                         "\"%s\" (or dumping to %s/core.%d)",
5974                                      &core_pattern[1], p, current_process_id());
5975     } else {
5976       written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
5977     }
5978   }
5979 
5980   if (written < 0) {
5981     return -1;
5982   }


6078 
6079     char* const mapping2 = (char*) ::mmap(NULL, mapping_size,
6080       PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
6081       -1, 0);
6082     assert(mapping2 != MAP_FAILED, "should work");
6083 
6084     // Unmap the first mapping, but leave the second mapping intact: the first
6085     // mapping will serve as a value for a "good" req_addr (case 2). The second
6086     // mapping, still intact, as "bad" req_addr (case 3).
6087     ::munmap(mapping1, mapping_size);
6088 
6089     // Case 1
6090     test_log("%s, req_addr NULL:", __FUNCTION__);
6091     test_log("size            align           result");
6092 
6093     for (int i = 0; i < num_sizes; i++) {
6094       const size_t size = sizes[i];
6095       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);
6097         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " ->  " PTR_FORMAT " %s",
6098             size, alignment, p, (p != NULL ? "" : "(failed)"));
6099         if (p != NULL) {
6100           assert(is_ptr_aligned(p, alignment), "must be");
6101           small_page_write(p, size);
6102           os::Linux::release_memory_special_huge_tlbfs(p, size);
6103         }
6104       }
6105     }
6106 
6107     // Case 2
6108     test_log("%s, req_addr non-NULL:", __FUNCTION__);
6109     test_log("size            align           req_addr         result");
6110 
6111     for (int i = 0; i < num_sizes; i++) {
6112       const size_t size = sizes[i];
6113       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
6114         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);
6116         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
6117             size, alignment, req_addr, p,
6118             ((p != NULL ? (p == req_addr ? "(exact match)" : "") : "(failed)")));
6119         if (p != NULL) {
6120           assert(p == req_addr, "must be");
6121           small_page_write(p, size);
6122           os::Linux::release_memory_special_huge_tlbfs(p, size);
6123         }
6124       }
6125     }
6126 
6127     // Case 3
6128     test_log("%s, req_addr non-NULL with preexisting mapping:", __FUNCTION__);
6129     test_log("size            align           req_addr         result");
6130 
6131     for (int i = 0; i < num_sizes; i++) {
6132       const size_t size = sizes[i];
6133       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
6134         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);
6136         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
6137             size, alignment, req_addr, p,
6138             ((p != NULL ? "" : "(failed)")));
6139         // 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)
6141         assert(p == NULL, "must be");
6142       }
6143     }
6144 
6145     ::munmap(mapping2, mapping_size);
6146 
6147   }
6148 
6149   static void test_reserve_memory_special_huge_tlbfs() {
6150     if (!UseHugeTLBFS) {
6151       return;
6152     }
6153 
6154     test_reserve_memory_special_huge_tlbfs_only();
6155     test_reserve_memory_special_huge_tlbfs_mixed();
6156   }
6157 




  89 # include <sys/time.h>
  90 # include <sys/times.h>
  91 # include <sys/utsname.h>
  92 # include <sys/socket.h>
  93 # include <sys/wait.h>
  94 # include <pwd.h>
  95 # include <poll.h>
  96 # include <semaphore.h>
  97 # include <fcntl.h>
  98 # include <string.h>
  99 # include <syscall.h>
 100 # include <sys/sysinfo.h>
 101 # include <gnu/libc-version.h>
 102 # include <sys/ipc.h>
 103 # include <sys/shm.h>
 104 # include <link.h>
 105 # include <stdint.h>
 106 # include <inttypes.h>
 107 # include <sys/ioctl.h>
 108 

 109 
 110 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 111 // getrusage() is prepared to handle the associated failure.
 112 #ifndef RUSAGE_THREAD
 113   #define RUSAGE_THREAD   (1)               /* only the calling thread */
 114 #endif
 115 
 116 #define MAX_PATH    (2 * K)
 117 
 118 #define MAX_SECS 100000000
 119 
 120 // for timer info max values which include all bits
 121 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 122 
 123 #define LARGEPAGES_BIT (1 << 6)
 124 ////////////////////////////////////////////////////////////////////////////////
 125 // global variables
 126 julong os::Linux::_physical_memory = 0;
 127 
 128 address   os::Linux::_initial_thread_stack_bottom = NULL;


1951     st->print("Can not get library information for pid = %d\n", pid);
1952   }
1953 }
1954 
1955 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1956   FILE *procmapsFile = NULL;
1957 
1958   // Open the procfs maps file for the current process
1959   if ((procmapsFile = fopen("/proc/self/maps", "r")) != NULL) {
1960     // Allocate PATH_MAX for file name plus a reasonable size for other fields.
1961     char line[PATH_MAX + 100];
1962 
1963     // Read line by line from 'file'
1964     while (fgets(line, sizeof(line), procmapsFile) != NULL) {
1965       u8 base, top, offset, inode;
1966       char permissions[5];
1967       char device[6];
1968       char name[PATH_MAX + 1];
1969 
1970       // Parse fields from line
1971       sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %5s " INT64_FORMAT " %s",
1972              &base, &top, permissions, &offset, device, &inode, name);
1973 
1974       // Filter by device id '00:00' so that we only get file system mapped files.
1975       if (strcmp(device, "00:00") != 0) {
1976 
1977         // Call callback with the fields of interest
1978         if(callback(name, (address)base, (address)top, param)) {
1979           // Oops abort, callback aborted
1980           fclose(procmapsFile);
1981           return 1;
1982         }
1983       }
1984     }
1985     fclose(procmapsFile);
1986   }
1987   return 0;
1988 }
1989 
1990 void os::print_os_info_brief(outputStream* st) {
1991   os::Linux::print_distro_info(st);
1992 


2615   switch (err) {
2616   case EBADF:
2617   case EINVAL:
2618   case ENOTSUP:
2619     // let the caller deal with these errors
2620     return true;
2621 
2622   default:
2623     // Any remaining errors on this OS can cause our reserved mapping
2624     // to be lost. That can cause confusion where different data
2625     // structures think they have the same memory mapped. The worst
2626     // scenario is if both the VM and a library think they have the
2627     // same memory mapped.
2628     return false;
2629   }
2630 }
2631 
2632 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
2633                                     int err) {
2634   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
2635           ", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
2636           strerror(err), err);
2637 }
2638 
2639 static void warn_fail_commit_memory(char* addr, size_t size,
2640                                     size_t alignment_hint, bool exec,
2641                                     int err) {
2642   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
2643           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", p2i(addr), size,
2644           alignment_hint, exec, strerror(err), err);
2645 }
2646 
2647 // NOTE: Linux kernel does not really reserve the pages for us.
2648 //       All it does is to check if there are enough free pages
2649 //       left at the time of mmap(). This could be a potential
2650 //       problem.
2651 int os::Linux::commit_memory_impl(char* addr, size_t size, bool exec) {
2652   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2653   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
2654                                      MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2655   if (res != (uintptr_t) MAP_FAILED) {
2656     if (UseNUMAInterleaving) {
2657       numa_make_global(addr, size);
2658     }
2659     return 0;
2660   }
2661 
2662   int err = errno;  // save errno from mmap() call above
2663 


4700     perror("SR_initialize failed");
4701     return JNI_ERR;
4702   }
4703 
4704   Linux::signal_sets_init();
4705   Linux::install_signal_handlers();
4706 
4707   // Check minimum allowable stack size for thread creation and to initialize
4708   // the java system classes, including StackOverflowError - depends on page
4709   // size.  Add a page for compiler2 recursion in main thread.
4710   // Add in 2*BytesPerWord times page size to account for VM stack during
4711   // class initialization depending on 32 or 64 bit VM.
4712   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
4713                                       (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
4714                                       (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
4715 
4716   size_t threadStackSizeInBytes = ThreadStackSize * K;
4717   if (threadStackSizeInBytes != 0 &&
4718       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
4719     tty->print_cr("\nThe stack size specified is too small, "
4720                   "Specify at least " SIZE_FORMAT "k",
4721                   os::Linux::min_stack_allowed/ K);
4722     return JNI_ERR;
4723   }
4724 
4725   // Make the stack size a multiple of the page size so that
4726   // the yellow/red zones can be guarded.
4727   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
4728                                                 vm_page_size()));
4729 
4730   Linux::capture_initial_stack(JavaThread::stack_size_at_create());
4731 
4732 #if defined(IA32)
4733   workaround_expand_exec_shield_cs_limit();
4734 #endif
4735 
4736   Linux::libpthread_init();
4737   if (PrintMiscellaneous && (Verbose || WizardMode)) {
4738     tty->print_cr("[HotSpot is running with %s, %s]\n",
4739                   Linux::glibc_version(), Linux::libpthread_version());
4740   }


4901 
4902 // Suspends the target using the signal mechanism and then grabs the PC before
4903 // resuming the target. Used by the flat-profiler only
4904 ExtendedPC os::get_thread_pc(Thread* thread) {
4905   // Make sure that it is called by the watcher for the VMThread
4906   assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
4907   assert(thread->is_VM_thread(), "Can only be called for VMThread");
4908 
4909   PcFetcher fetcher(thread);
4910   fetcher.run();
4911   return fetcher.result();
4912 }
4913 
4914 ////////////////////////////////////////////////////////////////////////////////
4915 // debug support
4916 
4917 bool os::find(address addr, outputStream* st) {
4918   Dl_info dlinfo;
4919   memset(&dlinfo, 0, sizeof(dlinfo));
4920   if (dladdr(addr, &dlinfo) != 0) {
4921     st->print(PTR_FORMAT ": ", p2i(addr));
4922     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
4923       st->print("%s+" INTPTR_FORMAT_W(#), dlinfo.dli_sname,
4924                 p2i(addr - (intptr_t)dlinfo.dli_saddr));
4925     } else if (dlinfo.dli_fbase != NULL) {
4926       st->print("<offset " INTPTR_FORMAT_W(#) ">", p2i(addr - (intptr_t)dlinfo.dli_fbase));
4927     } else {
4928       st->print("<absolute address>");
4929     }
4930     if (dlinfo.dli_fname != NULL) {
4931       st->print(" in %s", dlinfo.dli_fname);
4932     }
4933     if (dlinfo.dli_fbase != NULL) {
4934       st->print(" at " PTR_FORMAT, p2i(dlinfo.dli_fbase));
4935     }
4936     st->cr();
4937 
4938     if (Verbose) {
4939       // decode some bytes around the PC
4940       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
4941       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
4942       address       lowest = (address) dlinfo.dli_sname;
4943       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
4944       if (begin < lowest)  begin = lowest;
4945       Dl_info dlinfo2;
4946       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
4947           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
4948         end = (address) dlinfo2.dli_saddr;
4949       }
4950       Disassembler::decode(begin, end, st);
4951     }
4952     return true;
4953   }
4954   return false;


5306   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
5307   info_ptr->may_skip_backward = false;     // elapsed time not wall time
5308   info_ptr->may_skip_forward = false;      // elapsed time not wall time
5309   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
5310 }
5311 
5312 bool os::is_thread_cpu_time_supported() {
5313   return true;
5314 }
5315 
5316 // System loadavg support.  Returns -1 if load average cannot be obtained.
5317 // Linux doesn't yet have a (official) notion of processor sets,
5318 // so just return the system wide load average.
5319 int os::loadavg(double loadavg[], int nelem) {
5320   return ::getloadavg(loadavg, nelem);
5321 }
5322 
5323 void os::pause() {
5324   char filename[MAX_PATH];
5325   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
5326     jio_snprintf(filename, MAX_PATH, "%s", PauseAtStartupFile);
5327   } else {
5328     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
5329   }
5330 
5331   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
5332   if (fd != -1) {
5333     struct stat buf;
5334     ::close(fd);
5335     while (::stat(filename, &buf) == 0) {
5336       (void)::poll(NULL, 0, 100);
5337     }
5338   } else {
5339     jio_fprintf(stderr,
5340                 "Could not open pause file '%s', continuing immediately.\n", filename);
5341   }
5342 }
5343 
5344 
5345 // Refer to the comments in os_solaris.cpp park-unpark. The next two
5346 // comment paragraphs are worth repeating here:


5942     ssize_t ret = ::read(core_pattern_file, core_pattern, core_pattern_len);
5943     ::close(core_pattern_file);
5944 
5945     if (ret > 0) {
5946       char *last_char = core_pattern + strlen(core_pattern) - 1;
5947 
5948       if (*last_char == '\n') {
5949         *last_char = '\0';
5950       }
5951     }
5952   }
5953 
5954   if (strlen(core_pattern) == 0) {
5955     return -1;
5956   }
5957 
5958   char *pid_pos = strstr(core_pattern, "%p");
5959   int written;
5960 
5961   if (core_pattern[0] == '/') {
5962     written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
5963   } else {
5964     char cwd[PATH_MAX];
5965 
5966     const char* p = get_current_directory(cwd, PATH_MAX);
5967     if (p == NULL) {
5968       return -1;
5969     }
5970 
5971     if (core_pattern[0] == '|') {
5972       written = jio_snprintf(buffer, bufferSize,
5973                         "\"%s\" (or dumping to %s/core.%d)",
5974                                      &core_pattern[1], p, current_process_id());
5975     } else {
5976       written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
5977     }
5978   }
5979 
5980   if (written < 0) {
5981     return -1;
5982   }


6078 
6079     char* const mapping2 = (char*) ::mmap(NULL, mapping_size,
6080       PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,
6081       -1, 0);
6082     assert(mapping2 != MAP_FAILED, "should work");
6083 
6084     // Unmap the first mapping, but leave the second mapping intact: the first
6085     // mapping will serve as a value for a "good" req_addr (case 2). The second
6086     // mapping, still intact, as "bad" req_addr (case 3).
6087     ::munmap(mapping1, mapping_size);
6088 
6089     // Case 1
6090     test_log("%s, req_addr NULL:", __FUNCTION__);
6091     test_log("size            align           result");
6092 
6093     for (int i = 0; i < num_sizes; i++) {
6094       const size_t size = sizes[i];
6095       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);
6097         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " ->  " PTR_FORMAT " %s",
6098                  size, alignment, p2i(p), (p != NULL ? "" : "(failed)"));
6099         if (p != NULL) {
6100           assert(is_ptr_aligned(p, alignment), "must be");
6101           small_page_write(p, size);
6102           os::Linux::release_memory_special_huge_tlbfs(p, size);
6103         }
6104       }
6105     }
6106 
6107     // Case 2
6108     test_log("%s, req_addr non-NULL:", __FUNCTION__);
6109     test_log("size            align           req_addr         result");
6110 
6111     for (int i = 0; i < num_sizes; i++) {
6112       const size_t size = sizes[i];
6113       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
6114         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);
6116         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
6117                  size, alignment, p2i(req_addr), p2i(p),
6118                  ((p != NULL ? (p == req_addr ? "(exact match)" : "") : "(failed)")));
6119         if (p != NULL) {
6120           assert(p == req_addr, "must be");
6121           small_page_write(p, size);
6122           os::Linux::release_memory_special_huge_tlbfs(p, size);
6123         }
6124       }
6125     }
6126 
6127     // Case 3
6128     test_log("%s, req_addr non-NULL with preexisting mapping:", __FUNCTION__);
6129     test_log("size            align           req_addr         result");
6130 
6131     for (int i = 0; i < num_sizes; i++) {
6132       const size_t size = sizes[i];
6133       for (size_t alignment = ag; is_size_aligned(size, alignment); alignment *= 2) {
6134         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);
6136         test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " ->  " PTR_FORMAT " %s",
6137                  size, alignment, p2i(req_addr), p2i(p),
6138                  ((p != NULL ? "" : "(failed)")));
6139         // 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)
6141         assert(p == NULL, "must be");
6142       }
6143     }
6144 
6145     ::munmap(mapping2, mapping_size);
6146 
6147   }
6148 
6149   static void test_reserve_memory_special_huge_tlbfs() {
6150     if (!UseHugeTLBFS) {
6151       return;
6152     }
6153 
6154     test_reserve_memory_special_huge_tlbfs_only();
6155     test_reserve_memory_special_huge_tlbfs_mixed();
6156   }
6157 


< prev index next >