src/hotspot/share/gc/g1/g1HeapVerifier.cpp
changeset 51494 1906adbef2dc
parent 51332 c25572739e7c
child 52062 8dbf1a13af49
equal deleted inserted replaced
51493:6b5f3f5fd63c 51494:1906adbef2dc
   486 // Heap region set verification
   486 // Heap region set verification
   487 
   487 
   488 class VerifyRegionListsClosure : public HeapRegionClosure {
   488 class VerifyRegionListsClosure : public HeapRegionClosure {
   489 private:
   489 private:
   490   HeapRegionSet*   _old_set;
   490   HeapRegionSet*   _old_set;
       
   491   HeapRegionSet*   _archive_set;
   491   HeapRegionSet*   _humongous_set;
   492   HeapRegionSet*   _humongous_set;
   492   HeapRegionManager*   _hrm;
   493   HeapRegionManager* _hrm;
   493 
   494 
   494 public:
   495 public:
   495   uint _old_count;
   496   uint _old_count;
       
   497   uint _archive_count;
   496   uint _humongous_count;
   498   uint _humongous_count;
   497   uint _free_count;
   499   uint _free_count;
   498 
   500 
   499   VerifyRegionListsClosure(HeapRegionSet* old_set,
   501   VerifyRegionListsClosure(HeapRegionSet* old_set,
       
   502                            HeapRegionSet* archive_set,
   500                            HeapRegionSet* humongous_set,
   503                            HeapRegionSet* humongous_set,
   501                            HeapRegionManager* hrm) :
   504                            HeapRegionManager* hrm) :
   502     _old_set(old_set), _humongous_set(humongous_set), _hrm(hrm),
   505     _old_set(old_set), _archive_set(archive_set), _humongous_set(humongous_set), _hrm(hrm),
   503     _old_count(), _humongous_count(), _free_count(){ }
   506     _old_count(), _archive_count(), _humongous_count(), _free_count(){ }
   504 
   507 
   505   bool do_heap_region(HeapRegion* hr) {
   508   bool do_heap_region(HeapRegion* hr) {
   506     if (hr->is_young()) {
   509     if (hr->is_young()) {
   507       // TODO
   510       // TODO
   508     } else if (hr->is_humongous()) {
   511     } else if (hr->is_humongous()) {
   509       assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
   512       assert(hr->containing_set() == _humongous_set, "Heap region %u is humongous but not in humongous set.", hr->hrm_index());
   510       _humongous_count++;
   513       _humongous_count++;
   511     } else if (hr->is_empty()) {
   514     } else if (hr->is_empty()) {
   512       assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
   515       assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
   513       _free_count++;
   516       _free_count++;
       
   517     } else if (hr->is_archive()) {
       
   518       assert(hr->containing_set() == _archive_set, "Heap region %u is archive but not in the archive set.", hr->hrm_index());
       
   519       _archive_count++;
   514     } else if (hr->is_old()) {
   520     } else if (hr->is_old()) {
   515       assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
   521       assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
   516       _old_count++;
   522       _old_count++;
   517     } else {
   523     } else {
   518       // There are no other valid region types. Check for one invalid
   524       // There are no other valid region types. Check for one invalid
   521       ShouldNotReachHere();
   527       ShouldNotReachHere();
   522     }
   528     }
   523     return false;
   529     return false;
   524   }
   530   }
   525 
   531 
   526   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
   532   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* archive_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
   527     guarantee(old_set->length() == _old_count, "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count);
   533     guarantee(old_set->length() == _old_count, "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count);
       
   534     guarantee(archive_set->length() == _archive_count, "Archive set count mismatch. Expected %u, actual %u.", archive_set->length(), _archive_count);
   528     guarantee(humongous_set->length() == _humongous_count, "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count);
   535     guarantee(humongous_set->length() == _humongous_count, "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count);
   529     guarantee(free_list->num_free_regions() == _free_count, "Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count);
   536     guarantee(free_list->num_free_regions() == _free_count, "Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count);
   530   }
   537   }
   531 };
   538 };
   532 
   539 
   537   _g1h->_hrm.verify();
   544   _g1h->_hrm.verify();
   538 
   545 
   539   // Finally, make sure that the region accounting in the lists is
   546   // Finally, make sure that the region accounting in the lists is
   540   // consistent with what we see in the heap.
   547   // consistent with what we see in the heap.
   541 
   548 
   542   VerifyRegionListsClosure cl(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
   549   VerifyRegionListsClosure cl(&_g1h->_old_set, &_g1h->_archive_set, &_g1h->_humongous_set, &_g1h->_hrm);
   543   _g1h->heap_region_iterate(&cl);
   550   _g1h->heap_region_iterate(&cl);
   544   cl.verify_counts(&_g1h->_old_set, &_g1h->_humongous_set, &_g1h->_hrm);
   551   cl.verify_counts(&_g1h->_old_set, &_g1h->_archive_set, &_g1h->_humongous_set, &_g1h->_hrm);
   545 }
   552 }
   546 
   553 
   547 void G1HeapVerifier::prepare_for_verify() {
   554 void G1HeapVerifier::prepare_for_verify() {
   548   if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
   555   if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
   549     _g1h->ensure_parsability(false);
   556     _g1h->ensure_parsability(false);
   753                              hr->in_collection_set(), cset_state.value(), i);
   760                              hr->in_collection_set(), cset_state.value(), i);
   754         _failures = true;
   761         _failures = true;
   755         return true;
   762         return true;
   756       }
   763       }
   757       if (cset_state.is_in_cset()) {
   764       if (cset_state.is_in_cset()) {
       
   765         if (hr->is_archive()) {
       
   766           log_error(gc, verify)("## is_archive in collection set for region %u", i);
       
   767           _failures = true;
       
   768           return true;
       
   769         }
   758         if (hr->is_young() != (cset_state.is_young())) {
   770         if (hr->is_young() != (cset_state.is_young())) {
   759           log_error(gc, verify)("## is_young %d / cset state " CSETSTATE_FORMAT " inconsistency for region %u",
   771           log_error(gc, verify)("## is_young %d / cset state " CSETSTATE_FORMAT " inconsistency for region %u",
   760                                hr->is_young(), cset_state.value(), i);
   772                                hr->is_young(), cset_state.value(), i);
   761           _failures = true;
   773           _failures = true;
   762           return true;
   774           return true;