< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




2897   os::native_path(fullname);
2898 
2899   char *path = _mktemp(fullname);
2900   if (path == NULL) {
2901     warning("_mktemp could not create file name from template %s (%s)", fullname, os::strerror(errno));
2902     os::free(fullname);
2903     return -1;
2904   }
2905 
2906   int fd = _open(path, O_RDWR | O_CREAT | O_TEMPORARY | O_EXCL, S_IWRITE | S_IREAD);
2907 
2908   os::free(fullname);
2909   if (fd < 0) {
2910         warning("Problem opening file for heap (%s)", os::strerror(errno));
2911     return -1;
2912   }
2913   return fd;
2914 }
2915 
2916 // If 'base' is not NULL, function will return NULL if it cannot get 'base'
2917 char* os::map_memory_to_dax_file(char* base, size_t size, int fd) {
2918   assert(fd != -1, "File descriptor is not valid");
2919 
2920   HANDLE fh = (HANDLE)_get_osfhandle(fd);
2921   HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE,
2922     (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL);
2923   if (fileMapping == NULL) {
2924     if (GetLastError() == ERROR_DISK_FULL) {
2925       vm_exit_during_initialization(err_msg("Could not allocate sufficient disk space for Java heap"));
2926     }
2927     else {
2928       vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
2929     }
2930 
2931     return NULL;
2932   }
2933 
2934   LPVOID addr = MapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base);
2935 
2936   CloseHandle(fileMapping);
2937 
2938   return (char*)addr;
2939 }
2940 
2941 char* os::replace_existing_mapping_with_dax_file_mapping(char* base, size_t size, int fd) {
2942   assert(fd != -1, "File descriptor is not valid");
2943   assert(base != NULL, "Base address cannot be NULL");
2944 
2945   release_memory(base, size);
2946   return map_memory_to_dax_file(base, size, fd);
2947 }
2948 
2949 // On win32, one cannot release just a part of reserved memory, it's an
2950 // all or nothing deal.  When we split a reservation, we must break the
2951 // reservation into two reservations.
2952 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
2953                                   bool realloc) {
2954   if (size > 0) {
2955     release_memory(base, size);
2956     if (realloc) {
2957       reserve_memory(split, base);
2958     }
2959     if (size != split) {
2960       reserve_memory(size - split, base + split);
2961     }
2962   }
2963 }
2964 
2965 // Multiple threads can race in this code but it's not possible to unmap small sections of
2966 // virtual space to get requested alignment, like posix-like os's.


