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

Thu, 27 Dec 2018 11:43:33 +0800

author
aoqi
date
Thu, 27 Dec 2018 11:43:33 +0800
changeset 9448
73d689add964
parent 9327
f96fcd9e1e1b
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

Merge

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

mercurial