comparison src/os/linux/vm/os_linux.cpp @ 6275:957c266d8bc5

Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Tue, 21 Aug 2012 10:39:19 +0200
parents 897b7d18bebc 65906dc96aa1
children e522a00b91aa
comparison
equal deleted inserted replaced
5891:fd8832ae511d 6275:957c266d8bc5
369 // 369 //
370 // Important note: if the location of libjvm.so changes this 370 // Important note: if the location of libjvm.so changes this
371 // code needs to be changed accordingly. 371 // code needs to be changed accordingly.
372 372
373 // The next few definitions allow the code to be verbatim: 373 // The next few definitions allow the code to be verbatim:
374 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n)) 374 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
375 #define getenv(n) ::getenv(n) 375 #define getenv(n) ::getenv(n)
376 376
377 /* 377 /*
378 * See ld(1): 378 * See ld(1):
379 * The linker uses the following search paths to locate required 379 * The linker uses the following search paths to locate required
637 # define _CS_GNU_LIBPTHREAD_VERSION 3 637 # define _CS_GNU_LIBPTHREAD_VERSION 3
638 # endif 638 # endif
639 639
640 size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); 640 size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
641 if (n > 0) { 641 if (n > 0) {
642 char *str = (char *)malloc(n); 642 char *str = (char *)malloc(n, mtInternal);
643 confstr(_CS_GNU_LIBC_VERSION, str, n); 643 confstr(_CS_GNU_LIBC_VERSION, str, n);
644 os::Linux::set_glibc_version(str); 644 os::Linux::set_glibc_version(str);
645 } else { 645 } else {
646 // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version() 646 // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
647 static char _gnu_libc_version[32]; 647 static char _gnu_libc_version[32];
650 os::Linux::set_glibc_version(_gnu_libc_version); 650 os::Linux::set_glibc_version(_gnu_libc_version);
651 } 651 }
652 652
653 n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0); 653 n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
654 if (n > 0) { 654 if (n > 0) {
655 char *str = (char *)malloc(n); 655 char *str = (char *)malloc(n, mtInternal);
656 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n); 656 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
657 // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells 657 // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
658 // us "NPTL-0.29" even we are running with LinuxThreads. Check if this 658 // us "NPTL-0.29" even we are running with LinuxThreads. Check if this
659 // is the case. LinuxThreads has a hard limit on max number of threads. 659 // is the case. LinuxThreads has a hard limit on max number of threads.
660 // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value. 660 // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
1683 } 1683 }
1684 } 1684 }
1685 // release the storage 1685 // release the storage
1686 for (int i = 0 ; i < n ; i++) { 1686 for (int i = 0 ; i < n ; i++) {
1687 if (pelements[i] != NULL) { 1687 if (pelements[i] != NULL) {
1688 FREE_C_HEAP_ARRAY(char, pelements[i]); 1688 FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
1689 } 1689 }
1690 } 1690 }
1691 if (pelements != NULL) { 1691 if (pelements != NULL) {
1692 FREE_C_HEAP_ARRAY(char*, pelements); 1692 FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
1693 } 1693 }
1694 } else { 1694 } else {
1695 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname); 1695 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
1696 } 1696 }
1697 } 1697 }
2018 if (!_print_ascii_file(fname, st)) { 2018 if (!_print_ascii_file(fname, st)) {
2019 st->print("Can not get library information for pid = %d\n", pid); 2019 st->print("Can not get library information for pid = %d\n", pid);
2020 } 2020 }
2021 } 2021 }
2022 2022
2023 void os::print_os_info_brief(outputStream* st) {
2024 os::Linux::print_distro_info(st);
2025
2026 os::Posix::print_uname_info(st);
2027
2028 os::Linux::print_libversion_info(st);
2029
2030 }
2023 2031
2024 void os::print_os_info(outputStream* st) { 2032 void os::print_os_info(outputStream* st) {
2025 st->print("OS:"); 2033 st->print("OS:");
2026 2034
2027 // Try to identify popular distros. 2035 os::Linux::print_distro_info(st);
2028 // Most Linux distributions have /etc/XXX-release file, which contains 2036
2029 // the OS version string. Some have more than one /etc/XXX-release file 2037 os::Posix::print_uname_info(st);
2030 // (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.), 2038
2031 // so the order is important. 2039 // Print warning if unsafe chroot environment detected
2040 if (unsafe_chroot_detected) {
2041 st->print("WARNING!! ");
2042 st->print_cr(unstable_chroot_error);
2043 }
2044
2045 os::Linux::print_libversion_info(st);
2046
2047 os::Posix::print_rlimit_info(st);
2048
2049 os::Posix::print_load_average(st);
2050
2051 os::Linux::print_full_memory_info(st);
2052 }
2053
2054 // Try to identify popular distros.
2055 // Most Linux distributions have /etc/XXX-release file, which contains
2056 // the OS version string. Some have more than one /etc/XXX-release file
2057 // (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.),
2058 // so the order is important.
2059 void os::Linux::print_distro_info(outputStream* st) {
2032 if (!_print_ascii_file("/etc/mandrake-release", st) && 2060 if (!_print_ascii_file("/etc/mandrake-release", st) &&
2033 !_print_ascii_file("/etc/sun-release", st) && 2061 !_print_ascii_file("/etc/sun-release", st) &&
2034 !_print_ascii_file("/etc/redhat-release", st) && 2062 !_print_ascii_file("/etc/redhat-release", st) &&
2035 !_print_ascii_file("/etc/SuSE-release", st) && 2063 !_print_ascii_file("/etc/SuSE-release", st) &&
2036 !_print_ascii_file("/etc/turbolinux-release", st) && 2064 !_print_ascii_file("/etc/turbolinux-release", st) &&
2039 !_print_ascii_file("/etc/ltib-release", st) && 2067 !_print_ascii_file("/etc/ltib-release", st) &&
2040 !_print_ascii_file("/etc/angstrom-version", st)) { 2068 !_print_ascii_file("/etc/angstrom-version", st)) {
2041 st->print("Linux"); 2069 st->print("Linux");
2042 } 2070 }
2043 st->cr(); 2071 st->cr();
2044 2072 }
2045 // kernel 2073
2046 st->print("uname:"); 2074 void os::Linux::print_libversion_info(outputStream* st) {
2047 struct utsname name;
2048 uname(&name);
2049 st->print(name.sysname); st->print(" ");
2050 st->print(name.release); st->print(" ");
2051 st->print(name.version); st->print(" ");
2052 st->print(name.machine);
2053 st->cr();
2054
2055 // Print warning if unsafe chroot environment detected
2056 if (unsafe_chroot_detected) {
2057 st->print("WARNING!! ");
2058 st->print_cr(unstable_chroot_error);
2059 }
2060
2061 // libc, pthread 2075 // libc, pthread
2062 st->print("libc:"); 2076 st->print("libc:");
2063 st->print(os::Linux::glibc_version()); st->print(" "); 2077 st->print(os::Linux::glibc_version()); st->print(" ");
2064 st->print(os::Linux::libpthread_version()); st->print(" "); 2078 st->print(os::Linux::libpthread_version()); st->print(" ");
2065 if (os::Linux::is_LinuxThreads()) { 2079 if (os::Linux::is_LinuxThreads()) {
2066 st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed"); 2080 st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
2067 } 2081 }
2068 st->cr(); 2082 st->cr();
2069 2083 }
2070 // rlimit 2084
2071 st->print("rlimit:"); 2085 void os::Linux::print_full_memory_info(outputStream* st) {
2072 struct rlimit rlim; 2086 st->print("\n/proc/meminfo:\n");
2073 2087 _print_ascii_file("/proc/meminfo", st);
2074 st->print(" STACK "); 2088 st->cr();
2075 getrlimit(RLIMIT_STACK, &rlim);
2076 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2077 else st->print("%uk", rlim.rlim_cur >> 10);
2078
2079 st->print(", CORE ");
2080 getrlimit(RLIMIT_CORE, &rlim);
2081 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2082 else st->print("%uk", rlim.rlim_cur >> 10);
2083
2084 st->print(", NPROC ");
2085 getrlimit(RLIMIT_NPROC, &rlim);
2086 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2087 else st->print("%d", rlim.rlim_cur);
2088
2089 st->print(", NOFILE ");
2090 getrlimit(RLIMIT_NOFILE, &rlim);
2091 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2092 else st->print("%d", rlim.rlim_cur);
2093
2094 st->print(", AS ");
2095 getrlimit(RLIMIT_AS, &rlim);
2096 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2097 else st->print("%uk", rlim.rlim_cur >> 10);
2098 st->cr();
2099
2100 // load average
2101 st->print("load average:");
2102 double loadavg[3];
2103 os::loadavg(loadavg, 3);
2104 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
2105 st->cr();
2106
2107 // meminfo
2108 st->print("\n/proc/meminfo:\n");
2109 _print_ascii_file("/proc/meminfo", st);
2110 st->cr();
2111 }
2112
2113 void os::pd_print_cpu_info(outputStream* st) {
2114 st->print("\n/proc/cpuinfo:\n");
2115 if (!_print_ascii_file("/proc/cpuinfo", st)) {
2116 st->print(" <Not Available>");
2117 }
2118 st->cr();
2119 } 2089 }
2120 2090
2121 void os::print_memory_info(outputStream* st) { 2091 void os::print_memory_info(outputStream* st) {
2122 2092
2123 st->print("Memory:"); 2093 st->print("Memory:");
2133 os::available_memory() >> 10); 2103 os::available_memory() >> 10);
2134 st->print(", swap " UINT64_FORMAT "k", 2104 st->print(", swap " UINT64_FORMAT "k",
2135 ((jlong)si.totalswap * si.mem_unit) >> 10); 2105 ((jlong)si.totalswap * si.mem_unit) >> 10);
2136 st->print("(" UINT64_FORMAT "k free)", 2106 st->print("(" UINT64_FORMAT "k free)",
2137 ((jlong)si.freeswap * si.mem_unit) >> 10); 2107 ((jlong)si.freeswap * si.mem_unit) >> 10);
2108 st->cr();
2109 }
2110
2111 void os::pd_print_cpu_info(outputStream* st) {
2112 st->print("\n/proc/cpuinfo:\n");
2113 if (!_print_ascii_file("/proc/cpuinfo", st)) {
2114 st->print(" <Not Available>");
2115 }
2138 st->cr(); 2116 st->cr();
2139 } 2117 }
2140 2118
2141 // Taken from /usr/include/bits/siginfo.h Supposed to be architecture specific 2119 // Taken from /usr/include/bits/siginfo.h Supposed to be architecture specific
2142 // but they're the same for all the linux arch that we support 2120 // but they're the same for all the linux arch that we support
2489 2467
2490 // NOTE: Linux kernel does not really reserve the pages for us. 2468 // NOTE: Linux kernel does not really reserve the pages for us.
2491 // All it does is to check if there are enough free pages 2469 // All it does is to check if there are enough free pages
2492 // left at the time of mmap(). This could be a potential 2470 // left at the time of mmap(). This could be a potential
2493 // problem. 2471 // problem.
2494 bool os::commit_memory(char* addr, size_t size, bool exec) { 2472 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
2495 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; 2473 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2496 uintptr_t res = (uintptr_t) ::mmap(addr, size, prot, 2474 uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
2497 MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0); 2475 MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2498 if (res != (uintptr_t) MAP_FAILED) { 2476 if (res != (uintptr_t) MAP_FAILED) {
2499 if (UseNUMAInterleaving) { 2477 if (UseNUMAInterleaving) {
2512 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems. 2490 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
2513 #ifndef MADV_HUGEPAGE 2491 #ifndef MADV_HUGEPAGE
2514 #define MADV_HUGEPAGE 14 2492 #define MADV_HUGEPAGE 14
2515 #endif 2493 #endif
2516 2494
2517 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, 2495 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
2518 bool exec) { 2496 bool exec) {
2519 if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) { 2497 if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
2520 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; 2498 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2521 uintptr_t res = 2499 uintptr_t res =
2522 (uintptr_t) ::mmap(addr, size, prot, 2500 (uintptr_t) ::mmap(addr, size, prot,
2536 return true; 2514 return true;
2537 } 2515 }
2538 return false; 2516 return false;
2539 } 2517 }
2540 2518
2541 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { 2519 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
2542 if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) { 2520 if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
2543 // We don't check the return value: madvise(MADV_HUGEPAGE) may not 2521 // We don't check the return value: madvise(MADV_HUGEPAGE) may not
2544 // be supported or the memory may already be backed by huge pages. 2522 // be supported or the memory may already be backed by huge pages.
2545 ::madvise(addr, bytes, MADV_HUGEPAGE); 2523 ::madvise(addr, bytes, MADV_HUGEPAGE);
2546 } 2524 }
2547 } 2525 }
2548 2526
2549 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { 2527 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
2550 commit_memory(addr, bytes, alignment_hint, false); 2528 // This method works by doing an mmap over an existing mmaping and effectively discarding
2529 // the existing pages. However it won't work for SHM-based large pages that cannot be
2530 // uncommitted at all. We don't do anything in this case to avoid creating a segment with
2531 // small pages on top of the SHM segment. This method always works for small pages, so we
2532 // allow that in any case.
2533 if (alignment_hint <= (size_t)os::vm_page_size() || !UseSHM) {
2534 commit_memory(addr, bytes, alignment_hint, false);
2535 }
2551 } 2536 }
2552 2537
2553 void os::numa_make_global(char *addr, size_t bytes) { 2538 void os::numa_make_global(char *addr, size_t bytes) {
2554 Linux::numa_interleave_memory(addr, bytes); 2539 Linux::numa_interleave_memory(addr, bytes);
2555 } 2540 }
2659 2644
2660 2645
2661 if (numa_available() != -1) { 2646 if (numa_available() != -1) {
2662 set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes")); 2647 set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes"));
2663 // Create a cpu -> node mapping 2648 // Create a cpu -> node mapping
2664 _cpu_to_node = new (ResourceObj::C_HEAP) GrowableArray<int>(0, true); 2649 _cpu_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true);
2665 rebuild_cpu_to_node_map(); 2650 rebuild_cpu_to_node_map();
2666 return true; 2651 return true;
2667 } 2652 }
2668 } 2653 }
2669 } 2654 }
2689 2674
2690 cpu_to_node()->clear(); 2675 cpu_to_node()->clear();
2691 cpu_to_node()->at_grow(cpu_num - 1); 2676 cpu_to_node()->at_grow(cpu_num - 1);
2692 size_t node_num = numa_get_groups_num(); 2677 size_t node_num = numa_get_groups_num();
2693 2678
2694 unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size); 2679 unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size, mtInternal);
2695 for (size_t i = 0; i < node_num; i++) { 2680 for (size_t i = 0; i < node_num; i++) {
2696 if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) { 2681 if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
2697 for (size_t j = 0; j < cpu_map_valid_size; j++) { 2682 for (size_t j = 0; j < cpu_map_valid_size; j++) {
2698 if (cpu_map[j] != 0) { 2683 if (cpu_map[j] != 0) {
2699 for (size_t k = 0; k < BitsPerCLong; k++) { 2684 for (size_t k = 0; k < BitsPerCLong; k++) {
2703 } 2688 }
2704 } 2689 }
2705 } 2690 }
2706 } 2691 }
2707 } 2692 }
2708 FREE_C_HEAP_ARRAY(unsigned long, cpu_map); 2693 FREE_C_HEAP_ARRAY(unsigned long, cpu_map, mtInternal);
2709 } 2694 }
2710 2695
2711 int os::Linux::get_node_by_cpu(int cpu_id) { 2696 int os::Linux::get_node_by_cpu(int cpu_id) {
2712 if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) { 2697 if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) {
2713 return cpu_to_node()->at(cpu_id); 2698 return cpu_to_node()->at(cpu_id);
2722 os::Linux::numa_available_func_t os::Linux::_numa_available; 2707 os::Linux::numa_available_func_t os::Linux::_numa_available;
2723 os::Linux::numa_tonode_memory_func_t os::Linux::_numa_tonode_memory; 2708 os::Linux::numa_tonode_memory_func_t os::Linux::_numa_tonode_memory;
2724 os::Linux::numa_interleave_memory_func_t os::Linux::_numa_interleave_memory; 2709 os::Linux::numa_interleave_memory_func_t os::Linux::_numa_interleave_memory;
2725 unsigned long* os::Linux::_numa_all_nodes; 2710 unsigned long* os::Linux::_numa_all_nodes;
2726 2711
2727 bool os::uncommit_memory(char* addr, size_t size) { 2712 bool os::pd_uncommit_memory(char* addr, size_t size) {
2728 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, 2713 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
2729 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); 2714 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
2730 return res != (uintptr_t) MAP_FAILED; 2715 return res != (uintptr_t) MAP_FAILED;
2731 } 2716 }
2732 2717
2787 // where we're going to put our guard pages, truncate the mapping at 2772 // where we're going to put our guard pages, truncate the mapping at
2788 // that point by munmap()ping it. This ensures that when we later 2773 // that point by munmap()ping it. This ensures that when we later
2789 // munmap() the guard pages we don't leave a hole in the stack 2774 // munmap() the guard pages we don't leave a hole in the stack
2790 // mapping. This only affects the main/initial thread, but guard 2775 // mapping. This only affects the main/initial thread, but guard
2791 // against future OS changes 2776 // against future OS changes
2792 bool os::create_stack_guard_pages(char* addr, size_t size) { 2777 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
2793 uintptr_t stack_extent, stack_base; 2778 uintptr_t stack_extent, stack_base;
2794 bool chk_bounds = NOT_DEBUG(os::Linux::is_initial_thread()) DEBUG_ONLY(true); 2779 bool chk_bounds = NOT_DEBUG(os::Linux::is_initial_thread()) DEBUG_ONLY(true);
2795 if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) { 2780 if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) {
2796 assert(os::Linux::is_initial_thread(), 2781 assert(os::Linux::is_initial_thread(),
2797 "growable stack in non-initial thread"); 2782 "growable stack in non-initial thread");
2860 // 2845 //
2861 static int anon_munmap(char * addr, size_t size) { 2846 static int anon_munmap(char * addr, size_t size) {
2862 return ::munmap(addr, size) == 0; 2847 return ::munmap(addr, size) == 0;
2863 } 2848 }
2864 2849
2865 char* os::reserve_memory(size_t bytes, char* requested_addr, 2850 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
2866 size_t alignment_hint) { 2851 size_t alignment_hint) {
2867 return anon_mmap(requested_addr, bytes, (requested_addr != NULL)); 2852 return anon_mmap(requested_addr, bytes, (requested_addr != NULL));
2868 } 2853 }
2869 2854
2870 bool os::release_memory(char* addr, size_t size) { 2855 bool os::pd_release_memory(char* addr, size_t size) {
2871 return anon_munmap(addr, size); 2856 return anon_munmap(addr, size);
2872 } 2857 }
2873 2858
2874 static address highest_vm_reserved_address() { 2859 static address highest_vm_reserved_address() {
2875 return _highest_vm_reserved_address; 2860 return _highest_vm_reserved_address;
3162 } 3147 }
3163 3148
3164 // Reserve memory at an arbitrary address, only if that area is 3149 // Reserve memory at an arbitrary address, only if that area is
3165 // available (and not reserved for something else). 3150 // available (and not reserved for something else).
3166 3151
3167 char* os::attempt_reserve_memory_at(size_t bytes, char* requested_addr) { 3152 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
3168 const int max_tries = 10; 3153 const int max_tries = 10;
3169 char* base[max_tries]; 3154 char* base[max_tries];
3170 size_t size[max_tries]; 3155 size_t size[max_tries];
3171 const size_t gap = 0x000000; 3156 const size_t gap = 0x000000;
3172 3157
4691 // is expected to return 0 on failure and 1 on success to the jdk. 4676 // is expected to return 0 on failure and 1 on success to the jdk.
4692 return (ret < 0) ? 0 : 1; 4677 return (ret < 0) ? 0 : 1;
4693 } 4678 }
4694 4679
4695 // Map a block of memory. 4680 // Map a block of memory.
4696 char* os::map_memory(int fd, const char* file_name, size_t file_offset, 4681 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
4697 char *addr, size_t bytes, bool read_only, 4682 char *addr, size_t bytes, bool read_only,
4698 bool allow_exec) { 4683 bool allow_exec) {
4699 int prot; 4684 int prot;
4700 int flags; 4685 int flags = MAP_PRIVATE;
4701 4686
4702 if (read_only) { 4687 if (read_only) {
4703 prot = PROT_READ; 4688 prot = PROT_READ;
4704 flags = MAP_SHARED;
4705 } else { 4689 } else {
4706 prot = PROT_READ | PROT_WRITE; 4690 prot = PROT_READ | PROT_WRITE;
4707 flags = MAP_PRIVATE;
4708 } 4691 }
4709 4692
4710 if (allow_exec) { 4693 if (allow_exec) {
4711 prot |= PROT_EXEC; 4694 prot |= PROT_EXEC;
4712 } 4695 }
4723 return mapped_address; 4706 return mapped_address;
4724 } 4707 }
4725 4708
4726 4709
4727 // Remap a block of memory. 4710 // Remap a block of memory.
4728 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, 4711 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
4729 char *addr, size_t bytes, bool read_only, 4712 char *addr, size_t bytes, bool read_only,
4730 bool allow_exec) { 4713 bool allow_exec) {
4731 // same as map_memory() on this OS 4714 // same as map_memory() on this OS
4732 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only, 4715 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
4733 allow_exec); 4716 allow_exec);
4734 } 4717 }
4735 4718
4736 4719
4737 // Unmap a block of memory. 4720 // Unmap a block of memory.
4738 bool os::unmap_memory(char* addr, size_t bytes) { 4721 bool os::pd_unmap_memory(char* addr, size_t bytes) {
4739 return munmap(addr, bytes) == 0; 4722 return munmap(addr, bytes) == 0;
4740 } 4723 }
4741 4724
4742 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time); 4725 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
4743 4726
5469 if (::stat(libmawtpath, &statbuf) == 0) return false; 5452 if (::stat(libmawtpath, &statbuf) == 0) return false;
5470 5453
5471 return true; 5454 return true;
5472 } 5455 }
5473 5456
5457 // Get the default path to the core file
5458 // Returns the length of the string
5459 int os::get_core_path(char* buffer, size_t bufferSize) {
5460 const char* p = get_current_directory(buffer, bufferSize);
5461
5462 if (p == NULL) {
5463 assert(p != NULL, "failed to get current directory");
5464 return 0;
5465 }
5466
5467 return strlen(buffer);
5468 }
5474 5469
5475 #ifdef JAVASE_EMBEDDED 5470 #ifdef JAVASE_EMBEDDED
5476 // 5471 //
5477 // A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory. 5472 // A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory.
5478 // 5473 //