src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

Print this page
rev 2722 : 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
Summary: Declare GrainBytes, GrainWords, and CardsPerRegion as size_t.
Reviewed-by:


 535                                "allocated "HR_FORMAT" from secondary_free_list",
 536                                HR_FORMAT_PARAMS(res));
 537       }
 538       return res;
 539     }
 540 
 541     // Wait here until we get notifed either when (a) there are no
 542     // more free regions coming or (b) some regions have been moved on
 543     // the secondary_free_list.
 544     SecondaryFreeList_lock->wait(Mutex::_no_safepoint_check_flag);
 545   }
 546 
 547   if (G1ConcRegionFreeingVerbose) {
 548     gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
 549                            "could not allocate from secondary_free_list");
 550   }
 551   return NULL;
 552 }
 553 
 554 HeapRegion* G1CollectedHeap::new_region(size_t word_size, bool do_expand) {
 555   assert(!isHumongous(word_size) ||
 556                                   word_size <= (size_t) HeapRegion::GrainWords,
 557          "the only time we use this to allocate a humongous region is "
 558          "when we are allocating a single humongous region");
 559 
 560   HeapRegion* res;
 561   if (G1StressConcRegionFreeing) {
 562     if (!_secondary_free_list.is_empty()) {
 563       if (G1ConcRegionFreeingVerbose) {
 564         gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
 565                                "forced to look at the secondary_free_list");
 566       }
 567       res = new_region_try_secondary_free_list();
 568       if (res != NULL) {
 569         return res;
 570       }
 571     }
 572   }
 573   res = _free_list.remove_head_or_null();
 574   if (res == NULL) {
 575     if (G1ConcRegionFreeingVerbose) {
 576       gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "


1153   { }
1154 
1155   void work(int i) {
1156     RebuildRSOutOfRegionClosure rebuild_rs(_g1, i);
1157     _g1->heap_region_par_iterate_chunked(&rebuild_rs, i,
1158                                          HeapRegion::RebuildRSClaimValue);
1159   }
1160 };
1161 
1162 class PostCompactionPrinterClosure: public HeapRegionClosure {
1163 private:
1164   G1HRPrinter* _hr_printer;
1165 public:
1166   bool doHeapRegion(HeapRegion* hr) {
1167     assert(!hr->is_young(), "not expecting to find young regions");
1168     // We only generate output for non-empty regions.
1169     if (!hr->is_empty()) {
1170       if (!hr->isHumongous()) {
1171         _hr_printer->post_compaction(hr, G1HRPrinter::Old);
1172       } else if (hr->startsHumongous()) {
1173         if (hr->capacity() == (size_t) HeapRegion::GrainBytes) {
1174           // single humongous region
1175           _hr_printer->post_compaction(hr, G1HRPrinter::SingleHumongous);
1176         } else {
1177           _hr_printer->post_compaction(hr, G1HRPrinter::StartsHumongous);
1178         }
1179       } else {
1180         assert(hr->continuesHumongous(), "only way to get here");
1181         _hr_printer->post_compaction(hr, G1HRPrinter::ContinuesHumongous);
1182       }
1183     }
1184     return false;
1185   }
1186 
1187   PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
1188     : _hr_printer(hr_printer) { }
1189 };
1190 
1191 bool G1CollectedHeap::do_collection(bool explicit_gc,
1192                                     bool clear_all_soft_refs,
1193                                     size_t word_size) {


1954   ReservedSpace g1_rs   = heap_rs.first_part(max_byte_size);
1955   _g1_reserved = MemRegion((HeapWord*)g1_rs.base(),
1956                            g1_rs.size()/HeapWordSize);
1957   ReservedSpace perm_gen_rs = heap_rs.last_part(max_byte_size);
1958 
1959   _perm_gen = pgs->init(perm_gen_rs, pgs->init_size(), rem_set());
1960 
1961   _g1_storage.initialize(g1_rs, 0);
1962   _g1_committed = MemRegion((HeapWord*)_g1_storage.low(), (size_t) 0);
1963   _hrs.initialize((HeapWord*) _g1_reserved.start(),
1964                   (HeapWord*) _g1_reserved.end(),
1965                   _expansion_regions);
1966 
1967   // 6843694 - ensure that the maximum region index can fit
1968   // in the remembered set structures.
1969   const size_t max_region_idx = ((size_t)1 << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
1970   guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
1971 
1972   size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
1973   guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
1974   guarantee((size_t) HeapRegion::CardsPerRegion < max_cards_per_region,
1975             "too many cards per region");
1976 
1977   HeapRegionSet::set_unrealistically_long_length(max_regions() + 1);
1978 
1979   _bot_shared = new G1BlockOffsetSharedArray(_reserved,
1980                                              heap_word_size(init_byte_size));
1981 
1982   _g1h = this;
1983 
1984    _in_cset_fast_test_length = max_regions();
1985    _in_cset_fast_test_base = NEW_C_HEAP_ARRAY(bool, _in_cset_fast_test_length);
1986 
1987    // We're biasing _in_cset_fast_test to avoid subtracting the
1988    // beginning of the heap every time we want to index; basically
1989    // it's the same with what we do with the card table.
1990    _in_cset_fast_test = _in_cset_fast_test_base -
1991                 ((size_t) _g1_reserved.start() >> HeapRegion::LogOfHRGrainBytes);
1992 
1993    // Clear the _cset_fast_test bitmap in anticipation of adding
1994    // regions to the incremental collection set for the first


3034     r->print_on(_st);
3035     return false;
3036   }
3037 };
3038 
3039 void G1CollectedHeap::print() const { print_on(tty); }
3040 
3041 void G1CollectedHeap::print_on(outputStream* st) const {
3042   print_on(st, PrintHeapAtGCExtended);
3043 }
3044 
3045 void G1CollectedHeap::print_on(outputStream* st, bool extended) const {
3046   st->print(" %-20s", "garbage-first heap");
3047   st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
3048             capacity()/K, used_unlocked()/K);
3049   st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
3050             _g1_storage.low_boundary(),
3051             _g1_storage.high(),
3052             _g1_storage.high_boundary());
3053   st->cr();
3054   st->print("  region size " SIZE_FORMAT "K, ",
3055             HeapRegion::GrainBytes/K);
3056   size_t young_regions = _young_list->length();
3057   st->print(SIZE_FORMAT " young (" SIZE_FORMAT "K), ",
3058             young_regions, young_regions * HeapRegion::GrainBytes / K);
3059   size_t survivor_regions = g1_policy()->recorded_survivor_regions();
3060   st->print(SIZE_FORMAT " survivors (" SIZE_FORMAT "K)",
3061             survivor_regions, survivor_regions * HeapRegion::GrainBytes / K);
3062   st->cr();
3063   perm()->as_gen()->print_on(st);
3064   if (extended) {
3065     st->cr();
3066     print_on_extended(st);
3067   }
3068 }
3069 
3070 void G1CollectedHeap::print_on_extended(outputStream* st) const {
3071   PrintRegionClosure blk(st);
3072   heap_region_iterate(&blk);
3073 }
3074 
3075 void G1CollectedHeap::print_gc_threads_on(outputStream* st) const {




 535                                "allocated "HR_FORMAT" from secondary_free_list",
 536                                HR_FORMAT_PARAMS(res));
 537       }
 538       return res;
 539     }
 540 
 541     // Wait here until we get notifed either when (a) there are no
 542     // more free regions coming or (b) some regions have been moved on
 543     // the secondary_free_list.
 544     SecondaryFreeList_lock->wait(Mutex::_no_safepoint_check_flag);
 545   }
 546 
 547   if (G1ConcRegionFreeingVerbose) {
 548     gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
 549                            "could not allocate from secondary_free_list");
 550   }
 551   return NULL;
 552 }
 553 
 554 HeapRegion* G1CollectedHeap::new_region(size_t word_size, bool do_expand) {
 555   assert(!isHumongous(word_size) || word_size <= HeapRegion::GrainWords,

 556          "the only time we use this to allocate a humongous region is "
 557          "when we are allocating a single humongous region");
 558 
 559   HeapRegion* res;
 560   if (G1StressConcRegionFreeing) {
 561     if (!_secondary_free_list.is_empty()) {
 562       if (G1ConcRegionFreeingVerbose) {
 563         gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "
 564                                "forced to look at the secondary_free_list");
 565       }
 566       res = new_region_try_secondary_free_list();
 567       if (res != NULL) {
 568         return res;
 569       }
 570     }
 571   }
 572   res = _free_list.remove_head_or_null();
 573   if (res == NULL) {
 574     if (G1ConcRegionFreeingVerbose) {
 575       gclog_or_tty->print_cr("G1ConcRegionFreeing [region alloc] : "


1152   { }
1153 
1154   void work(int i) {
1155     RebuildRSOutOfRegionClosure rebuild_rs(_g1, i);
1156     _g1->heap_region_par_iterate_chunked(&rebuild_rs, i,
1157                                          HeapRegion::RebuildRSClaimValue);
1158   }
1159 };
1160 
1161 class PostCompactionPrinterClosure: public HeapRegionClosure {
1162 private:
1163   G1HRPrinter* _hr_printer;
1164 public:
1165   bool doHeapRegion(HeapRegion* hr) {
1166     assert(!hr->is_young(), "not expecting to find young regions");
1167     // We only generate output for non-empty regions.
1168     if (!hr->is_empty()) {
1169       if (!hr->isHumongous()) {
1170         _hr_printer->post_compaction(hr, G1HRPrinter::Old);
1171       } else if (hr->startsHumongous()) {
1172         if (hr->capacity() == HeapRegion::GrainBytes) {
1173           // single humongous region
1174           _hr_printer->post_compaction(hr, G1HRPrinter::SingleHumongous);
1175         } else {
1176           _hr_printer->post_compaction(hr, G1HRPrinter::StartsHumongous);
1177         }
1178       } else {
1179         assert(hr->continuesHumongous(), "only way to get here");
1180         _hr_printer->post_compaction(hr, G1HRPrinter::ContinuesHumongous);
1181       }
1182     }
1183     return false;
1184   }
1185 
1186   PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
1187     : _hr_printer(hr_printer) { }
1188 };
1189 
1190 bool G1CollectedHeap::do_collection(bool explicit_gc,
1191                                     bool clear_all_soft_refs,
1192                                     size_t word_size) {


1953   ReservedSpace g1_rs   = heap_rs.first_part(max_byte_size);
1954   _g1_reserved = MemRegion((HeapWord*)g1_rs.base(),
1955                            g1_rs.size()/HeapWordSize);
1956   ReservedSpace perm_gen_rs = heap_rs.last_part(max_byte_size);
1957 
1958   _perm_gen = pgs->init(perm_gen_rs, pgs->init_size(), rem_set());
1959 
1960   _g1_storage.initialize(g1_rs, 0);
1961   _g1_committed = MemRegion((HeapWord*)_g1_storage.low(), (size_t) 0);
1962   _hrs.initialize((HeapWord*) _g1_reserved.start(),
1963                   (HeapWord*) _g1_reserved.end(),
1964                   _expansion_regions);
1965 
1966   // 6843694 - ensure that the maximum region index can fit
1967   // in the remembered set structures.
1968   const size_t max_region_idx = ((size_t)1 << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
1969   guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
1970 
1971   size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
1972   guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
1973   guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
1974             "too many cards per region");
1975 
1976   HeapRegionSet::set_unrealistically_long_length(max_regions() + 1);
1977 
1978   _bot_shared = new G1BlockOffsetSharedArray(_reserved,
1979                                              heap_word_size(init_byte_size));
1980 
1981   _g1h = this;
1982 
1983    _in_cset_fast_test_length = max_regions();
1984    _in_cset_fast_test_base = NEW_C_HEAP_ARRAY(bool, _in_cset_fast_test_length);
1985 
1986    // We're biasing _in_cset_fast_test to avoid subtracting the
1987    // beginning of the heap every time we want to index; basically
1988    // it's the same with what we do with the card table.
1989    _in_cset_fast_test = _in_cset_fast_test_base -
1990                 ((size_t) _g1_reserved.start() >> HeapRegion::LogOfHRGrainBytes);
1991 
1992    // Clear the _cset_fast_test bitmap in anticipation of adding
1993    // regions to the incremental collection set for the first


3033     r->print_on(_st);
3034     return false;
3035   }
3036 };
3037 
3038 void G1CollectedHeap::print() const { print_on(tty); }
3039 
3040 void G1CollectedHeap::print_on(outputStream* st) const {
3041   print_on(st, PrintHeapAtGCExtended);
3042 }
3043 
3044 void G1CollectedHeap::print_on(outputStream* st, bool extended) const {
3045   st->print(" %-20s", "garbage-first heap");
3046   st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
3047             capacity()/K, used_unlocked()/K);
3048   st->print(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
3049             _g1_storage.low_boundary(),
3050             _g1_storage.high(),
3051             _g1_storage.high_boundary());
3052   st->cr();
3053   st->print("  region size " SIZE_FORMAT "K, ", HeapRegion::GrainBytes / K);

3054   size_t young_regions = _young_list->length();
3055   st->print(SIZE_FORMAT " young (" SIZE_FORMAT "K), ",
3056             young_regions, young_regions * HeapRegion::GrainBytes / K);
3057   size_t survivor_regions = g1_policy()->recorded_survivor_regions();
3058   st->print(SIZE_FORMAT " survivors (" SIZE_FORMAT "K)",
3059             survivor_regions, survivor_regions * HeapRegion::GrainBytes / K);
3060   st->cr();
3061   perm()->as_gen()->print_on(st);
3062   if (extended) {
3063     st->cr();
3064     print_on_extended(st);
3065   }
3066 }
3067 
3068 void G1CollectedHeap::print_on_extended(outputStream* st) const {
3069   PrintRegionClosure blk(st);
3070   heap_region_iterate(&blk);
3071 }
3072 
3073 void G1CollectedHeap::print_gc_threads_on(outputStream* st) const {