40 # include "os_aix.inline.hpp" 41 #endif 42 #ifdef TARGET_OS_FAMILY_bsd 43 # include "os_bsd.inline.hpp" 44 #endif 45 #include "utilities/bitMap.inline.hpp" 46 47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) : 48 _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false), 49 _dirty(), _executable(false) { 50 initialize_with_page_size(rs, used_size, page_size); 51 } 52 53 void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) { 54 guarantee(rs.is_reserved(), "Given reserved space must have been reserved already."); 55 56 vmassert(_low_boundary == NULL, "VirtualSpace already initialized"); 57 vmassert(page_size > 0, "Page size must be non-zero."); 58 59 guarantee(is_ptr_aligned(rs.base(), page_size), 60 err_msg("Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size)); 61 guarantee(is_size_aligned(used_size, os::vm_page_size()), 62 err_msg("Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size)); 63 guarantee(used_size <= rs.size(), 64 err_msg("Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size())); 65 guarantee(is_size_aligned(rs.size(), page_size), 66 err_msg("Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size)); 67 68 _low_boundary = rs.base(); 69 _high_boundary = _low_boundary + used_size; 70 71 _special = rs.special(); 72 _executable = rs.executable(); 73 74 _page_size = page_size; 75 76 vmassert(_committed.size() == 0, "virtual space initialized more than once"); 77 BitMap::idx_t size_in_pages = rs.size() / page_size; 78 _committed.resize(size_in_pages, /* in_resource_area */ false); 79 if (_special) { 80 _dirty.resize(size_in_pages, /* in_resource_area */ false); 81 } 82 83 _tail_size = used_size % _page_size; 84 } 85 86 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() { 120 size_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const { 121 return (addr - _low_boundary) / _page_size; 122 } 123 124 bool G1PageBasedVirtualSpace::is_area_committed(size_t start_page, size_t size_in_pages) const { 125 size_t end_page = start_page + size_in_pages; 126 return _committed.get_next_zero_offset(start_page, end_page) >= end_page; 127 } 128 129 bool G1PageBasedVirtualSpace::is_area_uncommitted(size_t start_page, size_t size_in_pages) const { 130 size_t end_page = start_page + size_in_pages; 131 return _committed.get_next_one_offset(start_page, end_page) >= end_page; 132 } 133 134 char* G1PageBasedVirtualSpace::page_start(size_t index) const { 135 return _low_boundary + index * _page_size; 136 } 137 138 bool G1PageBasedVirtualSpace::is_after_last_page(size_t index) const { 139 guarantee(index <= _committed.size(), 140 err_msg("Given boundary page " SIZE_FORMAT " is beyond managed page count " SIZE_FORMAT, index, _committed.size())); 141 return index == _committed.size(); 142 } 143 144 void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) { 145 vmassert(num_pages > 0, "No full pages to commit"); 146 vmassert(start + num_pages <= _committed.size(), 147 err_msg("Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " " 148 "that is outside of managed space of " SIZE_FORMAT " pages", 149 start, start + num_pages, _committed.size())); 150 151 char* start_addr = page_start(start); 152 size_t size = num_pages * _page_size; 153 154 os::commit_memory_or_exit(start_addr, size, _page_size, _executable, 155 err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".", 156 p2i(start_addr), p2i(start_addr + size), size)); 157 } 158 159 void G1PageBasedVirtualSpace::commit_tail() { 160 vmassert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here"); 161 162 char* const aligned_end_address = (char*)align_ptr_down(_high_boundary, _page_size); 163 os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable, 164 err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".", 165 p2i(aligned_end_address), p2i(_high_boundary), _tail_size)); 166 } 167 168 void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) { 169 guarantee(start_page < end_page, 170 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page)); 171 guarantee(end_page <= _committed.size(), 172 err_msg("Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size())); 173 174 size_t pages = end_page - start_page; 175 bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial(); 176 177 // If we have to commit some (partial) tail area, decrease the amount of pages to avoid 178 // committing that in the full-page commit code. 179 if (need_to_commit_tail) { 180 pages--; 181 } 182 183 if (pages > 0) { 184 commit_preferred_pages(start_page, pages); 185 } 186 187 if (need_to_commit_tail) { 188 commit_tail(); 189 } 190 } 191 192 char* G1PageBasedVirtualSpace::bounded_end_addr(size_t end_page) const { 193 return MIN2(_high_boundary, page_start(end_page)); 194 } 195 196 void G1PageBasedVirtualSpace::pretouch_internal(size_t start_page, size_t end_page) { 197 guarantee(start_page < end_page, 198 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page)); 199 200 os::pretouch_memory(page_start(start_page), bounded_end_addr(end_page)); 201 } 202 203 bool G1PageBasedVirtualSpace::commit(size_t start_page, size_t size_in_pages) { 204 // We need to make sure to commit all pages covered by the given area. 205 guarantee(is_area_uncommitted(start_page, size_in_pages), "Specified area is not uncommitted"); 206 207 bool zero_filled = true; 208 size_t end_page = start_page + size_in_pages; 209 210 if (_special) { 211 // Check for dirty pages and update zero_filled if any found. 212 if (_dirty.get_next_one_offset(start_page, end_page) < end_page) { 213 zero_filled = false; 214 _dirty.clear_range(start_page, end_page); 215 } 216 } else { 217 commit_internal(start_page, end_page); 218 } 219 _committed.set_range(start_page, end_page); 220 221 if (AlwaysPreTouch) { 222 pretouch_internal(start_page, end_page); 223 } 224 return zero_filled; 225 } 226 227 void G1PageBasedVirtualSpace::uncommit_internal(size_t start_page, size_t end_page) { 228 guarantee(start_page < end_page, 229 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page)); 230 231 char* start_addr = page_start(start_page); 232 os::uncommit_memory(start_addr, pointer_delta(bounded_end_addr(end_page), start_addr, sizeof(char))); 233 } 234 235 void G1PageBasedVirtualSpace::uncommit(size_t start_page, size_t size_in_pages) { 236 guarantee(is_area_committed(start_page, size_in_pages), "checking"); 237 238 size_t end_page = start_page + size_in_pages; 239 if (_special) { 240 // Mark that memory is dirty. If committed again the memory might 241 // need to be cleared explicitly. 242 _dirty.set_range(start_page, end_page); 243 } else { 244 uncommit_internal(start_page, end_page); 245 } 246 247 _committed.clear_range(start_page, end_page); 248 } 249 | 40 # include "os_aix.inline.hpp" 41 #endif 42 #ifdef TARGET_OS_FAMILY_bsd 43 # include "os_bsd.inline.hpp" 44 #endif 45 #include "utilities/bitMap.inline.hpp" 46 47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) : 48 _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false), 49 _dirty(), _executable(false) { 50 initialize_with_page_size(rs, used_size, page_size); 51 } 52 53 void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) { 54 guarantee(rs.is_reserved(), "Given reserved space must have been reserved already."); 55 56 vmassert(_low_boundary == NULL, "VirtualSpace already initialized"); 57 vmassert(page_size > 0, "Page size must be non-zero."); 58 59 guarantee(is_ptr_aligned(rs.base(), page_size), 60 "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size); 61 guarantee(is_size_aligned(used_size, os::vm_page_size()), 62 "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size); 63 guarantee(used_size <= rs.size(), 64 "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size()); 65 guarantee(is_size_aligned(rs.size(), page_size), 66 "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size); 67 68 _low_boundary = rs.base(); 69 _high_boundary = _low_boundary + used_size; 70 71 _special = rs.special(); 72 _executable = rs.executable(); 73 74 _page_size = page_size; 75 76 vmassert(_committed.size() == 0, "virtual space initialized more than once"); 77 BitMap::idx_t size_in_pages = rs.size() / page_size; 78 _committed.resize(size_in_pages, /* in_resource_area */ false); 79 if (_special) { 80 _dirty.resize(size_in_pages, /* in_resource_area */ false); 81 } 82 83 _tail_size = used_size % _page_size; 84 } 85 86 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() { 120 size_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const { 121 return (addr - _low_boundary) / _page_size; 122 } 123 124 bool G1PageBasedVirtualSpace::is_area_committed(size_t start_page, size_t size_in_pages) const { 125 size_t end_page = start_page + size_in_pages; 126 return _committed.get_next_zero_offset(start_page, end_page) >= end_page; 127 } 128 129 bool G1PageBasedVirtualSpace::is_area_uncommitted(size_t start_page, size_t size_in_pages) const { 130 size_t end_page = start_page + size_in_pages; 131 return _committed.get_next_one_offset(start_page, end_page) >= end_page; 132 } 133 134 char* G1PageBasedVirtualSpace::page_start(size_t index) const { 135 return _low_boundary + index * _page_size; 136 } 137 138 bool G1PageBasedVirtualSpace::is_after_last_page(size_t index) const { 139 guarantee(index <= _committed.size(), 140 "Given boundary page " SIZE_FORMAT " is beyond managed page count " SIZE_FORMAT, index, _committed.size()); 141 return index == _committed.size(); 142 } 143 144 void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) { 145 vmassert(num_pages > 0, "No full pages to commit"); 146 vmassert(start + num_pages <= _committed.size(), 147 "Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " " 148 "that is outside of managed space of " SIZE_FORMAT " pages", 149 start, start + num_pages, _committed.size()); 150 151 char* start_addr = page_start(start); 152 size_t size = num_pages * _page_size; 153 154 os::commit_memory_or_exit(start_addr, size, _page_size, _executable, 155 err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".", 156 p2i(start_addr), p2i(start_addr + size), size)); 157 } 158 159 void G1PageBasedVirtualSpace::commit_tail() { 160 vmassert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here"); 161 162 char* const aligned_end_address = (char*)align_ptr_down(_high_boundary, _page_size); 163 os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable, 164 err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".", 165 p2i(aligned_end_address), p2i(_high_boundary), _tail_size)); 166 } 167 168 void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) { 169 guarantee(start_page < end_page, 170 "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page); 171 guarantee(end_page <= _committed.size(), 172 "Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size()); 173 174 size_t pages = end_page - start_page; 175 bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial(); 176 177 // If we have to commit some (partial) tail area, decrease the amount of pages to avoid 178 // committing that in the full-page commit code. 179 if (need_to_commit_tail) { 180 pages--; 181 } 182 183 if (pages > 0) { 184 commit_preferred_pages(start_page, pages); 185 } 186 187 if (need_to_commit_tail) { 188 commit_tail(); 189 } 190 } 191 192 char* G1PageBasedVirtualSpace::bounded_end_addr(size_t end_page) const { 193 return MIN2(_high_boundary, page_start(end_page)); 194 } 195 196 void G1PageBasedVirtualSpace::pretouch_internal(size_t start_page, size_t end_page) { 197 guarantee(start_page < end_page, 198 "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page); 199 200 os::pretouch_memory(page_start(start_page), bounded_end_addr(end_page)); 201 } 202 203 bool G1PageBasedVirtualSpace::commit(size_t start_page, size_t size_in_pages) { 204 // We need to make sure to commit all pages covered by the given area. 205 guarantee(is_area_uncommitted(start_page, size_in_pages), "Specified area is not uncommitted"); 206 207 bool zero_filled = true; 208 size_t end_page = start_page + size_in_pages; 209 210 if (_special) { 211 // Check for dirty pages and update zero_filled if any found. 212 if (_dirty.get_next_one_offset(start_page, end_page) < end_page) { 213 zero_filled = false; 214 _dirty.clear_range(start_page, end_page); 215 } 216 } else { 217 commit_internal(start_page, end_page); 218 } 219 _committed.set_range(start_page, end_page); 220 221 if (AlwaysPreTouch) { 222 pretouch_internal(start_page, end_page); 223 } 224 return zero_filled; 225 } 226 227 void G1PageBasedVirtualSpace::uncommit_internal(size_t start_page, size_t end_page) { 228 guarantee(start_page < end_page, 229 "Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page); 230 231 char* start_addr = page_start(start_page); 232 os::uncommit_memory(start_addr, pointer_delta(bounded_end_addr(end_page), start_addr, sizeof(char))); 233 } 234 235 void G1PageBasedVirtualSpace::uncommit(size_t start_page, size_t size_in_pages) { 236 guarantee(is_area_committed(start_page, size_in_pages), "checking"); 237 238 size_t end_page = start_page + size_in_pages; 239 if (_special) { 240 // Mark that memory is dirty. If committed again the memory might 241 // need to be cleared explicitly. 242 _dirty.set_range(start_page, end_page); 243 } else { 244 uncommit_internal(start_page, end_page); 245 } 246 247 _committed.clear_range(start_page, end_page); 248 } 249 |