2902 |
2902 |
2903 cleanup_after_large_page_init(); |
2903 cleanup_after_large_page_init(); |
2904 UseLargePages = success; |
2904 UseLargePages = success; |
2905 } |
2905 } |
2906 |
2906 |
|
2907 int os::create_file_for_heap(const char* dir) { |
|
2908 |
|
2909 const char name_template[] = "/jvmheap.XXXXXX"; |
|
2910 char *fullname = (char*)os::malloc((strlen(dir) + strlen(name_template) + 1), mtInternal); |
|
2911 if (fullname == NULL) { |
|
2912 vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno))); |
|
2913 return -1; |
|
2914 } |
|
2915 |
|
2916 (void)strncpy(fullname, dir, strlen(dir)+1); |
|
2917 (void)strncat(fullname, name_template, strlen(name_template)); |
|
2918 |
|
2919 os::native_path(fullname); |
|
2920 |
|
2921 char *path = _mktemp(fullname); |
|
2922 if (path == NULL) { |
|
2923 warning("_mktemp could not create file name from template %s (%s)", fullname, os::strerror(errno)); |
|
2924 os::free(fullname); |
|
2925 return -1; |
|
2926 } |
|
2927 |
|
2928 int fd = _open(path, O_RDWR | O_CREAT | O_TEMPORARY | O_EXCL, S_IWRITE | S_IREAD); |
|
2929 |
|
2930 os::free(fullname); |
|
2931 if (fd < 0) { |
|
2932 warning("Problem opening file for heap (%s)", os::strerror(errno)); |
|
2933 return -1; |
|
2934 } |
|
2935 return fd; |
|
2936 } |
|
2937 |
|
2938 // If 'base' is not NULL, function will return NULL if it cannot get 'base' |
|
2939 char* os::map_memory_to_file(char* base, size_t size, int fd) { |
|
2940 assert(fd != -1, "File descriptor is not valid"); |
|
2941 |
|
2942 HANDLE fh = (HANDLE)_get_osfhandle(fd); |
|
2943 #ifdef _LP64 |
|
2944 HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE, |
|
2945 (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL); |
|
2946 #else |
|
2947 HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE, |
|
2948 0, (DWORD)size, NULL); |
|
2949 #endif |
|
2950 if (fileMapping == NULL) { |
|
2951 if (GetLastError() == ERROR_DISK_FULL) { |
|
2952 vm_exit_during_initialization(err_msg("Could not allocate sufficient disk space for Java heap")); |
|
2953 } |
|
2954 else { |
|
2955 vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); |
|
2956 } |
|
2957 |
|
2958 return NULL; |
|
2959 } |
|
2960 |
|
2961 LPVOID addr = MapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base); |
|
2962 |
|
2963 CloseHandle(fileMapping); |
|
2964 |
|
2965 return (char*)addr; |
|
2966 } |
|
2967 |
|
2968 char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, int fd) { |
|
2969 assert(fd != -1, "File descriptor is not valid"); |
|
2970 assert(base != NULL, "Base address cannot be NULL"); |
|
2971 |
|
2972 release_memory(base, size); |
|
2973 return map_memory_to_file(base, size, fd); |
|
2974 } |
|
2975 |
2907 // On win32, one cannot release just a part of reserved memory, it's an |
2976 // On win32, one cannot release just a part of reserved memory, it's an |
2908 // all or nothing deal. When we split a reservation, we must break the |
2977 // all or nothing deal. When we split a reservation, we must break the |
2909 // reservation into two reservations. |
2978 // reservation into two reservations. |
2910 void os::pd_split_reserved_memory(char *base, size_t size, size_t split, |
2979 void os::pd_split_reserved_memory(char *base, size_t size, size_t split, |
2911 bool realloc) { |
2980 bool realloc) { |
2921 } |
2990 } |
2922 |
2991 |
2923 // Multiple threads can race in this code but it's not possible to unmap small sections of |
2992 // Multiple threads can race in this code but it's not possible to unmap small sections of |
2924 // virtual space to get requested alignment, like posix-like os's. |
2993 // virtual space to get requested alignment, like posix-like os's. |
2925 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe. |
2994 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe. |
2926 char* os::reserve_memory_aligned(size_t size, size_t alignment) { |
2995 char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { |
2927 assert((alignment & (os::vm_allocation_granularity() - 1)) == 0, |
2996 assert((alignment & (os::vm_allocation_granularity() - 1)) == 0, |
2928 "Alignment must be a multiple of allocation granularity (page size)"); |
2997 "Alignment must be a multiple of allocation granularity (page size)"); |
2929 assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned"); |
2998 assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned"); |
2930 |
2999 |
2931 size_t extra_size = size + alignment; |
3000 size_t extra_size = size + alignment; |
2932 assert(extra_size >= size, "overflow, size is too large to allow alignment"); |
3001 assert(extra_size >= size, "overflow, size is too large to allow alignment"); |
2933 |
3002 |
2934 char* aligned_base = NULL; |
3003 char* aligned_base = NULL; |
2935 |
3004 |
2936 do { |
3005 do { |
2937 char* extra_base = os::reserve_memory(extra_size, NULL, alignment); |
3006 char* extra_base = os::reserve_memory(extra_size, NULL, alignment, file_desc); |
2938 if (extra_base == NULL) { |
3007 if (extra_base == NULL) { |
2939 return NULL; |
3008 return NULL; |
2940 } |
3009 } |
2941 // Do manual alignment |
3010 // Do manual alignment |
2942 aligned_base = align_up(extra_base, alignment); |
3011 aligned_base = align_up(extra_base, alignment); |
2943 |
3012 |
2944 os::release_memory(extra_base, extra_size); |
3013 if (file_desc != -1) { |
2945 |
3014 os::unmap_memory(extra_base, extra_size); |
2946 aligned_base = os::reserve_memory(size, aligned_base); |
3015 } else { |
|
3016 os::release_memory(extra_base, extra_size); |
|
3017 } |
|
3018 |
|
3019 aligned_base = os::reserve_memory(size, aligned_base, 0, file_desc); |
2947 |
3020 |
2948 } while (aligned_base == NULL); |
3021 } while (aligned_base == NULL); |
2949 |
3022 |
2950 return aligned_base; |
3023 return aligned_base; |
2951 } |
3024 } |
2985 // available (and not reserved for something else). |
3058 // available (and not reserved for something else). |
2986 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
3059 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
2987 // Windows os::reserve_memory() fails of the requested address range is |
3060 // Windows os::reserve_memory() fails of the requested address range is |
2988 // not avilable. |
3061 // not avilable. |
2989 return reserve_memory(bytes, requested_addr); |
3062 return reserve_memory(bytes, requested_addr); |
|
3063 } |
|
3064 |
|
3065 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { |
|
3066 assert(file_desc >= 0, "file_desc is not valid"); |
|
3067 return map_memory_to_file(requested_addr, bytes, file_desc); |
2990 } |
3068 } |
2991 |
3069 |
2992 size_t os::large_page_size() { |
3070 size_t os::large_page_size() { |
2993 return _large_page_size; |
3071 return _large_page_size; |
2994 } |
3072 } |