hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
changeset 35065 b4ff0249c092
parent 35061 be6025ebffea
child 35079 edab77f91231
equal deleted inserted replaced
35063:cb24277be2e7 35065:b4ff0249c092
  5193   assert(free_list != NULL, "pre-condition");
  5193   assert(free_list != NULL, "pre-condition");
  5194   hr->clear_humongous();
  5194   hr->clear_humongous();
  5195   free_region(hr, free_list, par);
  5195   free_region(hr, free_list, par);
  5196 }
  5196 }
  5197 
  5197 
  5198 void G1CollectedHeap::remove_from_old_sets(const HeapRegionSetCount& old_regions_removed,
  5198 void G1CollectedHeap::remove_from_old_sets(const uint old_regions_removed,
  5199                                            const HeapRegionSetCount& humongous_regions_removed) {
  5199                                            const uint humongous_regions_removed) {
  5200   if (old_regions_removed.length() > 0 || humongous_regions_removed.length() > 0) {
  5200   if (old_regions_removed > 0 || humongous_regions_removed > 0) {
  5201     MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag);
  5201     MutexLockerEx x(OldSets_lock, Mutex::_no_safepoint_check_flag);
  5202     _old_set.bulk_remove(old_regions_removed);
  5202     _old_set.bulk_remove(old_regions_removed);
  5203     _humongous_set.bulk_remove(humongous_regions_removed);
  5203     _humongous_set.bulk_remove(humongous_regions_removed);
  5204   }
  5204   }
  5205 
  5205 
  5580 
  5580 
  5581 class G1FreeHumongousRegionClosure : public HeapRegionClosure {
  5581 class G1FreeHumongousRegionClosure : public HeapRegionClosure {
  5582  private:
  5582  private:
  5583   FreeRegionList* _free_region_list;
  5583   FreeRegionList* _free_region_list;
  5584   HeapRegionSet* _proxy_set;
  5584   HeapRegionSet* _proxy_set;
  5585   HeapRegionSetCount _humongous_regions_removed;
  5585   uint _humongous_regions_removed;
  5586   size_t _freed_bytes;
  5586   size_t _freed_bytes;
  5587  public:
  5587  public:
  5588 
  5588 
  5589   G1FreeHumongousRegionClosure(FreeRegionList* free_region_list) :
  5589   G1FreeHumongousRegionClosure(FreeRegionList* free_region_list) :
  5590     _free_region_list(free_region_list), _humongous_regions_removed(), _freed_bytes(0) {
  5590     _free_region_list(free_region_list), _humongous_regions_removed(0), _freed_bytes(0) {
  5591   }
  5591   }
  5592 
  5592 
  5593   virtual bool doHeapRegion(HeapRegion* r) {
  5593   virtual bool doHeapRegion(HeapRegion* r) {
  5594     if (!r->is_starts_humongous()) {
  5594     if (!r->is_starts_humongous()) {
  5595       return false;
  5595       return false;
  5665     }
  5665     }
  5666     do {
  5666     do {
  5667       HeapRegion* next = g1h->next_region_in_humongous(r);
  5667       HeapRegion* next = g1h->next_region_in_humongous(r);
  5668       _freed_bytes += r->used();
  5668       _freed_bytes += r->used();
  5669       r->set_containing_set(NULL);
  5669       r->set_containing_set(NULL);
  5670       _humongous_regions_removed.increment(1u, r->capacity());
  5670       _humongous_regions_removed++;
  5671       g1h->free_humongous_region(r, _free_region_list, false);
  5671       g1h->free_humongous_region(r, _free_region_list, false);
  5672       r = next;
  5672       r = next;
  5673     } while (r != NULL);
  5673     } while (r != NULL);
  5674 
  5674 
  5675     return false;
  5675     return false;
  5676   }
  5676   }
  5677 
  5677 
  5678   HeapRegionSetCount& humongous_free_count() {
  5678   uint humongous_free_count() {
  5679     return _humongous_regions_removed;
  5679     return _humongous_regions_removed;
  5680   }
  5680   }
  5681 
  5681 
  5682   size_t bytes_freed() const {
  5682   size_t bytes_freed() const {
  5683     return _freed_bytes;
  5683     return _freed_bytes;
  5684   }
       
  5685 
       
  5686   size_t humongous_reclaimed() const {
       
  5687     return _humongous_regions_removed.length();
       
  5688   }
  5684   }
  5689 };
  5685 };
  5690 
  5686 
  5691 void G1CollectedHeap::eagerly_reclaim_humongous_regions() {
  5687 void G1CollectedHeap::eagerly_reclaim_humongous_regions() {
  5692   assert_at_safepoint(true);
  5688   assert_at_safepoint(true);
  5702   FreeRegionList local_cleanup_list("Local Humongous Cleanup List");
  5698   FreeRegionList local_cleanup_list("Local Humongous Cleanup List");
  5703 
  5699 
  5704   G1FreeHumongousRegionClosure cl(&local_cleanup_list);
  5700   G1FreeHumongousRegionClosure cl(&local_cleanup_list);
  5705   heap_region_iterate(&cl);
  5701   heap_region_iterate(&cl);
  5706 
  5702 
  5707   HeapRegionSetCount empty_set;
  5703   remove_from_old_sets(0, cl.humongous_free_count());
  5708   remove_from_old_sets(empty_set, cl.humongous_free_count());
       
  5709 
  5704 
  5710   G1HRPrinter* hrp = hr_printer();
  5705   G1HRPrinter* hrp = hr_printer();
  5711   if (hrp->is_active()) {
  5706   if (hrp->is_active()) {
  5712     FreeRegionListIterator iter(&local_cleanup_list);
  5707     FreeRegionListIterator iter(&local_cleanup_list);
  5713     while (iter.more_available()) {
  5708     while (iter.more_available()) {
  5718 
  5713 
  5719   prepend_to_freelist(&local_cleanup_list);
  5714   prepend_to_freelist(&local_cleanup_list);
  5720   decrement_summary_bytes(cl.bytes_freed());
  5715   decrement_summary_bytes(cl.bytes_freed());
  5721 
  5716 
  5722   g1_policy()->phase_times()->record_fast_reclaim_humongous_time_ms((os::elapsedTime() - start_time) * 1000.0,
  5717   g1_policy()->phase_times()->record_fast_reclaim_humongous_time_ms((os::elapsedTime() - start_time) * 1000.0,
  5723                                                                     cl.humongous_reclaimed());
  5718                                                                     cl.humongous_free_count());
  5724 }
  5719 }
  5725 
  5720 
  5726 // This routine is similar to the above but does not record
  5721 // This routine is similar to the above but does not record
  5727 // any policy statistics or update free lists; we are abandoning
  5722 // any policy statistics or update free lists; we are abandoning
  5728 // the current incremental collection set in preparation of a
  5723 // the current incremental collection set in preparation of a
  6064   HeapRegionSet*   _old_set;
  6059   HeapRegionSet*   _old_set;
  6065   HeapRegionSet*   _humongous_set;
  6060   HeapRegionSet*   _humongous_set;
  6066   HeapRegionManager*   _hrm;
  6061   HeapRegionManager*   _hrm;
  6067 
  6062 
  6068 public:
  6063 public:
  6069   HeapRegionSetCount _old_count;
  6064   uint _old_count;
  6070   HeapRegionSetCount _humongous_count;
  6065   uint _humongous_count;
  6071   HeapRegionSetCount _free_count;
  6066   uint _free_count;
  6072 
  6067 
  6073   VerifyRegionListsClosure(HeapRegionSet* old_set,
  6068   VerifyRegionListsClosure(HeapRegionSet* old_set,
  6074                            HeapRegionSet* humongous_set,
  6069                            HeapRegionSet* humongous_set,
  6075                            HeapRegionManager* hrm) :
  6070                            HeapRegionManager* hrm) :
  6076     _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
  6071     _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
  6079   bool doHeapRegion(HeapRegion* hr) {
  6074   bool doHeapRegion(HeapRegion* hr) {
  6080     if (hr->is_young()) {
  6075     if (hr->is_young()) {
  6081       // TODO
  6076       // TODO
  6082     } else if (hr->is_humongous()) {
  6077     } else if (hr->is_humongous()) {
  6083       assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
  6078       assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
  6084       _humongous_count.increment(1u, hr->capacity());
  6079       _humongous_count++;
  6085     } else if (hr->is_empty()) {
  6080     } else if (hr->is_empty()) {
  6086       assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
  6081       assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
  6087       _free_count.increment(1u, hr->capacity());
  6082       _free_count++;
  6088     } else if (hr->is_old()) {
  6083     } else if (hr->is_old()) {
  6089       assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
  6084       assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
  6090       _old_count.increment(1u, hr->capacity());
  6085       _old_count++;
  6091     } else {
  6086     } else {
  6092       // There are no other valid region types. Check for one invalid
  6087       // There are no other valid region types. Check for one invalid
  6093       // one we can identify: pinned without old or humongous set.
  6088       // one we can identify: pinned without old or humongous set.
  6094       assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
  6089       assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
  6095       ShouldNotReachHere();
  6090       ShouldNotReachHere();
  6096     }
  6091     }
  6097     return false;
  6092     return false;
  6098   }
  6093   }
  6099 
  6094 
  6100   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
  6095   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
  6101     guarantee(old_set->length() == _old_count.length(), "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count.length());
  6096     guarantee(old_set->length() == _old_count, "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count);
  6102     guarantee(old_set->total_capacity_bytes() == _old_count.capacity(), "Old set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6097     guarantee(humongous_set->length() == _humongous_count, "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count);
  6103               old_set->total_capacity_bytes(), _old_count.capacity());
  6098     guarantee(free_list->num_free_regions() == _free_count, "Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count);
  6104 
       
  6105     guarantee(humongous_set->length() == _humongous_count.length(), "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count.length());
       
  6106     guarantee(humongous_set->total_capacity_bytes() == _humongous_count.capacity(), "Hum set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
       
  6107               humongous_set->total_capacity_bytes(), _humongous_count.capacity());
       
  6108 
       
  6109     guarantee(free_list->num_free_regions() == _free_count.length(), "Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count.length());
       
  6110     guarantee(free_list->total_capacity_bytes() == _free_count.capacity(), "Free list capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
       
  6111               free_list->total_capacity_bytes(), _free_count.capacity());
       
  6112   }
  6099   }
  6113 };
  6100 };
  6114 
  6101 
  6115 void G1CollectedHeap::verify_region_sets() {
  6102 void G1CollectedHeap::verify_region_sets() {
  6116   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
  6103   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);