annotate hotspot/src/share/vm/gc/g1/g1CardCounts.cpp @ 30764:fec48bf5a827

8079792: GC directory structure cleanup Reviewed-by: brutisso, stefank, david
author pliden
date Wed, 13 May 2015 15:16:06 +0200
parents hotspot/src/share/vm/gc_implementation/g1/g1CardCounts.cpp@ebd5af27fe02
children 43f48e165466
rev   line source
johnc@17327 1 /*
tschatzl@30565 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
johnc@17327 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
johnc@17327 4 *
johnc@17327 5 * This code is free software; you can redistribute it and/or modify it
johnc@17327 6 * under the terms of the GNU General Public License version 2 only, as
johnc@17327 7 * published by the Free Software Foundation.
johnc@17327 8 *
johnc@17327 9 * This code is distributed in the hope that it will be useful, but WITHOUT
johnc@17327 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
johnc@17327 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
johnc@17327 12 * version 2 for more details (a copy is included in the LICENSE file that
johnc@17327 13 * accompanied this code).
johnc@17327 14 *
johnc@17327 15 * You should have received a copy of the GNU General Public License version
johnc@17327 16 * 2 along with this work; if not, write to the Free Software Foundation,
johnc@17327 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
johnc@17327 18 *
johnc@17327 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
johnc@17327 20 * or visit www.oracle.com if you need additional information or have any
johnc@17327 21 * questions.
johnc@17327 22 *
johnc@17327 23 */
johnc@17327 24
johnc@17327 25 #include "precompiled.hpp"
pliden@30764 26 #include "gc/g1/g1CardCounts.hpp"
pliden@30764 27 #include "gc/g1/g1CollectedHeap.inline.hpp"
pliden@30764 28 #include "gc/g1/g1CollectorPolicy.hpp"
pliden@30764 29 #include "gc/g1/g1GCPhaseTimes.hpp"
pliden@30764 30 #include "gc/shared/cardTableModRefBS.hpp"
johnc@17327 31 #include "services/memTracker.hpp"
johnc@17327 32 #include "utilities/copy.hpp"
johnc@17327 33
tschatzl@27149 34 void G1CardCountsMappingChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
tschatzl@27149 35 if (zero_filled) {
tschatzl@27149 36 return;
tschatzl@27149 37 }
tschatzl@26160 38 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
tschatzl@26160 39 _counts->clear_range(mr);
tschatzl@26160 40 }
tschatzl@26160 41
tschatzl@30565 42 size_t G1CardCounts::compute_size(size_t mem_region_size_in_words) {
tschatzl@30565 43 // We keep card counts for every card, so the size of the card counts table must
tschatzl@30565 44 // be the same as the card table.
tschatzl@30565 45 return G1SATBCardTableLoggingModRefBS::compute_size(mem_region_size_in_words);
tschatzl@30565 46 }
tschatzl@30565 47
tschatzl@30565 48 size_t G1CardCounts::heap_map_factor() {
tschatzl@30565 49 // See G1CardCounts::compute_size() why we reuse the card table value.
tschatzl@30565 50 return G1SATBCardTableLoggingModRefBS::heap_map_factor();
tschatzl@30565 51 }
tschatzl@30565 52
johnc@17327 53 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
johnc@17327 54 if (has_count_table()) {
johnc@17327 55 assert(from_card_num < to_card_num,
johnc@17327 56 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT,
johnc@17327 57 from_card_num, to_card_num));
johnc@17327 58 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
johnc@17327 59 }
johnc@17327 60 }
johnc@17327 61
johnc@17327 62 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
tschatzl@26160 63 _listener(), _g1h(g1h), _card_counts(NULL), _reserved_max_card_num(0) {
tschatzl@26160 64 _listener.set_cardcounts(this);
tschatzl@26160 65 }
johnc@17327 66
tschatzl@26160 67 void G1CardCounts::initialize(G1RegionToSpaceMapper* mapper) {
johnc@17327 68 assert(_g1h->max_capacity() > 0, "initialization order");
johnc@17327 69 assert(_g1h->capacity() == 0, "initialization order");
johnc@17327 70
johnc@17327 71 if (G1ConcRSHotCardLimit > 0) {
johnc@17327 72 // The max value we can store in the counts table is
johnc@17327 73 // max_jubyte. Guarantee the value of the hot
johnc@17327 74 // threshold limit is no more than this.
johnc@17327 75 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
johnc@17327 76
mgerdin@20309 77 _ct_bs = _g1h->g1_barrier_set();
johnc@17327 78 _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start());
johnc@17327 79
tschatzl@26160 80 _card_counts = (jubyte*) mapper->reserved().start();
tschatzl@26160 81 _reserved_max_card_num = mapper->reserved().byte_size();
tschatzl@26160 82 mapper->set_mapping_changed_listener(&_listener);
johnc@17327 83 }
johnc@17327 84 }
johnc@17327 85
johnc@17327 86 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
johnc@17327 87 // Returns the number of times the card has been refined.
johnc@17327 88 // If we failed to reserve/commit the counts table, return 0.
johnc@17327 89 // If card_ptr is beyond the committed end of the counts table,
johnc@17327 90 // return 0.
johnc@17327 91 // Otherwise return the actual count.
johnc@17327 92 // Unless G1ConcRSHotCardLimit has been set appropriately,
johnc@17327 93 // returning 0 will result in the card being considered
johnc@17327 94 // cold and will be refined immediately.
johnc@17327 95 uint count = 0;
johnc@17327 96 if (has_count_table()) {
johnc@17327 97 size_t card_num = ptr_2_card_num(card_ptr);
tschatzl@26160 98 assert(card_num < _reserved_max_card_num,
tschatzl@26160 99 err_msg("Card "SIZE_FORMAT" outside of card counts table (max size "SIZE_FORMAT")",
tschatzl@26160 100 card_num, _reserved_max_card_num));
tschatzl@26160 101 count = (uint) _card_counts[card_num];
tschatzl@26160 102 if (count < G1ConcRSHotCardLimit) {
tschatzl@26160 103 _card_counts[card_num] =
tschatzl@26160 104 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
johnc@17327 105 }
johnc@17327 106 }
johnc@17327 107 return count;
johnc@17327 108 }
johnc@17327 109
johnc@17327 110 bool G1CardCounts::is_hot(uint count) {
johnc@17327 111 return (count >= G1ConcRSHotCardLimit);
johnc@17327 112 }
johnc@17327 113
johnc@17327 114 void G1CardCounts::clear_region(HeapRegion* hr) {
tschatzl@26160 115 MemRegion mr(hr->bottom(), hr->end());
tschatzl@26160 116 clear_range(mr);
tschatzl@26160 117 }
tschatzl@26160 118
tschatzl@26160 119 void G1CardCounts::clear_range(MemRegion mr) {
johnc@17327 120 if (has_count_table()) {
tschatzl@26160 121 const jbyte* from_card_ptr = _ct_bs->byte_for_const(mr.start());
tschatzl@26160 122 // We use the last address in the range as the range could represent the
tschatzl@26160 123 // last region in the heap. In which case trying to find the card will be an
tschatzl@26160 124 // OOB access to the card table.
tschatzl@26160 125 const jbyte* last_card_ptr = _ct_bs->byte_for_const(mr.last());
johnc@17327 126
johnc@17327 127 #ifdef ASSERT
johnc@17327 128 HeapWord* start_addr = _ct_bs->addr_for(from_card_ptr);
tschatzl@26160 129 assert(start_addr == mr.start(), "MemRegion start must be aligned to a card.");
johnc@17327 130 HeapWord* last_addr = _ct_bs->addr_for(last_card_ptr);
tschatzl@26160 131 assert((last_addr + CardTableModRefBS::card_size_in_words) == mr.end(), "MemRegion end must be aligned to a card.");
johnc@17327 132 #endif // ASSERT
johnc@17327 133
johnc@17327 134 // Clear the counts for the (exclusive) card range.
johnc@17327 135 size_t from_card_num = ptr_2_card_num(from_card_ptr);
johnc@17327 136 size_t to_card_num = ptr_2_card_num(last_card_ptr) + 1;
johnc@17327 137 clear_range(from_card_num, to_card_num);
johnc@17327 138 }
johnc@17327 139 }
johnc@17327 140
tschatzl@26160 141 class G1CardCountsClearClosure : public HeapRegionClosure {
tschatzl@26160 142 private:
tschatzl@26160 143 G1CardCounts* _card_counts;
tschatzl@26160 144 public:
tschatzl@26160 145 G1CardCountsClearClosure(G1CardCounts* card_counts) :
tschatzl@26160 146 HeapRegionClosure(), _card_counts(card_counts) { }
tschatzl@26160 147
tschatzl@26160 148
tschatzl@26160 149 virtual bool doHeapRegion(HeapRegion* r) {
tschatzl@26160 150 _card_counts->clear_region(r);
tschatzl@26160 151 return false;
tschatzl@26160 152 }
tschatzl@26160 153 };
tschatzl@26160 154
johnc@17327 155 void G1CardCounts::clear_all() {
johnc@17327 156 assert(SafepointSynchronize::is_at_safepoint(), "don't call this otherwise");
tschatzl@26160 157 G1CardCountsClearClosure cl(this);
tschatzl@26160 158 _g1h->heap_region_iterate(&cl);
johnc@17327 159 }