< prev index next >

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

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/heapRegion.inline.hpp"
  30 #include "gc/g1/heapRegionRemSet.hpp"
  31 #include "gc/g1/youngList.hpp"

  32 #include "utilities/ostream.hpp"
  33 
  34 YoungList::YoungList(G1CollectedHeap* g1h) :
  35     _g1h(g1h), _head(NULL), _length(0), _last_sampled_rs_lengths(0),
  36     _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) {
  37   guarantee(check_list_empty(false), "just making sure...");
  38 }
  39 
  40 void YoungList::push_region(HeapRegion *hr) {
  41   assert(!hr->is_young(), "should not already be young");
  42   assert(hr->get_next_young_region() == NULL, "cause it should!");
  43 
  44   hr->set_next_young_region(_head);
  45   _head = hr;
  46 
  47   _g1h->g1_policy()->set_region_eden(hr, (int) _length);
  48   ++_length;
  49 }
  50 
  51 void YoungList::add_survivor_region(HeapRegion* hr) {


  81   _length = 0;
  82 
  83   empty_list(_survivor_head);
  84   _survivor_head = NULL;
  85   _survivor_tail = NULL;
  86   _survivor_length = 0;
  87 
  88   _last_sampled_rs_lengths = 0;
  89 
  90   assert(check_list_empty(false), "just making sure...");
  91 }
  92 
  93 bool YoungList::check_list_well_formed() {
  94   bool ret = true;
  95 
  96   uint length = 0;
  97   HeapRegion* curr = _head;
  98   HeapRegion* last = NULL;
  99   while (curr != NULL) {
 100     if (!curr->is_young()) {
 101       gclog_or_tty->print_cr("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
 102                              "incorrectly tagged (y: %d, surv: %d)",
 103                              p2i(curr->bottom()), p2i(curr->end()),
 104                              curr->is_young(), curr->is_survivor());
 105       ret = false;
 106     }
 107     ++length;
 108     last = curr;
 109     curr = curr->get_next_young_region();
 110   }
 111   ret = ret && (length == _length);
 112 
 113   if (!ret) {
 114     gclog_or_tty->print_cr("### YOUNG LIST seems not well formed!");
 115     gclog_or_tty->print_cr("###   list has %u entries, _length is %u",
 116                            length, _length);
 117   }
 118 
 119   return ret;
 120 }
 121 
 122 bool YoungList::check_list_empty(bool check_sample) {
 123   bool ret = true;
 124 
 125   if (_length != 0) {
 126     gclog_or_tty->print_cr("### YOUNG LIST should have 0 length, not %u",
 127                   _length);
 128     ret = false;
 129   }
 130   if (check_sample && _last_sampled_rs_lengths != 0) {
 131     gclog_or_tty->print_cr("### YOUNG LIST has non-zero last sampled RS lengths");
 132     ret = false;
 133   }
 134   if (_head != NULL) {
 135     gclog_or_tty->print_cr("### YOUNG LIST does not have a NULL head");
 136     ret = false;
 137   }
 138   if (!ret) {
 139     gclog_or_tty->print_cr("### YOUNG LIST does not seem empty");
 140   }
 141 
 142   return ret;
 143 }
 144 
 145 void
 146 YoungList::rs_length_sampling_init() {
 147   _sampled_rs_lengths = 0;
 148   _curr               = _head;
 149 }
 150 
 151 bool
 152 YoungList::rs_length_sampling_more() {
 153   return _curr != NULL;
 154 }
 155 
 156 void
 157 YoungList::rs_length_sampling_next() {
 158   assert( _curr != NULL, "invariant" );
 159   size_t rs_length = _curr->rem_set()->occupied();
 160 
 161   _sampled_rs_lengths += rs_length;
 162 
 163   // The current region may not yet have been added to the
 164   // incremental collection set (it gets added when it is
 165   // retired as the current allocation region).
 166   if (_curr->in_collection_set()) {
 167     // Update the collection set policy information for this region
 168     _g1h->g1_policy()->update_incremental_cset_info(_curr, rs_length);
 169   }
 170 
 171   _curr = _curr->get_next_young_region();
 172   if (_curr == NULL) {
 173     _last_sampled_rs_lengths = _sampled_rs_lengths;
 174     // gclog_or_tty->print_cr("last sampled RS lengths = %d", _last_sampled_rs_lengths);
 175   }
 176 }
 177 
 178 void
 179 YoungList::reset_auxilary_lists() {
 180   guarantee( is_empty(), "young list should be empty" );
 181   assert(check_list_well_formed(), "young list should be well formed");
 182 
 183   // Add survivor regions to SurvRateGroup.
 184   _g1h->g1_policy()->note_start_adding_survivor_regions();
 185   _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
 186 
 187   int young_index_in_cset = 0;
 188   for (HeapRegion* curr = _survivor_head;
 189        curr != NULL;
 190        curr = curr->get_next_young_region()) {
 191     _g1h->g1_policy()->set_region_survivor(curr, young_index_in_cset);
 192 
 193     // The region is a non-empty survivor so let's add it to
 194     // the incremental collection set for the next evacuation


 205     assert(_survivor_tail != NULL, "cause it shouldn't be");
 206     assert(_survivor_length > 0, "invariant");
 207     _survivor_tail->set_next_young_region(NULL);
 208   }
 209 
 210   // Don't clear the survivor list handles until the start of
 211   // the next evacuation pause - we need it in order to re-tag
 212   // the survivor regions from this evacuation pause as 'young'
 213   // at the start of the next.
 214 
 215   _g1h->g1_policy()->finished_recalculating_age_indexes(false /* is_survivors */);
 216 
 217   assert(check_list_well_formed(), "young list should be well formed");
 218 }
 219 
 220 void YoungList::print() {
 221   HeapRegion* lists[] = {_head,   _survivor_head};
 222   const char* names[] = {"YOUNG", "SURVIVOR"};
 223 
 224   for (uint list = 0; list < ARRAY_SIZE(lists); ++list) {
 225     gclog_or_tty->print_cr("%s LIST CONTENTS", names[list]);
 226     HeapRegion *curr = lists[list];
 227     if (curr == NULL) {
 228       gclog_or_tty->print_cr("  empty");
 229     }
 230     while (curr != NULL) {
 231       gclog_or_tty->print_cr("  " HR_FORMAT ", P: " PTR_FORMAT ", N: " PTR_FORMAT ", age: %4d",
 232                              HR_FORMAT_PARAMS(curr),
 233                              p2i(curr->prev_top_at_mark_start()),
 234                              p2i(curr->next_top_at_mark_start()),
 235                              curr->age_in_surv_rate_group_cond());
 236       curr = curr->get_next_young_region();
 237     }
 238   }
 239 
 240   gclog_or_tty->cr();
 241 }


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.hpp"
  27 #include "gc/g1/g1CollectorPolicy.hpp"
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/heapRegion.inline.hpp"
  30 #include "gc/g1/heapRegionRemSet.hpp"
  31 #include "gc/g1/youngList.hpp"
  32 #include "logging/log.hpp"
  33 #include "utilities/ostream.hpp"
  34 
  35 YoungList::YoungList(G1CollectedHeap* g1h) :
  36     _g1h(g1h), _head(NULL), _length(0), _last_sampled_rs_lengths(0),
  37     _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) {
  38   guarantee(check_list_empty(false), "just making sure...");
  39 }
  40 
  41 void YoungList::push_region(HeapRegion *hr) {
  42   assert(!hr->is_young(), "should not already be young");
  43   assert(hr->get_next_young_region() == NULL, "cause it should!");
  44 
  45   hr->set_next_young_region(_head);
  46   _head = hr;
  47 
  48   _g1h->g1_policy()->set_region_eden(hr, (int) _length);
  49   ++_length;
  50 }
  51 
  52 void YoungList::add_survivor_region(HeapRegion* hr) {


  82   _length = 0;
  83 
  84   empty_list(_survivor_head);
  85   _survivor_head = NULL;
  86   _survivor_tail = NULL;
  87   _survivor_length = 0;
  88 
  89   _last_sampled_rs_lengths = 0;
  90 
  91   assert(check_list_empty(false), "just making sure...");
  92 }
  93 
  94 bool YoungList::check_list_well_formed() {
  95   bool ret = true;
  96 
  97   uint length = 0;
  98   HeapRegion* curr = _head;
  99   HeapRegion* last = NULL;
 100   while (curr != NULL) {
 101     if (!curr->is_young()) {
 102       log_info(gc, verify)("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
 103                            "incorrectly tagged (y: %d, surv: %d)",
 104                            p2i(curr->bottom()), p2i(curr->end()),
 105                            curr->is_young(), curr->is_survivor());
 106       ret = false;
 107     }
 108     ++length;
 109     last = curr;
 110     curr = curr->get_next_young_region();
 111   }
 112   ret = ret && (length == _length);
 113 
 114   if (!ret) {
 115     log_info(gc, verify)("### YOUNG LIST seems not well formed!");
 116     log_info(gc, verify)("###   list has %u entries, _length is %u",
 117                            length, _length);
 118   }
 119 
 120   return ret;
 121 }
 122 
 123 bool YoungList::check_list_empty(bool check_sample) {
 124   bool ret = true;
 125 
 126   if (_length != 0) {
 127     log_info(gc, verify)("### YOUNG LIST should have 0 length, not %u", _length);

 128     ret = false;
 129   }
 130   if (check_sample && _last_sampled_rs_lengths != 0) {
 131     log_info(gc, verify)("### YOUNG LIST has non-zero last sampled RS lengths");
 132     ret = false;
 133   }
 134   if (_head != NULL) {
 135     log_info(gc, verify)("### YOUNG LIST does not have a NULL head");
 136     ret = false;
 137   }
 138   if (!ret) {
 139     log_info(gc, verify)("### YOUNG LIST does not seem empty");
 140   }
 141 
 142   return ret;
 143 }
 144 
 145 void
 146 YoungList::rs_length_sampling_init() {
 147   _sampled_rs_lengths = 0;
 148   _curr               = _head;
 149 }
 150 
 151 bool
 152 YoungList::rs_length_sampling_more() {
 153   return _curr != NULL;
 154 }
 155 
 156 void
 157 YoungList::rs_length_sampling_next() {
 158   assert( _curr != NULL, "invariant" );
 159   size_t rs_length = _curr->rem_set()->occupied();
 160 
 161   _sampled_rs_lengths += rs_length;
 162 
 163   // The current region may not yet have been added to the
 164   // incremental collection set (it gets added when it is
 165   // retired as the current allocation region).
 166   if (_curr->in_collection_set()) {
 167     // Update the collection set policy information for this region
 168     _g1h->g1_policy()->update_incremental_cset_info(_curr, rs_length);
 169   }
 170 
 171   _curr = _curr->get_next_young_region();
 172   if (_curr == NULL) {
 173     _last_sampled_rs_lengths = _sampled_rs_lengths;

 174   }
 175 }
 176 
 177 void
 178 YoungList::reset_auxilary_lists() {
 179   guarantee( is_empty(), "young list should be empty" );
 180   assert(check_list_well_formed(), "young list should be well formed");
 181 
 182   // Add survivor regions to SurvRateGroup.
 183   _g1h->g1_policy()->note_start_adding_survivor_regions();
 184   _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
 185 
 186   int young_index_in_cset = 0;
 187   for (HeapRegion* curr = _survivor_head;
 188        curr != NULL;
 189        curr = curr->get_next_young_region()) {
 190     _g1h->g1_policy()->set_region_survivor(curr, young_index_in_cset);
 191 
 192     // The region is a non-empty survivor so let's add it to
 193     // the incremental collection set for the next evacuation


 204     assert(_survivor_tail != NULL, "cause it shouldn't be");
 205     assert(_survivor_length > 0, "invariant");
 206     _survivor_tail->set_next_young_region(NULL);
 207   }
 208 
 209   // Don't clear the survivor list handles until the start of
 210   // the next evacuation pause - we need it in order to re-tag
 211   // the survivor regions from this evacuation pause as 'young'
 212   // at the start of the next.
 213 
 214   _g1h->g1_policy()->finished_recalculating_age_indexes(false /* is_survivors */);
 215 
 216   assert(check_list_well_formed(), "young list should be well formed");
 217 }
 218 
 219 void YoungList::print() {
 220   HeapRegion* lists[] = {_head,   _survivor_head};
 221   const char* names[] = {"YOUNG", "SURVIVOR"};
 222 
 223   for (uint list = 0; list < ARRAY_SIZE(lists); ++list) {
 224     tty->print_cr("%s LIST CONTENTS", names[list]);
 225     HeapRegion *curr = lists[list];
 226     if (curr == NULL) {
 227       tty->print_cr("  empty");
 228     }
 229     while (curr != NULL) {
 230       tty->print_cr("  " HR_FORMAT ", P: " PTR_FORMAT ", N: " PTR_FORMAT ", age: %4d",
 231                              HR_FORMAT_PARAMS(curr),
 232                              p2i(curr->prev_top_at_mark_start()),
 233                              p2i(curr->next_top_at_mark_start()),
 234                              curr->age_in_surv_rate_group_cond());
 235       curr = curr->get_next_young_region();
 236     }
 237   }
 238 
 239   tty->cr();
 240 }
< prev index next >