< prev index next >

src/hotspot/share/memory/virtualspace.cpp

Print this page




 175       }
 176     }
 177   }
 178 
 179   if (base == NULL) {
 180     // Optimistically assume that the OSes returns an aligned base pointer.
 181     // When reserving a large address range, most OSes seem to align to at
 182     // least 64K.
 183 
 184     // If the memory was requested at a particular address, use
 185     // os::attempt_reserve_memory_at() to avoid over mapping something
 186     // important.  If available space is not detected, return NULL.
 187 
 188     if (requested_address != 0) {
 189       base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap);
 190       if (failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
 191         // OS ignored requested address. Try different address.
 192         base = NULL;
 193       }
 194     } else {
 195       base = os::reserve_memory(size, NULL, alignment, _fd_for_heap);
 196     }
 197 
 198     if (base == NULL) return;
 199 
 200     // Check alignment constraints
 201     if ((((size_t)base) & (alignment - 1)) != 0) {
 202       // Base not aligned, retry
 203       unmap_or_release_memory(base, size, _fd_for_heap != -1 /*is_file_mapped*/);
 204 
 205       // Make sure that size is aligned
 206       size = align_up(size, alignment);
 207       base = os::reserve_memory_aligned(size, alignment, _fd_for_heap);
 208 
 209       if (requested_address != 0 &&
 210           failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
 211         // As a result of the alignment constraints, the allocated base differs
 212         // from the requested address. Return back to the caller who can
 213         // take remedial action (like try again without a requested address).
 214         assert(_base == NULL, "should be");
 215         return;


 967     lower_needs =
 968       pointer_delta(lower_high(), aligned_lower_new_high, sizeof(char));
 969   }
 970 
 971   // Check contiguity.
 972   assert(middle_high_boundary() <= upper_high() &&
 973          upper_high() <= upper_high_boundary(),
 974          "high address must be contained within the region");
 975   assert(lower_high_boundary() <= middle_high() &&
 976          middle_high() <= middle_high_boundary(),
 977          "high address must be contained within the region");
 978   assert(low_boundary() <= lower_high() &&
 979          lower_high() <= lower_high_boundary(),
 980          "high address must be contained within the region");
 981 
 982   // Uncommit
 983   if (upper_needs > 0) {
 984     assert(middle_high_boundary() <= aligned_upper_new_high &&
 985            aligned_upper_new_high + upper_needs <= upper_high_boundary(),
 986            "must not shrink beyond region");
 987     if (!os::uncommit_memory(aligned_upper_new_high, upper_needs)) {
 988       debug_only(warning("os::uncommit_memory failed"));
 989       return;
 990     } else {
 991       _upper_high -= upper_needs;
 992     }
 993   }
 994   if (middle_needs > 0) {
 995     assert(lower_high_boundary() <= aligned_middle_new_high &&
 996            aligned_middle_new_high + middle_needs <= middle_high_boundary(),
 997            "must not shrink beyond region");
 998     if (!os::uncommit_memory(aligned_middle_new_high, middle_needs)) {
 999       debug_only(warning("os::uncommit_memory failed"));
1000       return;
1001     } else {
1002       _middle_high -= middle_needs;
1003     }
1004   }
1005   if (lower_needs > 0) {
1006     assert(low_boundary() <= aligned_lower_new_high &&
1007            aligned_lower_new_high + lower_needs <= lower_high_boundary(),
1008            "must not shrink beyond region");
1009     if (!os::uncommit_memory(aligned_lower_new_high, lower_needs)) {
1010       debug_only(warning("os::uncommit_memory failed"));
1011       return;
1012     } else {
1013       _lower_high -= lower_needs;
1014     }
1015   }
1016 
1017   _high -= size;
1018 }
1019 
1020 #ifndef PRODUCT
1021 void VirtualSpace::check_for_contiguity() {
1022   // Check contiguity.
1023   assert(low_boundary() <= lower_high() &&
1024          lower_high() <= lower_high_boundary(),
1025          "high address must be contained within the region");
1026   assert(lower_high_boundary() <= middle_high() &&
1027          middle_high() <= middle_high_boundary(),
1028          "high address must be contained within the region");
1029   assert(middle_high_boundary() <= upper_high() &&




 175       }
 176     }
 177   }
 178 
 179   if (base == NULL) {
 180     // Optimistically assume that the OSes returns an aligned base pointer.
 181     // When reserving a large address range, most OSes seem to align to at
 182     // least 64K.
 183 
 184     // If the memory was requested at a particular address, use
 185     // os::attempt_reserve_memory_at() to avoid over mapping something
 186     // important.  If available space is not detected, return NULL.
 187 
 188     if (requested_address != 0) {
 189       base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap);
 190       if (failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
 191         // OS ignored requested address. Try different address.
 192         base = NULL;
 193       }
 194     } else {
 195       base = os::reserve_memory(size, NULL, alignment, _fd_for_heap, _executable);
 196     }
 197 
 198     if (base == NULL) return;
 199 
 200     // Check alignment constraints
 201     if ((((size_t)base) & (alignment - 1)) != 0) {
 202       // Base not aligned, retry
 203       unmap_or_release_memory(base, size, _fd_for_heap != -1 /*is_file_mapped*/);
 204 
 205       // Make sure that size is aligned
 206       size = align_up(size, alignment);
 207       base = os::reserve_memory_aligned(size, alignment, _fd_for_heap);
 208 
 209       if (requested_address != 0 &&
 210           failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) {
 211         // As a result of the alignment constraints, the allocated base differs
 212         // from the requested address. Return back to the caller who can
 213         // take remedial action (like try again without a requested address).
 214         assert(_base == NULL, "should be");
 215         return;


 967     lower_needs =
 968       pointer_delta(lower_high(), aligned_lower_new_high, sizeof(char));
 969   }
 970 
 971   // Check contiguity.
 972   assert(middle_high_boundary() <= upper_high() &&
 973          upper_high() <= upper_high_boundary(),
 974          "high address must be contained within the region");
 975   assert(lower_high_boundary() <= middle_high() &&
 976          middle_high() <= middle_high_boundary(),
 977          "high address must be contained within the region");
 978   assert(low_boundary() <= lower_high() &&
 979          lower_high() <= lower_high_boundary(),
 980          "high address must be contained within the region");
 981 
 982   // Uncommit
 983   if (upper_needs > 0) {
 984     assert(middle_high_boundary() <= aligned_upper_new_high &&
 985            aligned_upper_new_high + upper_needs <= upper_high_boundary(),
 986            "must not shrink beyond region");
 987     if (!os::uncommit_memory(aligned_upper_new_high, upper_needs, _executable)) {
 988       debug_only(warning("os::uncommit_memory failed"));
 989       return;
 990     } else {
 991       _upper_high -= upper_needs;
 992     }
 993   }
 994   if (middle_needs > 0) {
 995     assert(lower_high_boundary() <= aligned_middle_new_high &&
 996            aligned_middle_new_high + middle_needs <= middle_high_boundary(),
 997            "must not shrink beyond region");
 998     if (!os::uncommit_memory(aligned_middle_new_high, middle_needs, _executable)) {
 999       debug_only(warning("os::uncommit_memory failed"));
1000       return;
1001     } else {
1002       _middle_high -= middle_needs;
1003     }
1004   }
1005   if (lower_needs > 0) {
1006     assert(low_boundary() <= aligned_lower_new_high &&
1007            aligned_lower_new_high + lower_needs <= lower_high_boundary(),
1008            "must not shrink beyond region");
1009     if (!os::uncommit_memory(aligned_lower_new_high, lower_needs, _executable)) {
1010       debug_only(warning("os::uncommit_memory failed"));
1011       return;
1012     } else {
1013       _lower_high -= lower_needs;
1014     }
1015   }
1016 
1017   _high -= size;
1018 }
1019 
1020 #ifndef PRODUCT
1021 void VirtualSpace::check_for_contiguity() {
1022   // Check contiguity.
1023   assert(low_boundary() <= lower_high() &&
1024          lower_high() <= lower_high_boundary(),
1025          "high address must be contained within the region");
1026   assert(lower_high_boundary() <= middle_high() &&
1027          middle_high() <= middle_high_boundary(),
1028          "high address must be contained within the region");
1029   assert(middle_high_boundary() <= upper_high() &&


< prev index next >