< prev index next >

src/share/vm/gc/g1/heapRegionManager.cpp

Print this page
rev 8461 : imported patch webrev1.patch
rev 8462 : [mq]: version3


 261     cur++;
 262   }
 263   if (cur == max_length()) {
 264     return num_regions;
 265   }
 266   *res_idx = cur;
 267   while (cur < max_length() && !is_available(cur)) {
 268     cur++;
 269   }
 270   num_regions = cur - *res_idx;
 271 #ifdef ASSERT
 272   for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
 273     assert(!is_available(i), "just checking");
 274   }
 275   assert(cur == max_length() || num_regions == 0 || is_available(cur),
 276          err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
 277 #endif
 278   return num_regions;
 279 }
 280 
 281 uint HeapRegionManager::find_highest_available(bool* expanded) {
 282   // Loop downwards from the highest region index, looking for an
 283   // entry which is either free or not yet committed.  If not yet
 284   // committed, expand_at that index, and set the 'expanded' output
 285   // bool result to true.
 286   uint curr = max_length() - 1;
 287   while (curr != 0) {
 288     HeapRegion *hr = _regions.get_by_index(curr);
 289     if (hr == NULL) {
 290       uint res = expand_at(curr, 1);
 291       if (res == 1) {
 292         *expanded = true;
 293         return curr;
 294       }
 295     } else {
 296       if (hr->is_free()) {
 297         *expanded = false;
 298         return curr;
 299       }
 300     }



 301     curr--;
 302   }
 303   return G1_NO_HRM_INDEX;






















 304 }
 305 
 306 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer, bool concurrent) const {
 307   const uint start_index = hrclaimer->start_region_for_worker(worker_id);
 308 
 309   // Every worker will actually look at all regions, skipping over regions that
 310   // are currently not committed.
 311   // This also (potentially) iterates over regions newly allocated during GC. This
 312   // is no problem except for some extra work.
 313   const uint n_regions = hrclaimer->n_regions();
 314   for (uint count = 0; count < n_regions; count++) {
 315     const uint index = (start_index + count) % n_regions;
 316     assert(index < n_regions, "sanity");
 317     // Skip over unavailable regions
 318     if (!is_available(index)) {
 319       continue;
 320     }
 321     HeapRegion* r = _regions.get_by_index(index);
 322     // We'll ignore "continues humongous" regions (we'll process them
 323     // when we come across their corresponding "start humongous"


 444 
 445 void HeapRegionManager::verify() {
 446   guarantee(length() <= _allocated_heapregions_length,
 447             err_msg("invariant: _length: %u _allocated_length: %u",
 448                     length(), _allocated_heapregions_length));
 449   guarantee(_allocated_heapregions_length <= max_length(),
 450             err_msg("invariant: _allocated_length: %u _max_length: %u",
 451                     _allocated_heapregions_length, max_length()));
 452 
 453   bool prev_committed = true;
 454   uint num_committed = 0;
 455   HeapWord* prev_end = heap_bottom();
 456   for (uint i = 0; i < _allocated_heapregions_length; i++) {
 457     if (!is_available(i)) {
 458       prev_committed = false;
 459       continue;
 460     }
 461     num_committed++;
 462     HeapRegion* hr = _regions.get_by_index(i);
 463     guarantee(hr != NULL, err_msg("invariant: i: %u", i));
 464     guarantee(!prev_committed || hr->bottom() == prev_end || hr->is_archive(),
 465               err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,
 466                       i, HR_FORMAT_PARAMS(hr), p2i(prev_end)));
 467     guarantee(hr->hrm_index() == i,
 468               err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index()));
 469     // Asserts will fire if i is >= _length
 470     HeapWord* addr = hr->bottom();
 471     guarantee(addr_to_region(addr) == hr, "sanity");
 472     // We cannot check whether the region is part of a particular set: at the time
 473     // this method may be called, we have only completed allocation of the regions,
 474     // but not put into a region set.
 475     prev_committed = true;
 476     if (hr->is_starts_humongous()) {
 477       prev_end = hr->orig_end();
 478     } else {
 479       prev_end = hr->end();
 480     }
 481   }
 482   for (uint i = _allocated_heapregions_length; i < max_length(); i++) {
 483     guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i));
 484   }




 261     cur++;
 262   }
 263   if (cur == max_length()) {
 264     return num_regions;
 265   }
 266   *res_idx = cur;
 267   while (cur < max_length() && !is_available(cur)) {
 268     cur++;
 269   }
 270   num_regions = cur - *res_idx;
 271 #ifdef ASSERT
 272   for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
 273     assert(!is_available(i), "just checking");
 274   }
 275   assert(cur == max_length() || num_regions == 0 || is_available(cur),
 276          err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
 277 #endif
 278   return num_regions;
 279 }
 280 
 281 uint HeapRegionManager::find_highest_free(bool* expanded) {
 282   // Loop downwards from the highest region index, looking for an
 283   // entry which is either free or not yet committed.  If not yet
 284   // committed, expand_at that index.

 285   uint curr = max_length() - 1;
 286   while (true) {
 287     HeapRegion *hr = _regions.get_by_index(curr);
 288     if (hr == NULL) {
 289       uint res = expand_at(curr, 1);
 290       if (res == 1) {
 291         *expanded = true;
 292         return curr;
 293       }
 294     } else {
 295       if (hr->is_free()) {
 296         *expanded = false;
 297         return curr;
 298       }
 299     }
 300     if (curr == 0) {
 301       return G1_NO_HRM_INDEX;
 302     }
 303     curr--;
 304   }
 305 }
 306 
 307 bool HeapRegionManager::allocate_containing_regions(MemRegion range, size_t* commit_count) {
 308   size_t commits = 0;
 309   uint start_index = (uint)_regions.get_index_by_address(range.start());
 310   uint last_index = (uint)_regions.get_index_by_address(range.last());
 311 
 312   // Ensure that each G1 region in the range is free, returning false if not.                                                        
 313   // Commit those that are not yet available, and keep count.
 314   for (uint curr_index = start_index; curr_index <= last_index; curr_index++) {
 315     if (!is_available(curr_index)) {
 316       commits++;
 317       expand_at(curr_index, 1);
 318     }
 319     HeapRegion* curr_region  = _regions.get_by_index(curr_index);
 320     if (!curr_region->is_free()) {
 321       return false;
 322     }
 323   }
 324 
 325   allocate_free_regions_starting_at(start_index, (last_index - start_index) + 1);
 326   *commit_count = commits;
 327   return true;
 328 }
 329 
 330 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer, bool concurrent) const {
 331   const uint start_index = hrclaimer->start_region_for_worker(worker_id);
 332 
 333   // Every worker will actually look at all regions, skipping over regions that
 334   // are currently not committed.
 335   // This also (potentially) iterates over regions newly allocated during GC. This
 336   // is no problem except for some extra work.
 337   const uint n_regions = hrclaimer->n_regions();
 338   for (uint count = 0; count < n_regions; count++) {
 339     const uint index = (start_index + count) % n_regions;
 340     assert(index < n_regions, "sanity");
 341     // Skip over unavailable regions
 342     if (!is_available(index)) {
 343       continue;
 344     }
 345     HeapRegion* r = _regions.get_by_index(index);
 346     // We'll ignore "continues humongous" regions (we'll process them
 347     // when we come across their corresponding "start humongous"


 468 
 469 void HeapRegionManager::verify() {
 470   guarantee(length() <= _allocated_heapregions_length,
 471             err_msg("invariant: _length: %u _allocated_length: %u",
 472                     length(), _allocated_heapregions_length));
 473   guarantee(_allocated_heapregions_length <= max_length(),
 474             err_msg("invariant: _allocated_length: %u _max_length: %u",
 475                     _allocated_heapregions_length, max_length()));
 476 
 477   bool prev_committed = true;
 478   uint num_committed = 0;
 479   HeapWord* prev_end = heap_bottom();
 480   for (uint i = 0; i < _allocated_heapregions_length; i++) {
 481     if (!is_available(i)) {
 482       prev_committed = false;
 483       continue;
 484     }
 485     num_committed++;
 486     HeapRegion* hr = _regions.get_by_index(i);
 487     guarantee(hr != NULL, err_msg("invariant: i: %u", i));
 488     guarantee(!prev_committed || hr->bottom() == prev_end,
 489               err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,
 490                       i, HR_FORMAT_PARAMS(hr), p2i(prev_end)));
 491     guarantee(hr->hrm_index() == i,
 492               err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index()));
 493     // Asserts will fire if i is >= _length
 494     HeapWord* addr = hr->bottom();
 495     guarantee(addr_to_region(addr) == hr, "sanity");
 496     // We cannot check whether the region is part of a particular set: at the time
 497     // this method may be called, we have only completed allocation of the regions,
 498     // but not put into a region set.
 499     prev_committed = true;
 500     if (hr->is_starts_humongous()) {
 501       prev_end = hr->orig_end();
 502     } else {
 503       prev_end = hr->end();
 504     }
 505   }
 506   for (uint i = _allocated_heapregions_length; i < max_length(); i++) {
 507     guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i));
 508   }


< prev index next >