comparison src/os/solaris/vm/os_solaris.cpp @ 60:8d84e28e68ba

6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file Summary: os::attempt_reserve_memory_at() now passes an address hint to mmap Reviewed-by: kamg, dice
author sbohne
date Fri, 14 Mar 2008 10:43:02 -0400
parents a61af66fc99e
children 5a76ab815e34
comparison
equal deleted inserted replaced
59:887682771f69 60:8d84e28e68ba
2783 return NULL; 2783 return NULL;
2784 } 2784 }
2785 return b; 2785 return b;
2786 } 2786 }
2787 2787
2788 char* 2788 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed) {
2789 os::reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) { 2789 char* addr = requested_addr;
2790 char* addr = NULL; 2790 int flags = MAP_PRIVATE | MAP_NORESERVE;
2791 int flags; 2791
2792 2792 assert(!(fixed && (alignment_hint > 0)), "alignment hint meaningless with fixed mmap");
2793 flags = MAP_PRIVATE | MAP_NORESERVE; 2793
2794 if (requested_addr != NULL) { 2794 if (fixed) {
2795 flags |= MAP_FIXED; 2795 flags |= MAP_FIXED;
2796 addr = requested_addr; 2796 } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
2797 } else if (has_map_align && alignment_hint > (size_t) vm_page_size()) {
2798 flags |= MAP_ALIGN; 2797 flags |= MAP_ALIGN;
2799 addr = (char*) alignment_hint; 2798 addr = (char*) alignment_hint;
2800 } 2799 }
2801 2800
2802 // Map uncommitted pages PROT_NONE so we fail early if we touch an 2801 // Map uncommitted pages PROT_NONE so we fail early if we touch an
2803 // uncommitted page. Otherwise, the read/write might succeed if we 2802 // uncommitted page. Otherwise, the read/write might succeed if we
2804 // have enough swap space to back the physical page. 2803 // have enough swap space to back the physical page.
2805 addr = Solaris::mmap_chunk(addr, bytes, flags, PROT_NONE); 2804 return mmap_chunk(addr, bytes, flags, PROT_NONE);
2805 }
2806
2807 char* os::reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) {
2808 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL));
2806 2809
2807 guarantee(requested_addr == NULL || requested_addr == addr, 2810 guarantee(requested_addr == NULL || requested_addr == addr,
2808 "OS failed to return requested mmap address."); 2811 "OS failed to return requested mmap address.");
2809
2810 return addr; 2812 return addr;
2811 } 2813 }
2812 2814
2813 // Reserve memory at an arbitrary address, only if that area is 2815 // Reserve memory at an arbitrary address, only if that area is
2814 // available (and not reserved for something else). 2816 // available (and not reserved for something else).
2830 // about at this low abstraction level. If we need higher alignment, 2832 // about at this low abstraction level. If we need higher alignment,
2831 // we can either pass an alignment to this method or verify alignment 2833 // we can either pass an alignment to this method or verify alignment
2832 // in one of the methods further up the call chain. See bug 5044738. 2834 // in one of the methods further up the call chain. See bug 5044738.
2833 assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block"); 2835 assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block");
2834 2836
2837 // Since snv_84, Solaris attempts to honor the address hint - see 5003415.
2838 // Give it a try, if the kernel honors the hint we can return immediately.
2839 char* addr = Solaris::anon_mmap(requested_addr, bytes, 0, false);
2840 volatile int err = errno;
2841 if (addr == requested_addr) {
2842 return addr;
2843 } else if (addr != NULL) {
2844 unmap_memory(addr, bytes);
2845 }
2846
2847 if (PrintMiscellaneous && Verbose) {
2848 char buf[256];
2849 buf[0] = '\0';
2850 if (addr == NULL) {
2851 jio_snprintf(buf, sizeof(buf), ": %s", strerror(err));
2852 }
2853 warning("attempt_reserve_memory_at: couldn't reserve %d bytes at "
2854 PTR_FORMAT ": reserve_memory_helper returned " PTR_FORMAT
2855 "%s", bytes, requested_addr, addr, buf);
2856 }
2857
2858 // Address hint method didn't work. Fall back to the old method.
2859 // In theory, once SNV becomes our oldest supported platform, this
2860 // code will no longer be needed.
2861 //
2835 // Repeatedly allocate blocks until the block is allocated at the 2862 // Repeatedly allocate blocks until the block is allocated at the
2836 // right spot. Give up after max_tries. 2863 // right spot. Give up after max_tries.
2837 int i; 2864 int i;
2838 for (i = 0; i < max_tries; ++i) { 2865 for (i = 0; i < max_tries; ++i) {
2839 base[i] = reserve_memory(bytes); 2866 base[i] = reserve_memory(bytes);