src/os/windows/vm/os_windows.cpp

Print this page
rev 4525 : 8014611: reserve_and_align() assumptions are invalid on windows
Summary: also reviewed by ron.durbin@oracle.com, thomas.schatzl@oracle.com
Reviewed-by: dcubed, brutisso


2954   cleanup_after_large_page_init();
2955   UseLargePages = success;
2956 }
2957 
2958 // On win32, one cannot release just a part of reserved memory, it's an
2959 // all or nothing deal.  When we split a reservation, we must break the
2960 // reservation into two reservations.
2961 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
2962                               bool realloc) {
2963   if (size > 0) {
2964     release_memory(base, size);
2965     if (realloc) {
2966       reserve_memory(split, base);
2967     }
2968     if (size != split) {
2969       reserve_memory(size - split, base + split);
2970     }
2971   }
2972 }
2973 




2974 // Multiple threads can race in this code but it's not possible to unmap small sections of
2975 // virtual space to get requested alignment, like posix-like os's.
2976 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe.
2977 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
2978   assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
2979       "Alignment must be a multiple of allocation granularity (page size)");
2980   assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
2981 
2982   size_t extra_size = size + alignment;
2983   assert(extra_size >= size, "overflow, size is too large to allow alignment");
2984 
2985   char* aligned_base = NULL;
2986 
2987   do {
2988     char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
2989     if (extra_base == NULL) {
2990       return NULL;
2991     }
2992     // Do manual alignment
2993     aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);




2954   cleanup_after_large_page_init();
2955   UseLargePages = success;
2956 }
2957 
2958 // On win32, one cannot release just a part of reserved memory, it's an
2959 // all or nothing deal.  When we split a reservation, we must break the
2960 // reservation into two reservations.
2961 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
2962                               bool realloc) {
2963   if (size > 0) {
2964     release_memory(base, size);
2965     if (realloc) {
2966       reserve_memory(split, base);
2967     }
2968     if (size != split) {
2969       reserve_memory(size - split, base + split);
2970     }
2971   }
2972 }
2973 
2974 bool os::can_release_partial_region() {
2975   return false;
2976 }
2977 
2978 // Multiple threads can race in this code but it's not possible to unmap small sections of
2979 // virtual space to get requested alignment, like posix-like os's.
2980 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe.
2981 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
2982   assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
2983       "Alignment must be a multiple of allocation granularity (page size)");
2984   assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
2985 
2986   size_t extra_size = size + alignment;
2987   assert(extra_size >= size, "overflow, size is too large to allow alignment");
2988 
2989   char* aligned_base = NULL;
2990 
2991   do {
2992     char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
2993     if (extra_base == NULL) {
2994       return NULL;
2995     }
2996     // Do manual alignment
2997     aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);