3020       tty->print_cr("reserve_memory of %Ix bytes took " JLONG_FORMAT " ms (" JLONG_FORMAT " ticks)", bytes,
3021                     reserveTimer.milliseconds(), reserveTimer.ticks());
3022     }
3023   }
3024   assert(res == NULL || addr == NULL || addr == res,
3025          "Unexpected address from reserve.");
3026 
3027   return res;
3028 }
3029 
3030 // Reserve memory at an arbitrary address, only if that area is
3031 // available (and not reserved for something else).
3032 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
3033   // Windows os::reserve_memory() fails of the requested address range is
3034   // not avilable.
3035   return reserve_memory(bytes, requested_addr);
3036 }
3037 
3038 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) {
3039   assert(file_desc >= 0, "file_desc is not valid");
3040   return map_memory_to_dax_file(requested_addr, bytes, file_desc);
3041 }
3042 
3043 size_t os::large_page_size() {
3044   return _large_page_size;
3045 }
3046 
3047 bool os::can_commit_large_page_memory() {
3048   // Windows only uses large page memory when the entire region is reserved
3049   // and committed in a single VirtualAlloc() call. This may change in the
3050   // future, but with Windows 2003 it's not possible to commit on demand.
3051   return false;
3052 }
3053 
3054 bool os::can_execute_large_page_memory() {
3055   return true;
3056 }
3057 
3058 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
3059                                  bool exec) {
3060   assert(UseLargePages, "only for large pages");




2897   os::native_path(fullname);
2898 
2899   char *path = _mktemp(fullname);
2900   if (path == NULL) {
2901     warning("_mktemp could not create file name from template %s (%s)", fullname, os::strerror(errno));
2902     os::free(fullname);
2903     return -1;
2904   }
2905 
2906   int fd = _open(path, O_RDWR | O_CREAT | O_TEMPORARY | O_EXCL, S_IWRITE | S_IREAD);
2907 
2908   os::free(fullname);
2909   if (fd < 0) {
2910         warning("Problem opening file for heap (%s)", os::strerror(errno));
2911     return -1;
2912   }
2913   return fd;
2914 }
2915 
2916 // If 'base' is not NULL, function will return NULL if it cannot get 'base'
2917 char* os::map_memory_to_file(char* base, size_t size, int fd) {
2918   assert(fd != -1, "File descriptor is not valid");
2919 
2920   HANDLE fh = (HANDLE)_get_osfhandle(fd);
2921   HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE,
2922     (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL);
2923   if (fileMapping == NULL) {
2924     if (GetLastError() == ERROR_DISK_FULL) {
2925       vm_exit_during_initialization(err_msg("Could not allocate sufficient disk space for Java heap"));
2926     }
2927     else {
2928       vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
2929     }
2930 
2931     return NULL;
2932   }
2933 
2934   LPVOID addr = MapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base);
2935 
2936   CloseHandle(fileMapping);
2937 
2938   return (char*)addr;
2939 }
2940 
2941 char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, int fd) {
2942   assert(fd != -1, "File descriptor is not valid");
2943   assert(base != NULL, "Base address cannot be NULL");
2944 
2945   release_memory(base, size);
2946   return map_memory_to_file(base, size, fd);
2947 }
2948 
2949 // On win32, one cannot release just a part of reserved memory, it's an
2950 // all or nothing deal.  When we split a reservation, we must break the
2951 // reservation into two reservations.
2952 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
2953                                   bool realloc) {
2954   if (size > 0) {
2955     release_memory(base, size);
2956     if (realloc) {
2957       reserve_memory(split, base);
2958     }
2959     if (size != split) {
2960       reserve_memory(size - split, base + split);
2961     }
2962   }
2963 }
2964 
2965 // Multiple threads can race in this code but it's not possible to unmap small sections of
2966 // virtual space to get requested alignment, like posix-like os's.


3020       tty->print_cr("reserve_memory of %Ix bytes took " JLONG_FORMAT " ms (" JLONG_FORMAT " ticks)", bytes,
3021                     reserveTimer.milliseconds(), reserveTimer.ticks());
3022     }
3023   }
3024   assert(res == NULL || addr == NULL || addr == res,
3025          "Unexpected address from reserve.");
3026 
3027   return res;
3028 }
3029 
3030 // Reserve memory at an arbitrary address, only if that area is
3031 // available (and not reserved for something else).
3032 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
3033   // Windows os::reserve_memory() fails of the requested address range is
3034   // not avilable.
3035   return reserve_memory(bytes, requested_addr);
3036 }
3037 
3038 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) {
3039   assert(file_desc >= 0, "file_desc is not valid");
3040   return map_memory_to_file(requested_addr, bytes, file_desc);
3041 }
3042 
3043 size_t os::large_page_size() {
3044   return _large_page_size;
3045 }
3046 
3047 bool os::can_commit_large_page_memory() {
3048   // Windows only uses large page memory when the entire region is reserved
3049   // and committed in a single VirtualAlloc() call. This may change in the
3050   // future, but with Windows 2003 it's not possible to commit on demand.
3051   return false;
3052 }
3053 
3054 bool os::can_execute_large_page_memory() {
3055   return true;
3056 }
3057 
3058 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr,
3059                                  bool exec) {
3060   assert(UseLargePages, "only for large pages");


< prev index next >