hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
changeset 26696 623a25e6c686
parent 26692 b24a4cc794ce
child 26701 f8ff74a6c058
equal deleted inserted replaced
26695:18baf1a5a8ce 26696:623a25e6c686
   209 void YoungList::empty_list(HeapRegion* list) {
   209 void YoungList::empty_list(HeapRegion* list) {
   210   while (list != NULL) {
   210   while (list != NULL) {
   211     HeapRegion* next = list->get_next_young_region();
   211     HeapRegion* next = list->get_next_young_region();
   212     list->set_next_young_region(NULL);
   212     list->set_next_young_region(NULL);
   213     list->uninstall_surv_rate_group();
   213     list->uninstall_surv_rate_group();
   214     list->set_not_young();
   214     // This is called before a Full GC and all the non-empty /
       
   215     // non-humongous regions at the end of the Full GC will end up as
       
   216     // old anyway.
       
   217     list->set_old();
   215     list = next;
   218     list = next;
   216   }
   219   }
   217 }
   220 }
   218 
   221 
   219 void YoungList::empty_list() {
   222 void YoungList::empty_list() {
   368     gclog_or_tty->print_cr("%s LIST CONTENTS", names[list]);
   371     gclog_or_tty->print_cr("%s LIST CONTENTS", names[list]);
   369     HeapRegion *curr = lists[list];
   372     HeapRegion *curr = lists[list];
   370     if (curr == NULL)
   373     if (curr == NULL)
   371       gclog_or_tty->print_cr("  empty");
   374       gclog_or_tty->print_cr("  empty");
   372     while (curr != NULL) {
   375     while (curr != NULL) {
   373       gclog_or_tty->print_cr("  "HR_FORMAT", P: "PTR_FORMAT "N: "PTR_FORMAT", age: %4d",
   376       gclog_or_tty->print_cr("  "HR_FORMAT", P: "PTR_FORMAT ", N: "PTR_FORMAT", age: %4d",
   374                              HR_FORMAT_PARAMS(curr),
   377                              HR_FORMAT_PARAMS(curr),
   375                              curr->prev_top_at_mark_start(),
   378                              curr->prev_top_at_mark_start(),
   376                              curr->next_top_at_mark_start(),
   379                              curr->next_top_at_mark_start(),
   377                              curr->age_in_surv_rate_group_cond());
   380                              curr->age_in_surv_rate_group_cond());
   378       curr = curr->get_next_young_region();
   381       curr = curr->get_next_young_region();
   800       g1_policy()->record_new_heap_size(num_regions());
   803       g1_policy()->record_new_heap_size(num_regions());
   801 
   804 
   802 #ifdef ASSERT
   805 #ifdef ASSERT
   803       for (uint i = first; i < first + obj_regions; ++i) {
   806       for (uint i = first; i < first + obj_regions; ++i) {
   804         HeapRegion* hr = region_at(i);
   807         HeapRegion* hr = region_at(i);
       
   808         assert(hr->is_free(), "sanity");
   805         assert(hr->is_empty(), "sanity");
   809         assert(hr->is_empty(), "sanity");
   806         assert(is_on_master_free_list(hr), "sanity");
   810         assert(is_on_master_free_list(hr), "sanity");
   807       }
   811       }
   808 #endif
   812 #endif
   809       _hrm.allocate_free_regions_starting_at(first, obj_regions);
   813       _hrm.allocate_free_regions_starting_at(first, obj_regions);
  1223 private:
  1227 private:
  1224   G1HRPrinter* _hr_printer;
  1228   G1HRPrinter* _hr_printer;
  1225 public:
  1229 public:
  1226   bool doHeapRegion(HeapRegion* hr) {
  1230   bool doHeapRegion(HeapRegion* hr) {
  1227     assert(!hr->is_young(), "not expecting to find young regions");
  1231     assert(!hr->is_young(), "not expecting to find young regions");
  1228     // We only generate output for non-empty regions.
  1232     if (hr->is_free()) {
  1229     if (!hr->is_empty()) {
  1233       // We only generate output for non-empty regions.
  1230       if (!hr->isHumongous()) {
  1234     } else if (hr->startsHumongous()) {
  1231         _hr_printer->post_compaction(hr, G1HRPrinter::Old);
  1235       if (hr->region_num() == 1) {
  1232       } else if (hr->startsHumongous()) {
  1236         // single humongous region
  1233         if (hr->region_num() == 1) {
  1237         _hr_printer->post_compaction(hr, G1HRPrinter::SingleHumongous);
  1234           // single humongous region
       
  1235           _hr_printer->post_compaction(hr, G1HRPrinter::SingleHumongous);
       
  1236         } else {
       
  1237           _hr_printer->post_compaction(hr, G1HRPrinter::StartsHumongous);
       
  1238         }
       
  1239       } else {
  1238       } else {
  1240         assert(hr->continuesHumongous(), "only way to get here");
  1239         _hr_printer->post_compaction(hr, G1HRPrinter::StartsHumongous);
  1241         _hr_printer->post_compaction(hr, G1HRPrinter::ContinuesHumongous);
       
  1242       }
  1240       }
       
  1241     } else if (hr->continuesHumongous()) {
       
  1242       _hr_printer->post_compaction(hr, G1HRPrinter::ContinuesHumongous);
       
  1243     } else if (hr->is_old()) {
       
  1244       _hr_printer->post_compaction(hr, G1HRPrinter::Old);
       
  1245     } else {
       
  1246       ShouldNotReachHere();
  1243     }
  1247     }
  1244     return false;
  1248     return false;
  1245   }
  1249   }
  1246 
  1250 
  1247   PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
  1251   PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
  2119   HeapRegion* dummy_region = _hrm.get_dummy_region();
  2123   HeapRegion* dummy_region = _hrm.get_dummy_region();
  2120 
  2124 
  2121   // We'll re-use the same region whether the alloc region will
  2125   // We'll re-use the same region whether the alloc region will
  2122   // require BOT updates or not and, if it doesn't, then a non-young
  2126   // require BOT updates or not and, if it doesn't, then a non-young
  2123   // region will complain that it cannot support allocations without
  2127   // region will complain that it cannot support allocations without
  2124   // BOT updates. So we'll tag the dummy region as young to avoid that.
  2128   // BOT updates. So we'll tag the dummy region as eden to avoid that.
  2125   dummy_region->set_young();
  2129   dummy_region->set_eden();
  2126   // Make sure it's full.
  2130   // Make sure it's full.
  2127   dummy_region->set_top(dummy_region->end());
  2131   dummy_region->set_top(dummy_region->end());
  2128   G1AllocRegion::setup(this, dummy_region);
  2132   G1AllocRegion::setup(this, dummy_region);
  2129 
  2133 
  2130   init_mutator_alloc_region();
  2134   init_mutator_alloc_region();
  4029                                  true  /* verify_fingers */);
  4033                                  true  /* verify_fingers */);
  4030 
  4034 
  4031         if (_hr_printer.is_active()) {
  4035         if (_hr_printer.is_active()) {
  4032           HeapRegion* hr = g1_policy()->collection_set();
  4036           HeapRegion* hr = g1_policy()->collection_set();
  4033           while (hr != NULL) {
  4037           while (hr != NULL) {
  4034             G1HRPrinter::RegionType type;
       
  4035             if (!hr->is_young()) {
       
  4036               type = G1HRPrinter::Old;
       
  4037             } else if (hr->is_survivor()) {
       
  4038               type = G1HRPrinter::Survivor;
       
  4039             } else {
       
  4040               type = G1HRPrinter::Eden;
       
  4041             }
       
  4042             _hr_printer.cset(hr);
  4038             _hr_printer.cset(hr);
  4043             hr = hr->next_in_collection_set();
  4039             hr = hr->next_in_collection_set();
  4044           }
  4040           }
  4045         }
  4041         }
  4046 
  4042 
  6061 
  6057 
  6062 void G1CollectedHeap::free_region(HeapRegion* hr,
  6058 void G1CollectedHeap::free_region(HeapRegion* hr,
  6063                                   FreeRegionList* free_list,
  6059                                   FreeRegionList* free_list,
  6064                                   bool par,
  6060                                   bool par,
  6065                                   bool locked) {
  6061                                   bool locked) {
  6066   assert(!hr->isHumongous(), "this is only for non-humongous regions");
  6062   assert(!hr->is_free(), "the region should not be free");
  6067   assert(!hr->is_empty(), "the region should not be empty");
  6063   assert(!hr->is_empty(), "the region should not be empty");
  6068   assert(_hrm.is_available(hr->hrm_index()), "region should be committed");
  6064   assert(_hrm.is_available(hr->hrm_index()), "region should be committed");
  6069   assert(free_list != NULL, "pre-condition");
  6065   assert(free_list != NULL, "pre-condition");
  6070 
  6066 
  6071   if (G1VerifyBitmaps) {
  6067   if (G1VerifyBitmaps) {
  6091 
  6087 
  6092   size_t hr_capacity = hr->capacity();
  6088   size_t hr_capacity = hr->capacity();
  6093   // We need to read this before we make the region non-humongous,
  6089   // We need to read this before we make the region non-humongous,
  6094   // otherwise the information will be gone.
  6090   // otherwise the information will be gone.
  6095   uint last_index = hr->last_hc_index();
  6091   uint last_index = hr->last_hc_index();
  6096   hr->set_notHumongous();
  6092   hr->clear_humongous();
  6097   free_region(hr, free_list, par);
  6093   free_region(hr, free_list, par);
  6098 
  6094 
  6099   uint i = hr->hrm_index() + 1;
  6095   uint i = hr->hrm_index() + 1;
  6100   while (i < last_index) {
  6096   while (i < last_index) {
  6101     HeapRegion* curr_hr = region_at(i);
  6097     HeapRegion* curr_hr = region_at(i);
  6102     assert(curr_hr->continuesHumongous(), "invariant");
  6098     assert(curr_hr->continuesHumongous(), "invariant");
  6103     curr_hr->set_notHumongous();
  6099     curr_hr->clear_humongous();
  6104     free_region(curr_hr, free_list, par);
  6100     free_region(curr_hr, free_list, par);
  6105     i += 1;
  6101     i += 1;
  6106   }
  6102   }
  6107 }
  6103 }
  6108 
  6104 
  6406     } else {
  6402     } else {
  6407       cur->uninstall_surv_rate_group();
  6403       cur->uninstall_surv_rate_group();
  6408       if (cur->is_young()) {
  6404       if (cur->is_young()) {
  6409         cur->set_young_index_in_cset(-1);
  6405         cur->set_young_index_in_cset(-1);
  6410       }
  6406       }
  6411       cur->set_not_young();
       
  6412       cur->set_evacuation_failed(false);
  6407       cur->set_evacuation_failed(false);
  6413       // The region is now considered to be old.
  6408       // The region is now considered to be old.
       
  6409       cur->set_old();
  6414       _old_set.add(cur);
  6410       _old_set.add(cur);
  6415       evacuation_info.increment_collectionset_used_after(cur->used());
  6411       evacuation_info.increment_collectionset_used_after(cur->used());
  6416     }
  6412     }
  6417     cur = next;
  6413     cur = next;
  6418   }
  6414   }
  6695 
  6691 
  6696 public:
  6692 public:
  6697   TearDownRegionSetsClosure(HeapRegionSet* old_set) : _old_set(old_set) { }
  6693   TearDownRegionSetsClosure(HeapRegionSet* old_set) : _old_set(old_set) { }
  6698 
  6694 
  6699   bool doHeapRegion(HeapRegion* r) {
  6695   bool doHeapRegion(HeapRegion* r) {
  6700     if (r->is_empty()) {
  6696     if (r->is_old()) {
  6701       // We ignore empty regions, we'll empty the free list afterwards
  6697       _old_set->remove(r);
  6702     } else if (r->is_young()) {
  6698     } else {
  6703       // We ignore young regions, we'll empty the young list afterwards
  6699       // We ignore free regions, we'll empty the free list afterwards.
  6704     } else if (r->isHumongous()) {
  6700       // We ignore young regions, we'll empty the young list afterwards.
  6705       // We ignore humongous regions, we're not tearing down the
  6701       // We ignore humongous regions, we're not tearing down the
  6706       // humongous region set
  6702       // humongous regions set.
  6707     } else {
  6703       assert(r->is_free() || r->is_young() || r->isHumongous(),
  6708       // The rest should be old
  6704              "it cannot be another type");
  6709       _old_set->remove(r);
       
  6710     }
  6705     }
  6711     return false;
  6706     return false;
  6712   }
  6707   }
  6713 
  6708 
  6714   ~TearDownRegionSetsClosure() {
  6709   ~TearDownRegionSetsClosure() {
  6754       return false;
  6749       return false;
  6755     }
  6750     }
  6756 
  6751 
  6757     if (r->is_empty()) {
  6752     if (r->is_empty()) {
  6758       // Add free regions to the free list
  6753       // Add free regions to the free list
       
  6754       r->set_free();
  6759       _hrm->insert_into_free_list(r);
  6755       _hrm->insert_into_free_list(r);
  6760     } else if (!_free_list_only) {
  6756     } else if (!_free_list_only) {
  6761       assert(!r->is_young(), "we should not come across young regions");
  6757       assert(!r->is_young(), "we should not come across young regions");
  6762 
  6758 
  6763       if (r->isHumongous()) {
  6759       if (r->isHumongous()) {
  6764         // We ignore humongous regions, we left the humongous set unchanged
  6760         // We ignore humongous regions, we left the humongous set unchanged
  6765       } else {
  6761       } else {
  6766         // The rest should be old, add them to the old set
  6762         // Objects that were compacted would have ended up on regions
       
  6763         // that were previously old or free.
       
  6764         assert(r->is_free() || r->is_old(), "invariant");
       
  6765         // We now consider them old, so register as such.
       
  6766         r->set_old();
  6767         _old_set->add(r);
  6767         _old_set->add(r);
  6768       }
  6768       }
  6769       _total_used += r->used();
  6769       _total_used += r->used();
  6770     }
  6770     }
  6771 
  6771 
  6828 }
  6828 }
  6829 
  6829 
  6830 void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region,
  6830 void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region,
  6831                                                   size_t allocated_bytes) {
  6831                                                   size_t allocated_bytes) {
  6832   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
  6832   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
  6833   assert(alloc_region->is_young(), "all mutator alloc regions should be young");
  6833   assert(alloc_region->is_eden(), "all mutator alloc regions should be eden");
  6834 
  6834 
  6835   g1_policy()->add_region_to_incremental_cset_lhs(alloc_region);
  6835   g1_policy()->add_region_to_incremental_cset_lhs(alloc_region);
  6836   _summary_bytes_used += allocated_bytes;
  6836   _summary_bytes_used += allocated_bytes;
  6837   _hr_printer.retire(alloc_region);
  6837   _hr_printer.retire(alloc_region);
  6838   // We update the eden sizes here, when the region is retired,
  6838   // We update the eden sizes here, when the region is retired,
  6887       if (survivor) {
  6887       if (survivor) {
  6888         new_alloc_region->set_survivor();
  6888         new_alloc_region->set_survivor();
  6889         _hr_printer.alloc(new_alloc_region, G1HRPrinter::Survivor);
  6889         _hr_printer.alloc(new_alloc_region, G1HRPrinter::Survivor);
  6890         check_bitmaps("Survivor Region Allocation", new_alloc_region);
  6890         check_bitmaps("Survivor Region Allocation", new_alloc_region);
  6891       } else {
  6891       } else {
       
  6892         new_alloc_region->set_old();
  6892         _hr_printer.alloc(new_alloc_region, G1HRPrinter::Old);
  6893         _hr_printer.alloc(new_alloc_region, G1HRPrinter::Old);
  6893         check_bitmaps("Old Region Allocation", new_alloc_region);
  6894         check_bitmaps("Old Region Allocation", new_alloc_region);
  6894       }
  6895       }
  6895       bool during_im = g1_policy()->during_initial_mark_pause();
  6896       bool during_im = g1_policy()->during_initial_mark_pause();
  6896       new_alloc_region->note_start_of_copying(during_im);
  6897       new_alloc_region->note_start_of_copying(during_im);
  6998       assert(hr->containing_set() == _humongous_set, err_msg("Heap region %u is starts humongous but not in humongous set.", hr->hrm_index()));
  6999       assert(hr->containing_set() == _humongous_set, err_msg("Heap region %u is starts humongous but not in humongous set.", hr->hrm_index()));
  6999       _humongous_count.increment(1u, hr->capacity());
  7000       _humongous_count.increment(1u, hr->capacity());
  7000     } else if (hr->is_empty()) {
  7001     } else if (hr->is_empty()) {
  7001       assert(_hrm->is_free(hr), err_msg("Heap region %u is empty but not on the free list.", hr->hrm_index()));
  7002       assert(_hrm->is_free(hr), err_msg("Heap region %u is empty but not on the free list.", hr->hrm_index()));
  7002       _free_count.increment(1u, hr->capacity());
  7003       _free_count.increment(1u, hr->capacity());
  7003     } else {
  7004     } else if (hr->is_old()) {
  7004       assert(hr->containing_set() == _old_set, err_msg("Heap region %u is old but not in the old set.", hr->hrm_index()));
  7005       assert(hr->containing_set() == _old_set, err_msg("Heap region %u is old but not in the old set.", hr->hrm_index()));
  7005       _old_count.increment(1u, hr->capacity());
  7006       _old_count.increment(1u, hr->capacity());
       
  7007     } else {
       
  7008       ShouldNotReachHere();
  7006     }
  7009     }
  7007     return false;
  7010     return false;
  7008   }
  7011   }
  7009 
  7012 
  7010   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
  7013   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {