hotspot/src/share/vm/gc/g1/youngList.cpp
changeset 38183 cb68e4923223
parent 38162 4e2c3433a3ae
equal deleted inserted replaced
38173:73d05e56ec86 38183:cb68e4923223
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "gc/g1/g1CollectedHeap.hpp"
       
    27 #include "gc/g1/g1CollectionSet.hpp"
       
    28 #include "gc/g1/g1Policy.hpp"
       
    29 #include "gc/g1/heapRegion.hpp"
    26 #include "gc/g1/heapRegion.hpp"
    30 #include "gc/g1/heapRegion.inline.hpp"
       
    31 #include "gc/g1/heapRegionRemSet.hpp"
       
    32 #include "gc/g1/youngList.hpp"
    27 #include "gc/g1/youngList.hpp"
    33 #include "logging/log.hpp"
       
    34 #include "utilities/growableArray.hpp"
    28 #include "utilities/growableArray.hpp"
    35 #include "utilities/ostream.hpp"
    29 #include "utilities/debug.hpp"
    36 
    30 
    37 YoungList::YoungList(G1CollectedHeap* g1h) :
    31 G1SurvivorRegions::G1SurvivorRegions() : _regions(new (ResourceObj::C_HEAP, mtGC) GrowableArray<HeapRegion*>(8, true, mtGC)) {}
    38     _g1h(g1h),
    32 
    39     _survivor_regions(new (ResourceObj::C_HEAP, mtGC) GrowableArray<HeapRegion*>(8, true, mtGC)),
    33 void G1SurvivorRegions::add(HeapRegion* hr) {
    40     _head(NULL),
    34   assert(hr->is_survivor(), "should be flagged as survivor region");
    41     _length(0) {
    35   _regions->append(hr);
    42   guarantee(check_list_empty(), "just making sure...");
       
    43 }
    36 }
    44 
    37 
    45 void YoungList::push_region(HeapRegion *hr) {
    38 uint G1SurvivorRegions::length() const {
    46   assert(!hr->is_young(), "should not already be young");
    39   return (uint)_regions->length();
    47   assert(hr->get_next_young_region() == NULL, "cause it should!");
       
    48 
       
    49   hr->set_next_young_region(_head);
       
    50   _head = hr;
       
    51 
       
    52   _g1h->g1_policy()->set_region_eden(hr);
       
    53   ++_length;
       
    54 }
    40 }
    55 
    41 
    56 void YoungList::add_survivor_region(HeapRegion* hr) {
    42 void G1SurvivorRegions::convert_to_eden() {
    57   assert(hr->is_survivor(), "should be flagged as survivor region");
    43   for (GrowableArrayIterator<HeapRegion*> it = _regions->begin();
    58   assert(hr->get_next_young_region() == NULL, "cause it should!");
    44        it != _regions->end();
    59 
    45        ++it) {
    60   _survivor_regions->append(hr);
    46     HeapRegion* hr = *it;
       
    47     hr->set_eden_pre_gc();
       
    48   }
       
    49   clear();
    61 }
    50 }
    62 
    51 
    63 void YoungList::empty_list(HeapRegion* list) {
    52 void G1SurvivorRegions::clear() {
    64   while (list != NULL) {
    53   _regions->clear();
    65     HeapRegion* next = list->get_next_young_region();
       
    66     list->set_next_young_region(NULL);
       
    67     list->uninstall_surv_rate_group();
       
    68     // This is called before a Full GC and all the non-empty /
       
    69     // non-humongous regions at the end of the Full GC will end up as
       
    70     // old anyway.
       
    71     list->set_old();
       
    72     list = next;
       
    73   }
       
    74 }
    54 }
    75 
    55 
    76 void YoungList::empty_list() {
    56 void G1EdenRegions::add(HeapRegion* hr) {
    77   assert(check_list_well_formed(), "young list should be well formed");
    57   assert(!hr->is_eden(), "should not already be set");
    78 
    58   _length++;
    79   empty_list(_head);
       
    80   _head = NULL;
       
    81   _length = 0;
       
    82 
       
    83   if (survivor_length() > 0) {
       
    84     empty_list(_survivor_regions->last());
       
    85   }
       
    86   _survivor_regions->clear();
       
    87 
       
    88   assert(check_list_empty(), "just making sure...");
       
    89 }
    59 }
    90 
       
    91 uint YoungList::survivor_length() {
       
    92   return _survivor_regions->length();
       
    93 }
       
    94 
       
    95 bool YoungList::check_list_well_formed() {
       
    96   bool ret = true;
       
    97 
       
    98   uint length = 0;
       
    99   HeapRegion* curr = _head;
       
   100   HeapRegion* last = NULL;
       
   101   while (curr != NULL) {
       
   102     if (!curr->is_young()) {
       
   103       log_error(gc, verify)("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
       
   104                             "incorrectly tagged (y: %d, surv: %d)",
       
   105                             p2i(curr->bottom()), p2i(curr->end()),
       
   106                             curr->is_young(), curr->is_survivor());
       
   107       ret = false;
       
   108     }
       
   109     ++length;
       
   110     last = curr;
       
   111     curr = curr->get_next_young_region();
       
   112   }
       
   113   ret = ret && (length == _length);
       
   114 
       
   115   if (!ret) {
       
   116     log_error(gc, verify)("### YOUNG LIST seems not well formed!");
       
   117     log_error(gc, verify)("###   list has %u entries, _length is %u", length, _length);
       
   118   }
       
   119 
       
   120   return ret;
       
   121 }
       
   122 
       
   123 bool YoungList::check_list_empty() {
       
   124   bool ret = true;
       
   125 
       
   126   if (_length != 0) {
       
   127     log_error(gc, verify)("### YOUNG LIST should have 0 length, not %u", _length);
       
   128     ret = false;
       
   129   }
       
   130   if (_head != NULL) {
       
   131     log_error(gc, verify)("### YOUNG LIST does not have a NULL head");
       
   132     ret = false;
       
   133   }
       
   134   if (!ret) {
       
   135     log_error(gc, verify)("### YOUNG LIST does not seem empty");
       
   136   }
       
   137 
       
   138   return ret;
       
   139 }
       
   140 
       
   141 void
       
   142 YoungList::reset_auxilary_lists() {
       
   143   guarantee( is_empty(), "young list should be empty" );
       
   144   assert(check_list_well_formed(), "young list should be well formed");
       
   145 
       
   146   // Add survivor regions to SurvRateGroup.
       
   147   _g1h->g1_policy()->note_start_adding_survivor_regions();
       
   148   _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
       
   149 
       
   150   HeapRegion* last = NULL;
       
   151   for (GrowableArrayIterator<HeapRegion*> it = _survivor_regions->begin();
       
   152        it != _survivor_regions->end();
       
   153        ++it) {
       
   154     HeapRegion* curr = *it;
       
   155     _g1h->g1_policy()->set_region_survivor(curr);
       
   156 
       
   157     // The region is a non-empty survivor so let's add it to
       
   158     // the incremental collection set for the next evacuation
       
   159     // pause.
       
   160     _g1h->collection_set()->add_survivor_regions(curr);
       
   161 
       
   162     curr->set_next_young_region(last);
       
   163     last = curr;
       
   164   }
       
   165   _g1h->g1_policy()->note_stop_adding_survivor_regions();
       
   166 
       
   167   _head   = last;
       
   168   _length = _survivor_regions->length();
       
   169 
       
   170   // Don't clear the survivor list handles until the start of
       
   171   // the next evacuation pause - we need it in order to re-tag
       
   172   // the survivor regions from this evacuation pause as 'young'
       
   173   // at the start of the next.
       
   174 
       
   175   _g1h->g1_policy()->finished_recalculating_age_indexes(false /* is_survivors */);
       
   176 
       
   177   assert(check_list_well_formed(), "young list should be well formed");
       
   178 }