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

Fri, 11 Apr 2014 11:00:12 +0200

author
pliden
date
Fri, 11 Apr 2014 11:00:12 +0200
changeset 6690
1772223a25a2
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 7051
1f1d373cd044
permissions
-rw-r--r--

8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
Reviewed-by: brutisso, mgerdin

johnc@5078 1 /*
drchase@6680 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
johnc@5078 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
johnc@5078 4 *
johnc@5078 5 * This code is free software; you can redistribute it and/or modify it
johnc@5078 6 * under the terms of the GNU General Public License version 2 only, as
johnc@5078 7 * published by the Free Software Foundation.
johnc@5078 8 *
johnc@5078 9 * This code is distributed in the hope that it will be useful, but WITHOUT
johnc@5078 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
johnc@5078 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
johnc@5078 12 * version 2 for more details (a copy is included in the LICENSE file that
johnc@5078 13 * accompanied this code).
johnc@5078 14 *
johnc@5078 15 * You should have received a copy of the GNU General Public License version
johnc@5078 16 * 2 along with this work; if not, write to the Free Software Foundation,
johnc@5078 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
johnc@5078 18 *
johnc@5078 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
johnc@5078 20 * or visit www.oracle.com if you need additional information or have any
johnc@5078 21 * questions.
johnc@5078 22 *
johnc@5078 23 */
johnc@5078 24
johnc@5078 25 #include "precompiled.hpp"
johnc@5078 26 #include "gc_implementation/g1/g1CardCounts.hpp"
johnc@5078 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
johnc@5078 28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
johnc@5078 29 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
johnc@5078 30 #include "memory/cardTableModRefBS.hpp"
johnc@5078 31 #include "services/memTracker.hpp"
johnc@5078 32 #include "utilities/copy.hpp"
johnc@5078 33
drchase@6680 34 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 35
johnc@5078 36 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
johnc@5078 37 if (has_count_table()) {
shade@5709 38 assert(from_card_num >= 0 && from_card_num < _committed_max_card_num,
shade@5709 39 err_msg("from card num out of range: "SIZE_FORMAT, from_card_num));
johnc@5078 40 assert(from_card_num < to_card_num,
johnc@5078 41 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT,
johnc@5078 42 from_card_num, to_card_num));
johnc@5078 43 assert(to_card_num <= _committed_max_card_num,
johnc@5078 44 err_msg("to card num out of range: "
johnc@5078 45 "to: "SIZE_FORMAT ", "
johnc@5078 46 "max: "SIZE_FORMAT,
johnc@5078 47 to_card_num, _committed_max_card_num));
johnc@5078 48
johnc@5078 49 to_card_num = MIN2(_committed_max_card_num, to_card_num);
johnc@5078 50
johnc@5078 51 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
johnc@5078 52 }
johnc@5078 53 }
johnc@5078 54
johnc@5078 55 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
johnc@5078 56 _g1h(g1h), _card_counts(NULL),
johnc@5078 57 _reserved_max_card_num(0), _committed_max_card_num(0),
johnc@5078 58 _committed_size(0) {}
johnc@5078 59
johnc@5078 60 void G1CardCounts::initialize() {
johnc@5078 61 assert(_g1h->max_capacity() > 0, "initialization order");
johnc@5078 62 assert(_g1h->capacity() == 0, "initialization order");
johnc@5078 63
johnc@5078 64 if (G1ConcRSHotCardLimit > 0) {
johnc@5078 65 // The max value we can store in the counts table is
johnc@5078 66 // max_jubyte. Guarantee the value of the hot
johnc@5078 67 // threshold limit is no more than this.
johnc@5078 68 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
johnc@5078 69
mgerdin@5811 70 _ct_bs = _g1h->g1_barrier_set();
johnc@5078 71 _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start());
johnc@5078 72
johnc@5078 73 // Allocate/Reserve the counts table
johnc@5078 74 size_t reserved_bytes = _g1h->max_capacity();
johnc@5078 75 _reserved_max_card_num = reserved_bytes >> CardTableModRefBS::card_shift;
johnc@5078 76
johnc@5078 77 size_t reserved_size = _reserved_max_card_num * sizeof(jbyte);
johnc@5078 78 ReservedSpace rs(ReservedSpace::allocation_align_size_up(reserved_size));
johnc@5078 79 if (!rs.is_reserved()) {
johnc@5078 80 warning("Could not reserve enough space for the card counts table");
johnc@5078 81 guarantee(!has_reserved_count_table(), "should be NULL");
johnc@5078 82 return;
johnc@5078 83 }
johnc@5078 84
johnc@5078 85 MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
johnc@5078 86
johnc@5078 87 _card_counts_storage.initialize(rs, 0);
johnc@5078 88 _card_counts = (jubyte*) _card_counts_storage.low();
johnc@5078 89 }
johnc@5078 90 }
johnc@5078 91
johnc@5078 92 void G1CardCounts::resize(size_t heap_capacity) {
johnc@5078 93 // Expand the card counts table to handle a heap with the given capacity.
johnc@5078 94
johnc@5078 95 if (!has_reserved_count_table()) {
johnc@5078 96 // Don't expand if we failed to reserve the card counts table.
johnc@5078 97 return;
johnc@5078 98 }
johnc@5078 99
johnc@5078 100 assert(_committed_size ==
johnc@5078 101 ReservedSpace::allocation_align_size_up(_committed_size),
johnc@5078 102 err_msg("Unaligned? committed_size: " SIZE_FORMAT, _committed_size));
johnc@5078 103
johnc@5121 104 // Verify that the committed space for the card counts matches our
johnc@5121 105 // committed max card num. Note for some allocation alignments, the
johnc@5121 106 // amount of space actually committed for the counts table will be able
johnc@5121 107 // to span more cards than the number spanned by the maximum heap.
johnc@5078 108 size_t prev_committed_size = _committed_size;
johnc@5121 109 size_t prev_committed_card_num = committed_to_card_num(prev_committed_size);
johnc@5121 110
johnc@5078 111 assert(prev_committed_card_num == _committed_max_card_num,
johnc@5078 112 err_msg("Card mismatch: "
johnc@5078 113 "prev: " SIZE_FORMAT ", "
johnc@5121 114 "committed: "SIZE_FORMAT", "
johnc@5121 115 "reserved: "SIZE_FORMAT,
johnc@5121 116 prev_committed_card_num, _committed_max_card_num, _reserved_max_card_num));
johnc@5078 117
johnc@5078 118 size_t new_size = (heap_capacity >> CardTableModRefBS::card_shift) * sizeof(jbyte);
johnc@5078 119 size_t new_committed_size = ReservedSpace::allocation_align_size_up(new_size);
johnc@5121 120 size_t new_committed_card_num = committed_to_card_num(new_committed_size);
johnc@5078 121
johnc@5078 122 if (_committed_max_card_num < new_committed_card_num) {
johnc@5078 123 // we need to expand the backing store for the card counts
johnc@5078 124 size_t expand_size = new_committed_size - prev_committed_size;
johnc@5078 125
johnc@5078 126 if (!_card_counts_storage.expand_by(expand_size)) {
johnc@5078 127 warning("Card counts table backing store commit failure");
johnc@5078 128 return;
johnc@5078 129 }
johnc@5078 130 assert(_card_counts_storage.committed_size() == new_committed_size,
johnc@5078 131 "expansion commit failure");
johnc@5078 132
johnc@5078 133 _committed_size = new_committed_size;
johnc@5078 134 _committed_max_card_num = new_committed_card_num;
johnc@5078 135
johnc@5078 136 clear_range(prev_committed_card_num, _committed_max_card_num);
johnc@5078 137 }
johnc@5078 138 }
johnc@5078 139
johnc@5078 140 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
johnc@5078 141 // Returns the number of times the card has been refined.
johnc@5078 142 // If we failed to reserve/commit the counts table, return 0.
johnc@5078 143 // If card_ptr is beyond the committed end of the counts table,
johnc@5078 144 // return 0.
johnc@5078 145 // Otherwise return the actual count.
johnc@5078 146 // Unless G1ConcRSHotCardLimit has been set appropriately,
johnc@5078 147 // returning 0 will result in the card being considered
johnc@5078 148 // cold and will be refined immediately.
johnc@5078 149 uint count = 0;
johnc@5078 150 if (has_count_table()) {
johnc@5078 151 size_t card_num = ptr_2_card_num(card_ptr);
johnc@5078 152 if (card_num < _committed_max_card_num) {
johnc@5078 153 count = (uint) _card_counts[card_num];
johnc@5078 154 if (count < G1ConcRSHotCardLimit) {
johnc@5342 155 _card_counts[card_num] =
johnc@5342 156 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
johnc@5078 157 }
johnc@5078 158 }
johnc@5078 159 }
johnc@5078 160 return count;
johnc@5078 161 }
johnc@5078 162
johnc@5078 163 bool G1CardCounts::is_hot(uint count) {
johnc@5078 164 return (count >= G1ConcRSHotCardLimit);
johnc@5078 165 }
johnc@5078 166
johnc@5078 167 void G1CardCounts::clear_region(HeapRegion* hr) {
johnc@5078 168 assert(!hr->isHumongous(), "Should have been cleared");
johnc@5078 169 if (has_count_table()) {
johnc@5078 170 HeapWord* bottom = hr->bottom();
johnc@5078 171
johnc@5078 172 // We use the last address in hr as hr could be the
johnc@5078 173 // last region in the heap. In which case trying to find
johnc@5078 174 // the card for hr->end() will be an OOB accesss to the
johnc@5078 175 // card table.
johnc@5078 176 HeapWord* last = hr->end() - 1;
johnc@5078 177 assert(_g1h->g1_committed().contains(last),
johnc@5078 178 err_msg("last not in committed: "
johnc@5078 179 "last: " PTR_FORMAT ", "
johnc@5078 180 "committed: [" PTR_FORMAT ", " PTR_FORMAT ")",
johnc@5078 181 last,
johnc@5078 182 _g1h->g1_committed().start(),
johnc@5078 183 _g1h->g1_committed().end()));
johnc@5078 184
johnc@5078 185 const jbyte* from_card_ptr = _ct_bs->byte_for_const(bottom);
johnc@5078 186 const jbyte* last_card_ptr = _ct_bs->byte_for_const(last);
johnc@5078 187
johnc@5078 188 #ifdef ASSERT
johnc@5078 189 HeapWord* start_addr = _ct_bs->addr_for(from_card_ptr);
johnc@5078 190 assert(start_addr == hr->bottom(), "alignment");
johnc@5078 191 HeapWord* last_addr = _ct_bs->addr_for(last_card_ptr);
johnc@5078 192 assert((last_addr + CardTableModRefBS::card_size_in_words) == hr->end(), "alignment");
johnc@5078 193 #endif // ASSERT
johnc@5078 194
johnc@5078 195 // Clear the counts for the (exclusive) card range.
johnc@5078 196 size_t from_card_num = ptr_2_card_num(from_card_ptr);
johnc@5078 197 size_t to_card_num = ptr_2_card_num(last_card_ptr) + 1;
johnc@5078 198 clear_range(from_card_num, to_card_num);
johnc@5078 199 }
johnc@5078 200 }
johnc@5078 201
johnc@5078 202 void G1CardCounts::clear_all() {
johnc@5078 203 assert(SafepointSynchronize::is_at_safepoint(), "don't call this otherwise");
johnc@5078 204 clear_range((size_t)0, _committed_max_card_num);
johnc@5078 205 }
johnc@5078 206
johnc@5078 207 G1CardCounts::~G1CardCounts() {
johnc@5078 208 if (has_reserved_count_table()) {
johnc@5078 209 _card_counts_storage.release();
johnc@5078 210 }
johnc@5078 211 }
johnc@5078 212

mercurial