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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
child 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
aoqi@0 36 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
aoqi@0 37 if (has_count_table()) {
aoqi@0 38 assert(from_card_num >= 0 && from_card_num < _committed_max_card_num,
aoqi@0 39 err_msg("from card num out of range: "SIZE_FORMAT, from_card_num));
aoqi@0 40 assert(from_card_num < to_card_num,
aoqi@0 41 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT,
aoqi@0 42 from_card_num, to_card_num));
aoqi@0 43 assert(to_card_num <= _committed_max_card_num,
aoqi@0 44 err_msg("to card num out of range: "
aoqi@0 45 "to: "SIZE_FORMAT ", "
aoqi@0 46 "max: "SIZE_FORMAT,
aoqi@0 47 to_card_num, _committed_max_card_num));
aoqi@0 48
aoqi@0 49 to_card_num = MIN2(_committed_max_card_num, to_card_num);
aoqi@0 50
aoqi@0 51 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
aoqi@0 52 }
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
aoqi@0 56 _g1h(g1h), _card_counts(NULL),
aoqi@0 57 _reserved_max_card_num(0), _committed_max_card_num(0),
aoqi@0 58 _committed_size(0) {}
aoqi@0 59
aoqi@0 60 void G1CardCounts::initialize() {
aoqi@0 61 assert(_g1h->max_capacity() > 0, "initialization order");
aoqi@0 62 assert(_g1h->capacity() == 0, "initialization order");
aoqi@0 63
aoqi@0 64 if (G1ConcRSHotCardLimit > 0) {
aoqi@0 65 // The max value we can store in the counts table is
aoqi@0 66 // max_jubyte. Guarantee the value of the hot
aoqi@0 67 // threshold limit is no more than this.
aoqi@0 68 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
aoqi@0 69
aoqi@0 70 _ct_bs = _g1h->g1_barrier_set();
aoqi@0 71 _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start());
aoqi@0 72
aoqi@0 73 // Allocate/Reserve the counts table
aoqi@0 74 size_t reserved_bytes = _g1h->max_capacity();
aoqi@0 75 _reserved_max_card_num = reserved_bytes >> CardTableModRefBS::card_shift;
aoqi@0 76
aoqi@0 77 size_t reserved_size = _reserved_max_card_num * sizeof(jbyte);
aoqi@0 78 ReservedSpace rs(ReservedSpace::allocation_align_size_up(reserved_size));
aoqi@0 79 if (!rs.is_reserved()) {
aoqi@0 80 warning("Could not reserve enough space for the card counts table");
aoqi@0 81 guarantee(!has_reserved_count_table(), "should be NULL");
aoqi@0 82 return;
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
aoqi@0 86
aoqi@0 87 _card_counts_storage.initialize(rs, 0);
aoqi@0 88 _card_counts = (jubyte*) _card_counts_storage.low();
aoqi@0 89 }
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 void G1CardCounts::resize(size_t heap_capacity) {
aoqi@0 93 // Expand the card counts table to handle a heap with the given capacity.
aoqi@0 94
aoqi@0 95 if (!has_reserved_count_table()) {
aoqi@0 96 // Don't expand if we failed to reserve the card counts table.
aoqi@0 97 return;
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 assert(_committed_size ==
aoqi@0 101 ReservedSpace::allocation_align_size_up(_committed_size),
aoqi@0 102 err_msg("Unaligned? committed_size: " SIZE_FORMAT, _committed_size));
aoqi@0 103
aoqi@0 104 // Verify that the committed space for the card counts matches our
aoqi@0 105 // committed max card num. Note for some allocation alignments, the
aoqi@0 106 // amount of space actually committed for the counts table will be able
aoqi@0 107 // to span more cards than the number spanned by the maximum heap.
aoqi@0 108 size_t prev_committed_size = _committed_size;
aoqi@0 109 size_t prev_committed_card_num = committed_to_card_num(prev_committed_size);
aoqi@0 110
aoqi@0 111 assert(prev_committed_card_num == _committed_max_card_num,
aoqi@0 112 err_msg("Card mismatch: "
aoqi@0 113 "prev: " SIZE_FORMAT ", "
aoqi@0 114 "committed: "SIZE_FORMAT", "
aoqi@0 115 "reserved: "SIZE_FORMAT,
aoqi@0 116 prev_committed_card_num, _committed_max_card_num, _reserved_max_card_num));
aoqi@0 117
aoqi@0 118 size_t new_size = (heap_capacity >> CardTableModRefBS::card_shift) * sizeof(jbyte);
aoqi@0 119 size_t new_committed_size = ReservedSpace::allocation_align_size_up(new_size);
aoqi@0 120 size_t new_committed_card_num = committed_to_card_num(new_committed_size);
aoqi@0 121
aoqi@0 122 if (_committed_max_card_num < new_committed_card_num) {
aoqi@0 123 // we need to expand the backing store for the card counts
aoqi@0 124 size_t expand_size = new_committed_size - prev_committed_size;
aoqi@0 125
aoqi@0 126 if (!_card_counts_storage.expand_by(expand_size)) {
aoqi@0 127 warning("Card counts table backing store commit failure");
aoqi@0 128 return;
aoqi@0 129 }
aoqi@0 130 assert(_card_counts_storage.committed_size() == new_committed_size,
aoqi@0 131 "expansion commit failure");
aoqi@0 132
aoqi@0 133 _committed_size = new_committed_size;
aoqi@0 134 _committed_max_card_num = new_committed_card_num;
aoqi@0 135
aoqi@0 136 clear_range(prev_committed_card_num, _committed_max_card_num);
aoqi@0 137 }
aoqi@0 138 }
aoqi@0 139
aoqi@0 140 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
aoqi@0 141 // Returns the number of times the card has been refined.
aoqi@0 142 // If we failed to reserve/commit the counts table, return 0.
aoqi@0 143 // If card_ptr is beyond the committed end of the counts table,
aoqi@0 144 // return 0.
aoqi@0 145 // Otherwise return the actual count.
aoqi@0 146 // Unless G1ConcRSHotCardLimit has been set appropriately,
aoqi@0 147 // returning 0 will result in the card being considered
aoqi@0 148 // cold and will be refined immediately.
aoqi@0 149 uint count = 0;
aoqi@0 150 if (has_count_table()) {
aoqi@0 151 size_t card_num = ptr_2_card_num(card_ptr);
aoqi@0 152 if (card_num < _committed_max_card_num) {
aoqi@0 153 count = (uint) _card_counts[card_num];
aoqi@0 154 if (count < G1ConcRSHotCardLimit) {
aoqi@0 155 _card_counts[card_num] =
aoqi@0 156 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
aoqi@0 157 }
aoqi@0 158 }
aoqi@0 159 }
aoqi@0 160 return count;
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 bool G1CardCounts::is_hot(uint count) {
aoqi@0 164 return (count >= G1ConcRSHotCardLimit);
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 void G1CardCounts::clear_region(HeapRegion* hr) {
aoqi@0 168 assert(!hr->isHumongous(), "Should have been cleared");
aoqi@0 169 if (has_count_table()) {
aoqi@0 170 HeapWord* bottom = hr->bottom();
aoqi@0 171
aoqi@0 172 // We use the last address in hr as hr could be the
aoqi@0 173 // last region in the heap. In which case trying to find
aoqi@0 174 // the card for hr->end() will be an OOB accesss to the
aoqi@0 175 // card table.
aoqi@0 176 HeapWord* last = hr->end() - 1;
aoqi@0 177 assert(_g1h->g1_committed().contains(last),
aoqi@0 178 err_msg("last not in committed: "
aoqi@0 179 "last: " PTR_FORMAT ", "
aoqi@0 180 "committed: [" PTR_FORMAT ", " PTR_FORMAT ")",
aoqi@0 181 last,
aoqi@0 182 _g1h->g1_committed().start(),
aoqi@0 183 _g1h->g1_committed().end()));
aoqi@0 184
aoqi@0 185 const jbyte* from_card_ptr = _ct_bs->byte_for_const(bottom);
aoqi@0 186 const jbyte* last_card_ptr = _ct_bs->byte_for_const(last);
aoqi@0 187
aoqi@0 188 #ifdef ASSERT
aoqi@0 189 HeapWord* start_addr = _ct_bs->addr_for(from_card_ptr);
aoqi@0 190 assert(start_addr == hr->bottom(), "alignment");
aoqi@0 191 HeapWord* last_addr = _ct_bs->addr_for(last_card_ptr);
aoqi@0 192 assert((last_addr + CardTableModRefBS::card_size_in_words) == hr->end(), "alignment");
aoqi@0 193 #endif // ASSERT
aoqi@0 194
aoqi@0 195 // Clear the counts for the (exclusive) card range.
aoqi@0 196 size_t from_card_num = ptr_2_card_num(from_card_ptr);
aoqi@0 197 size_t to_card_num = ptr_2_card_num(last_card_ptr) + 1;
aoqi@0 198 clear_range(from_card_num, to_card_num);
aoqi@0 199 }
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 void G1CardCounts::clear_all() {
aoqi@0 203 assert(SafepointSynchronize::is_at_safepoint(), "don't call this otherwise");
aoqi@0 204 clear_range((size_t)0, _committed_max_card_num);
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 G1CardCounts::~G1CardCounts() {
aoqi@0 208 if (has_reserved_count_table()) {
aoqi@0 209 _card_counts_storage.release();
aoqi@0 210 }
aoqi@0 211 }
aoqi@0 212

mercurial