hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
changeset 33105 294e48b4f704
parent 32818 87014063ec81
child 33107 77bf0d2069a3
equal deleted inserted replaced
33104:a7c0f60a1294 33105:294e48b4f704
   969     size_t word_size = curr_range.word_size();
   969     size_t word_size = curr_range.word_size();
   970     HeapWord* last_address = curr_range.last();
   970     HeapWord* last_address = curr_range.last();
   971     size_t commits = 0;
   971     size_t commits = 0;
   972 
   972 
   973     guarantee(reserved.contains(start_address) && reserved.contains(last_address),
   973     guarantee(reserved.contains(start_address) && reserved.contains(last_address),
   974               err_msg("MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
   974               "MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
   975               p2i(start_address), p2i(last_address)));
   975               p2i(start_address), p2i(last_address));
   976     guarantee(start_address > prev_last_addr,
   976     guarantee(start_address > prev_last_addr,
   977               err_msg("Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
   977               "Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
   978               p2i(start_address), p2i(prev_last_addr)));
   978               p2i(start_address), p2i(prev_last_addr));
   979     prev_last_addr = last_address;
   979     prev_last_addr = last_address;
   980 
   980 
   981     // Check for ranges that start in the same G1 region in which the previous
   981     // Check for ranges that start in the same G1 region in which the previous
   982     // range ended, and adjust the start address so we don't try to allocate
   982     // range ended, and adjust the start address so we don't try to allocate
   983     // the same region again. If the current range is entirely within that
   983     // the same region again. If the current range is entirely within that
  1015     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1015     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1016     prev_last_region = last_region;
  1016     prev_last_region = last_region;
  1017 
  1017 
  1018     while (curr_region != NULL) {
  1018     while (curr_region != NULL) {
  1019       assert(curr_region->is_empty() && !curr_region->is_pinned(),
  1019       assert(curr_region->is_empty() && !curr_region->is_pinned(),
  1020              err_msg("Region already in use (index %u)", curr_region->hrm_index()));
  1020              "Region already in use (index %u)", curr_region->hrm_index());
  1021       _hr_printer.alloc(curr_region, G1HRPrinter::Archive);
  1021       _hr_printer.alloc(curr_region, G1HRPrinter::Archive);
  1022       curr_region->set_allocation_context(AllocationContext::system());
  1022       curr_region->set_allocation_context(AllocationContext::system());
  1023       curr_region->set_archive();
  1023       curr_region->set_archive();
  1024       _old_set.add(curr_region);
  1024       _old_set.add(curr_region);
  1025       if (curr_region != last_region) {
  1025       if (curr_region != last_region) {
  1053   for (size_t i = 0; i < count; i++) {
  1053   for (size_t i = 0; i < count; i++) {
  1054     HeapWord* start_address = ranges[i].start();
  1054     HeapWord* start_address = ranges[i].start();
  1055     HeapWord* last_address = ranges[i].last();
  1055     HeapWord* last_address = ranges[i].last();
  1056 
  1056 
  1057     assert(reserved.contains(start_address) && reserved.contains(last_address),
  1057     assert(reserved.contains(start_address) && reserved.contains(last_address),
  1058            err_msg("MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
  1058            "MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
  1059                    p2i(start_address), p2i(last_address)));
  1059            p2i(start_address), p2i(last_address));
  1060     assert(start_address > prev_last_addr,
  1060     assert(start_address > prev_last_addr,
  1061            err_msg("Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
  1061            "Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
  1062                    p2i(start_address), p2i(prev_last_addr)));
  1062            p2i(start_address), p2i(prev_last_addr));
  1063 
  1063 
  1064     HeapRegion* start_region = _hrm.addr_to_region(start_address);
  1064     HeapRegion* start_region = _hrm.addr_to_region(start_address);
  1065     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1065     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1066     HeapWord* bottom_address = start_region->bottom();
  1066     HeapWord* bottom_address = start_region->bottom();
  1067 
  1067 
  1074     // Verify that the regions were all marked as archive regions by
  1074     // Verify that the regions were all marked as archive regions by
  1075     // alloc_archive_regions.
  1075     // alloc_archive_regions.
  1076     HeapRegion* curr_region = start_region;
  1076     HeapRegion* curr_region = start_region;
  1077     while (curr_region != NULL) {
  1077     while (curr_region != NULL) {
  1078       guarantee(curr_region->is_archive(),
  1078       guarantee(curr_region->is_archive(),
  1079                 err_msg("Expected archive region at index %u", curr_region->hrm_index()));
  1079                 "Expected archive region at index %u", curr_region->hrm_index());
  1080       if (curr_region != last_region) {
  1080       if (curr_region != last_region) {
  1081         curr_region = _hrm.next_region_in_heap(curr_region);
  1081         curr_region = _hrm.next_region_in_heap(curr_region);
  1082       } else {
  1082       } else {
  1083         curr_region = NULL;
  1083         curr_region = NULL;
  1084       }
  1084       }
  1137   for (size_t i = 0; i < count; i++) {
  1137   for (size_t i = 0; i < count; i++) {
  1138     HeapWord* start_address = ranges[i].start();
  1138     HeapWord* start_address = ranges[i].start();
  1139     HeapWord* last_address = ranges[i].last();
  1139     HeapWord* last_address = ranges[i].last();
  1140 
  1140 
  1141     assert(reserved.contains(start_address) && reserved.contains(last_address),
  1141     assert(reserved.contains(start_address) && reserved.contains(last_address),
  1142            err_msg("MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
  1142            "MemRegion outside of heap [" PTR_FORMAT ", " PTR_FORMAT "]",
  1143                    p2i(start_address), p2i(last_address)));
  1143            p2i(start_address), p2i(last_address));
  1144     assert(start_address > prev_last_addr,
  1144     assert(start_address > prev_last_addr,
  1145            err_msg("Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
  1145            "Ranges not in ascending order: " PTR_FORMAT " <= " PTR_FORMAT ,
  1146                    p2i(start_address), p2i(prev_last_addr)));
  1146            p2i(start_address), p2i(prev_last_addr));
  1147     size_used += ranges[i].byte_size();
  1147     size_used += ranges[i].byte_size();
  1148     prev_last_addr = last_address;
  1148     prev_last_addr = last_address;
  1149 
  1149 
  1150     HeapRegion* start_region = _hrm.addr_to_region(start_address);
  1150     HeapRegion* start_region = _hrm.addr_to_region(start_address);
  1151     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1151     HeapRegion* last_region = _hrm.addr_to_region(last_address);
  1166     // After verifying that each region was marked as an archive region by
  1166     // After verifying that each region was marked as an archive region by
  1167     // alloc_archive_regions, set it free and empty and uncommit it.
  1167     // alloc_archive_regions, set it free and empty and uncommit it.
  1168     HeapRegion* curr_region = start_region;
  1168     HeapRegion* curr_region = start_region;
  1169     while (curr_region != NULL) {
  1169     while (curr_region != NULL) {
  1170       guarantee(curr_region->is_archive(),
  1170       guarantee(curr_region->is_archive(),
  1171                 err_msg("Expected archive region at index %u", curr_region->hrm_index()));
  1171                 "Expected archive region at index %u", curr_region->hrm_index());
  1172       uint curr_index = curr_region->hrm_index();
  1172       uint curr_index = curr_region->hrm_index();
  1173       _old_set.remove(curr_region);
  1173       _old_set.remove(curr_region);
  1174       curr_region->set_free();
  1174       curr_region->set_free();
  1175       curr_region->set_top(curr_region->bottom());
  1175       curr_region->set_top(curr_region->bottom());
  1176       if (curr_region != last_region) {
  1176       if (curr_region != last_region) {
  1753   size_t maximum_desired_capacity = (size_t) maximum_desired_capacity_d;
  1753   size_t maximum_desired_capacity = (size_t) maximum_desired_capacity_d;
  1754 
  1754 
  1755   // This assert only makes sense here, before we adjust them
  1755   // This assert only makes sense here, before we adjust them
  1756   // with respect to the min and max heap size.
  1756   // with respect to the min and max heap size.
  1757   assert(minimum_desired_capacity <= maximum_desired_capacity,
  1757   assert(minimum_desired_capacity <= maximum_desired_capacity,
  1758          err_msg("minimum_desired_capacity = " SIZE_FORMAT ", "
  1758          "minimum_desired_capacity = " SIZE_FORMAT ", "
  1759                  "maximum_desired_capacity = " SIZE_FORMAT,
  1759          "maximum_desired_capacity = " SIZE_FORMAT,
  1760                  minimum_desired_capacity, maximum_desired_capacity));
  1760          minimum_desired_capacity, maximum_desired_capacity);
  1761 
  1761 
  1762   // Should not be greater than the heap max size. No need to adjust
  1762   // Should not be greater than the heap max size. No need to adjust
  1763   // it with respect to the heap min size as it's a lower bound (i.e.,
  1763   // it with respect to the heap min size as it's a lower bound (i.e.,
  1764   // we'll try to make the capacity larger than it, not smaller).
  1764   // we'll try to make the capacity larger than it, not smaller).
  1765   minimum_desired_capacity = MIN2(minimum_desired_capacity, max_heap_size);
  1765   minimum_desired_capacity = MIN2(minimum_desired_capacity, max_heap_size);
  2536 }
  2536 }
  2537 #endif // !PRODUCT
  2537 #endif // !PRODUCT
  2538 
  2538 
  2539 void G1CollectedHeap::increment_old_marking_cycles_started() {
  2539 void G1CollectedHeap::increment_old_marking_cycles_started() {
  2540   assert(_old_marking_cycles_started == _old_marking_cycles_completed ||
  2540   assert(_old_marking_cycles_started == _old_marking_cycles_completed ||
  2541     _old_marking_cycles_started == _old_marking_cycles_completed + 1,
  2541          _old_marking_cycles_started == _old_marking_cycles_completed + 1,
  2542     err_msg("Wrong marking cycle count (started: %d, completed: %d)",
  2542          "Wrong marking cycle count (started: %d, completed: %d)",
  2543     _old_marking_cycles_started, _old_marking_cycles_completed));
  2543          _old_marking_cycles_started, _old_marking_cycles_completed);
  2544 
  2544 
  2545   _old_marking_cycles_started++;
  2545   _old_marking_cycles_started++;
  2546 }
  2546 }
  2547 
  2547 
  2548 void G1CollectedHeap::increment_old_marking_cycles_completed(bool concurrent) {
  2548 void G1CollectedHeap::increment_old_marking_cycles_completed(bool concurrent) {
  2562 
  2562 
  2563   // This is the case for the inner caller, i.e. a Full GC.
  2563   // This is the case for the inner caller, i.e. a Full GC.
  2564   assert(concurrent ||
  2564   assert(concurrent ||
  2565          (_old_marking_cycles_started == _old_marking_cycles_completed + 1) ||
  2565          (_old_marking_cycles_started == _old_marking_cycles_completed + 1) ||
  2566          (_old_marking_cycles_started == _old_marking_cycles_completed + 2),
  2566          (_old_marking_cycles_started == _old_marking_cycles_completed + 2),
  2567          err_msg("for inner caller (Full GC): _old_marking_cycles_started = %u "
  2567          "for inner caller (Full GC): _old_marking_cycles_started = %u "
  2568                  "is inconsistent with _old_marking_cycles_completed = %u",
  2568          "is inconsistent with _old_marking_cycles_completed = %u",
  2569                  _old_marking_cycles_started, _old_marking_cycles_completed));
  2569          _old_marking_cycles_started, _old_marking_cycles_completed);
  2570 
  2570 
  2571   // This is the case for the outer caller, i.e. the concurrent cycle.
  2571   // This is the case for the outer caller, i.e. the concurrent cycle.
  2572   assert(!concurrent ||
  2572   assert(!concurrent ||
  2573          (_old_marking_cycles_started == _old_marking_cycles_completed + 1),
  2573          (_old_marking_cycles_started == _old_marking_cycles_completed + 1),
  2574          err_msg("for outer caller (concurrent cycle): "
  2574          "for outer caller (concurrent cycle): "
  2575                  "_old_marking_cycles_started = %u "
  2575          "_old_marking_cycles_started = %u "
  2576                  "is inconsistent with _old_marking_cycles_completed = %u",
  2576          "is inconsistent with _old_marking_cycles_completed = %u",
  2577                  _old_marking_cycles_started, _old_marking_cycles_completed));
  2577          _old_marking_cycles_started, _old_marking_cycles_completed);
  2578 
  2578 
  2579   _old_marking_cycles_completed += 1;
  2579   _old_marking_cycles_completed += 1;
  2580 
  2580 
  2581   // We need to clear the "in_progress" flag in the CM thread before
  2581   // We need to clear the "in_progress" flag in the CM thread before
  2582   // we wake up any waiters (especially when ExplicitInvokesConcurrent
  2582   // we wake up any waiters (especially when ExplicitInvokesConcurrent
  3122     k->oops_do(_oop_closure);
  3122     k->oops_do(_oop_closure);
  3123 
  3123 
  3124     _young_ref_counter_closure.reset_count();
  3124     _young_ref_counter_closure.reset_count();
  3125     k->oops_do(&_young_ref_counter_closure);
  3125     k->oops_do(&_young_ref_counter_closure);
  3126     if (_young_ref_counter_closure.count() > 0) {
  3126     if (_young_ref_counter_closure.count() > 0) {
  3127       guarantee(k->has_modified_oops(), err_msg("Klass " PTR_FORMAT ", has young refs but is not dirty.", p2i(k)));
  3127       guarantee(k->has_modified_oops(), "Klass " PTR_FORMAT ", has young refs but is not dirty.", p2i(k));
  3128     }
  3128     }
  3129   }
  3129   }
  3130 };
  3130 };
  3131 
  3131 
  3132 class VerifyLivenessOopClosure: public OopClosure {
  3132 class VerifyLivenessOopClosure: public OopClosure {
  3192   void do_oop(      oop *p) { do_oop_work(p); }
  3192   void do_oop(      oop *p) { do_oop_work(p); }
  3193 
  3193 
  3194   template <class T> void do_oop_work(T *p) {
  3194   template <class T> void do_oop_work(T *p) {
  3195     oop obj = oopDesc::load_decode_heap_oop(p);
  3195     oop obj = oopDesc::load_decode_heap_oop(p);
  3196     guarantee(obj == NULL || G1MarkSweep::in_archive_range(obj),
  3196     guarantee(obj == NULL || G1MarkSweep::in_archive_range(obj),
  3197               err_msg("Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
  3197               "Archive object at " PTR_FORMAT " references a non-archive object at " PTR_FORMAT,
  3198                       p2i(p), p2i(obj)));
  3198               p2i(p), p2i(obj));
  3199   }
  3199   }
  3200 };
  3200 };
  3201 
  3201 
  3202 class VerifyArchiveRegionClosure: public ObjectClosure {
  3202 class VerifyArchiveRegionClosure: public ObjectClosure {
  3203 public:
  3203 public:
  4707     }
  4707     }
  4708   }
  4708   }
  4709 
  4709 
  4710   ~G1StringSymbolTableUnlinkTask() {
  4710   ~G1StringSymbolTableUnlinkTask() {
  4711     guarantee(!_process_strings || StringTable::parallel_claimed_index() >= _initial_string_table_size,
  4711     guarantee(!_process_strings || StringTable::parallel_claimed_index() >= _initial_string_table_size,
  4712               err_msg("claim value %d after unlink less than initial string table size %d",
  4712               "claim value %d after unlink less than initial string table size %d",
  4713                       StringTable::parallel_claimed_index(), _initial_string_table_size));
  4713               StringTable::parallel_claimed_index(), _initial_string_table_size);
  4714     guarantee(!_process_symbols || SymbolTable::parallel_claimed_index() >= _initial_symbol_table_size,
  4714     guarantee(!_process_symbols || SymbolTable::parallel_claimed_index() >= _initial_symbol_table_size,
  4715               err_msg("claim value %d after unlink less than initial symbol table size %d",
  4715               "claim value %d after unlink less than initial symbol table size %d",
  4716                       SymbolTable::parallel_claimed_index(), _initial_symbol_table_size));
  4716               SymbolTable::parallel_claimed_index(), _initial_symbol_table_size);
  4717 
  4717 
  4718     if (G1TraceStringSymbolTableScrubbing) {
  4718     if (G1TraceStringSymbolTableScrubbing) {
  4719       gclog_or_tty->print_cr("Cleaned string and symbol table, "
  4719       gclog_or_tty->print_cr("Cleaned string and symbol table, "
  4720                              "strings: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed, "
  4720                              "strings: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed, "
  4721                              "symbols: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed",
  4721                              "symbols: " SIZE_FORMAT " processed, " SIZE_FORMAT " removed",
  5111       assert( obj->is_forwarded(), "invariant" );
  5111       assert( obj->is_forwarded(), "invariant" );
  5112       *p = obj->forwardee();
  5112       *p = obj->forwardee();
  5113     } else {
  5113     } else {
  5114       assert(!obj->is_forwarded(), "invariant" );
  5114       assert(!obj->is_forwarded(), "invariant" );
  5115       assert(cset_state.is_humongous(),
  5115       assert(cset_state.is_humongous(),
  5116              err_msg("Only allowed InCSet state is IsHumongous, but is %d", cset_state.value()));
  5116              "Only allowed InCSet state is IsHumongous, but is %d", cset_state.value());
  5117       _g1->set_humongous_is_live(obj);
  5117       _g1->set_humongous_is_live(obj);
  5118     }
  5118     }
  5119   }
  5119   }
  5120 };
  5120 };
  5121 
  5121 
  5165 
  5165 
  5166       if (_g1h->is_in_g1_reserved(p)) {
  5166       if (_g1h->is_in_g1_reserved(p)) {
  5167         _par_scan_state->push_on_queue(p);
  5167         _par_scan_state->push_on_queue(p);
  5168       } else {
  5168       } else {
  5169         assert(!Metaspace::contains((const void*)p),
  5169         assert(!Metaspace::contains((const void*)p),
  5170                err_msg("Unexpectedly found a pointer from metadata: " PTR_FORMAT, p2i(p)));
  5170                "Unexpectedly found a pointer from metadata: " PTR_FORMAT, p2i(p));
  5171         _copy_non_heap_obj_cl->do_oop(p);
  5171         _copy_non_heap_obj_cl->do_oop(p);
  5172       }
  5172       }
  5173     }
  5173     }
  5174   }
  5174   }
  5175 };
  5175 };
  5821 }
  5821 }
  5822 
  5822 
  5823 bool G1CollectedHeap::verify_no_bits_over_tams(const char* bitmap_name, CMBitMapRO* bitmap,
  5823 bool G1CollectedHeap::verify_no_bits_over_tams(const char* bitmap_name, CMBitMapRO* bitmap,
  5824                                                HeapWord* tams, HeapWord* end) {
  5824                                                HeapWord* tams, HeapWord* end) {
  5825   guarantee(tams <= end,
  5825   guarantee(tams <= end,
  5826             err_msg("tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end)));
  5826             "tams: " PTR_FORMAT " end: " PTR_FORMAT, p2i(tams), p2i(end));
  5827   HeapWord* result = bitmap->getNextMarkedWordAddress(tams, end);
  5827   HeapWord* result = bitmap->getNextMarkedWordAddress(tams, end);
  5828   if (result < end) {
  5828   if (result < end) {
  5829     gclog_or_tty->cr();
  5829     gclog_or_tty->cr();
  5830     gclog_or_tty->print_cr("## wrong marked address on %s bitmap: " PTR_FORMAT,
  5830     gclog_or_tty->print_cr("## wrong marked address on %s bitmap: " PTR_FORMAT,
  5831                            bitmap_name, p2i(result));
  5831                            bitmap_name, p2i(result));
  6172 
  6172 
  6173       return false;
  6173       return false;
  6174     }
  6174     }
  6175 
  6175 
  6176     guarantee(obj->is_typeArray(),
  6176     guarantee(obj->is_typeArray(),
  6177               err_msg("Only eagerly reclaiming type arrays is supported, but the object "
  6177               "Only eagerly reclaiming type arrays is supported, but the object "
  6178                       PTR_FORMAT " is not.",
  6178               PTR_FORMAT " is not.", p2i(r->bottom()));
  6179                       p2i(r->bottom())));
       
  6180 
  6179 
  6181     if (G1TraceEagerReclaimHumongousObjects) {
  6180     if (G1TraceEagerReclaimHumongousObjects) {
  6182       gclog_or_tty->print_cr("Dead humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length %u with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
  6181       gclog_or_tty->print_cr("Dead humongous region %u size " SIZE_FORMAT " start " PTR_FORMAT " length %u with remset " SIZE_FORMAT " code roots " SIZE_FORMAT " is marked %d reclaim candidate %d type array %d",
  6183                              region_idx,
  6182                              region_idx,
  6184                              (size_t)obj->size() * HeapWordSize,
  6183                              (size_t)obj->size() * HeapWordSize,
  6403   _summary_bytes_used += bytes;
  6402   _summary_bytes_used += bytes;
  6404 }
  6403 }
  6405 
  6404 
  6406 void G1CollectedHeap::decrease_used(size_t bytes) {
  6405 void G1CollectedHeap::decrease_used(size_t bytes) {
  6407   assert(_summary_bytes_used >= bytes,
  6406   assert(_summary_bytes_used >= bytes,
  6408          err_msg("invariant: _summary_bytes_used: " SIZE_FORMAT " should be >= bytes: " SIZE_FORMAT,
  6407          "invariant: _summary_bytes_used: " SIZE_FORMAT " should be >= bytes: " SIZE_FORMAT,
  6409                  _summary_bytes_used, bytes));
  6408          _summary_bytes_used, bytes);
  6410   _summary_bytes_used -= bytes;
  6409   _summary_bytes_used -= bytes;
  6411 }
  6410 }
  6412 
  6411 
  6413 void G1CollectedHeap::set_used(size_t bytes) {
  6412 void G1CollectedHeap::set_used(size_t bytes) {
  6414   _summary_bytes_used = bytes;
  6413   _summary_bytes_used = bytes;
  6486     if (_archive_allocator != NULL) {
  6485     if (_archive_allocator != NULL) {
  6487       _archive_allocator->clear_used();
  6486       _archive_allocator->clear_used();
  6488     }
  6487     }
  6489   }
  6488   }
  6490   assert(used_unlocked() == recalculate_used(),
  6489   assert(used_unlocked() == recalculate_used(),
  6491          err_msg("inconsistent used_unlocked(), "
  6490          "inconsistent used_unlocked(), "
  6492                  "value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT,
  6491          "value: " SIZE_FORMAT " recalculated: " SIZE_FORMAT,
  6493                  used_unlocked(), recalculate_used()));
  6492          used_unlocked(), recalculate_used());
  6494 }
  6493 }
  6495 
  6494 
  6496 void G1CollectedHeap::set_refine_cte_cl_concurrency(bool concurrent) {
  6495 void G1CollectedHeap::set_refine_cte_cl_concurrency(bool concurrent) {
  6497   _refine_cte_cl->set_concurrent(concurrent);
  6496   _refine_cte_cl->set_concurrent(concurrent);
  6498 }
  6497 }
  6629     }
  6628     }
  6630 
  6629 
  6631     if (hr->is_young()) {
  6630     if (hr->is_young()) {
  6632       // TODO
  6631       // TODO
  6633     } else if (hr->is_starts_humongous()) {
  6632     } else if (hr->is_starts_humongous()) {
  6634       assert(hr->containing_set() == _humongous_set, err_msg("Heap region %u is starts humongous but not in humongous set.", hr->hrm_index()));
  6633       assert(hr->containing_set() == _humongous_set, "Heap region %u is starts humongous but not in humongous set.", hr->hrm_index());
  6635       _humongous_count.increment(1u, hr->capacity());
  6634       _humongous_count.increment(1u, hr->capacity());
  6636     } else if (hr->is_empty()) {
  6635     } else if (hr->is_empty()) {
  6637       assert(_hrm->is_free(hr), err_msg("Heap region %u is empty but not on the free list.", hr->hrm_index()));
  6636       assert(_hrm->is_free(hr), "Heap region %u is empty but not on the free list.", hr->hrm_index());
  6638       _free_count.increment(1u, hr->capacity());
  6637       _free_count.increment(1u, hr->capacity());
  6639     } else if (hr->is_old()) {
  6638     } else if (hr->is_old()) {
  6640       assert(hr->containing_set() == _old_set, err_msg("Heap region %u is old but not in the old set.", hr->hrm_index()));
  6639       assert(hr->containing_set() == _old_set, "Heap region %u is old but not in the old set.", hr->hrm_index());
  6641       _old_count.increment(1u, hr->capacity());
  6640       _old_count.increment(1u, hr->capacity());
  6642     } else {
  6641     } else {
  6643       // There are no other valid region types. Check for one invalid
  6642       // There are no other valid region types. Check for one invalid
  6644       // one we can identify: pinned without old or humongous set.
  6643       // one we can identify: pinned without old or humongous set.
  6645       assert(!hr->is_pinned(), err_msg("Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index()));
  6644       assert(!hr->is_pinned(), "Heap region %u is pinned but not old (archive) or humongous.", hr->hrm_index());
  6646       ShouldNotReachHere();
  6645       ShouldNotReachHere();
  6647     }
  6646     }
  6648     return false;
  6647     return false;
  6649   }
  6648   }
  6650 
  6649 
  6651   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
  6650   void verify_counts(HeapRegionSet* old_set, HeapRegionSet* humongous_set, HeapRegionManager* free_list) {
  6652     guarantee(old_set->length() == _old_count.length(), err_msg("Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count.length()));
  6651     guarantee(old_set->length() == _old_count.length(), "Old set count mismatch. Expected %u, actual %u.", old_set->length(), _old_count.length());
  6653     guarantee(old_set->total_capacity_bytes() == _old_count.capacity(), err_msg("Old set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6652     guarantee(old_set->total_capacity_bytes() == _old_count.capacity(), "Old set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6654         old_set->total_capacity_bytes(), _old_count.capacity()));
  6653               old_set->total_capacity_bytes(), _old_count.capacity());
  6655 
  6654 
  6656     guarantee(humongous_set->length() == _humongous_count.length(), err_msg("Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count.length()));
  6655     guarantee(humongous_set->length() == _humongous_count.length(), "Hum set count mismatch. Expected %u, actual %u.", humongous_set->length(), _humongous_count.length());
  6657     guarantee(humongous_set->total_capacity_bytes() == _humongous_count.capacity(), err_msg("Hum set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6656     guarantee(humongous_set->total_capacity_bytes() == _humongous_count.capacity(), "Hum set capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6658         humongous_set->total_capacity_bytes(), _humongous_count.capacity()));
  6657               humongous_set->total_capacity_bytes(), _humongous_count.capacity());
  6659 
  6658 
  6660     guarantee(free_list->num_free_regions() == _free_count.length(), err_msg("Free list count mismatch. Expected %u, actual %u.", free_list->num_free_regions(), _free_count.length()));
  6659     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());
  6661     guarantee(free_list->total_capacity_bytes() == _free_count.capacity(), err_msg("Free list capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6660     guarantee(free_list->total_capacity_bytes() == _free_count.capacity(), "Free list capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
  6662         free_list->total_capacity_bytes(), _free_count.capacity()));
  6661               free_list->total_capacity_bytes(), _free_count.capacity());
  6663   }
  6662   }
  6664 };
  6663 };
  6665 
  6664 
  6666 void G1CollectedHeap::verify_region_sets() {
  6665 void G1CollectedHeap::verify_region_sets() {
  6667   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
  6666   assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
  6713     T heap_oop = oopDesc::load_heap_oop(p);
  6712     T heap_oop = oopDesc::load_heap_oop(p);
  6714     if (!oopDesc::is_null(heap_oop)) {
  6713     if (!oopDesc::is_null(heap_oop)) {
  6715       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  6714       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  6716       HeapRegion* hr = _g1h->heap_region_containing(obj);
  6715       HeapRegion* hr = _g1h->heap_region_containing(obj);
  6717       assert(!hr->is_continues_humongous(),
  6716       assert(!hr->is_continues_humongous(),
  6718              err_msg("trying to add code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
  6717              "trying to add code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
  6719                      " starting at " HR_FORMAT,
  6718              " starting at " HR_FORMAT,
  6720                      p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
  6719              p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()));
  6721 
  6720 
  6722       // HeapRegion::add_strong_code_root_locked() avoids adding duplicate entries.
  6721       // HeapRegion::add_strong_code_root_locked() avoids adding duplicate entries.
  6723       hr->add_strong_code_root_locked(_nm);
  6722       hr->add_strong_code_root_locked(_nm);
  6724     }
  6723     }
  6725   }
  6724   }
  6740     T heap_oop = oopDesc::load_heap_oop(p);
  6739     T heap_oop = oopDesc::load_heap_oop(p);
  6741     if (!oopDesc::is_null(heap_oop)) {
  6740     if (!oopDesc::is_null(heap_oop)) {
  6742       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  6741       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  6743       HeapRegion* hr = _g1h->heap_region_containing(obj);
  6742       HeapRegion* hr = _g1h->heap_region_containing(obj);
  6744       assert(!hr->is_continues_humongous(),
  6743       assert(!hr->is_continues_humongous(),
  6745              err_msg("trying to remove code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
  6744              "trying to remove code root " PTR_FORMAT " in continuation of humongous region " HR_FORMAT
  6746                      " starting at " HR_FORMAT,
  6745              " starting at " HR_FORMAT,
  6747                      p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region())));
  6746              p2i(_nm), HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()));
  6748 
  6747 
  6749       hr->remove_strong_code_root(_nm);
  6748       hr->remove_strong_code_root(_nm);
  6750     }
  6749     }
  6751   }
  6750   }
  6752 
  6751