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

Thu, 21 Aug 2014 11:47:10 +0200

author
tschatzl
date
Thu, 21 Aug 2014 11:47:10 +0200
changeset 7051
1f1d373cd044
parent 6680
78bbf4d43a14
child 7257
e7d0505c8a30
permissions
-rw-r--r--

8038423: G1: Decommit memory within heap
Summary: Allow G1 to decommit memory of arbitrary regions within the heap and their associated auxiliary data structures card table, BOT, hot card cache, and mark bitmaps.
Reviewed-by: mgerdin, brutisso, jwilhelm

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
tschatzl@7051 36 void G1CardCountsMappingChangedListener::on_commit(uint start_idx, size_t num_regions) {
tschatzl@7051 37 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
tschatzl@7051 38 _counts->clear_range(mr);
tschatzl@7051 39 }
tschatzl@7051 40
johnc@5078 41 void G1CardCounts::clear_range(size_t from_card_num, size_t to_card_num) {
johnc@5078 42 if (has_count_table()) {
johnc@5078 43 assert(from_card_num < to_card_num,
johnc@5078 44 err_msg("Wrong order? from: " SIZE_FORMAT ", to: "SIZE_FORMAT,
johnc@5078 45 from_card_num, to_card_num));
johnc@5078 46 Copy::fill_to_bytes(&_card_counts[from_card_num], (to_card_num - from_card_num));
johnc@5078 47 }
johnc@5078 48 }
johnc@5078 49
johnc@5078 50 G1CardCounts::G1CardCounts(G1CollectedHeap *g1h):
tschatzl@7051 51 _listener(), _g1h(g1h), _card_counts(NULL), _reserved_max_card_num(0) {
tschatzl@7051 52 _listener.set_cardcounts(this);
tschatzl@7051 53 }
johnc@5078 54
tschatzl@7051 55 void G1CardCounts::initialize(G1RegionToSpaceMapper* mapper) {
johnc@5078 56 assert(_g1h->max_capacity() > 0, "initialization order");
johnc@5078 57 assert(_g1h->capacity() == 0, "initialization order");
johnc@5078 58
johnc@5078 59 if (G1ConcRSHotCardLimit > 0) {
johnc@5078 60 // The max value we can store in the counts table is
johnc@5078 61 // max_jubyte. Guarantee the value of the hot
johnc@5078 62 // threshold limit is no more than this.
johnc@5078 63 guarantee(G1ConcRSHotCardLimit <= max_jubyte, "sanity");
johnc@5078 64
mgerdin@5811 65 _ct_bs = _g1h->g1_barrier_set();
johnc@5078 66 _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start());
johnc@5078 67
tschatzl@7051 68 _card_counts = (jubyte*) mapper->reserved().start();
tschatzl@7051 69 _reserved_max_card_num = mapper->reserved().byte_size();
tschatzl@7051 70 mapper->set_mapping_changed_listener(&_listener);
johnc@5078 71 }
johnc@5078 72 }
johnc@5078 73
johnc@5078 74 uint G1CardCounts::add_card_count(jbyte* card_ptr) {
johnc@5078 75 // Returns the number of times the card has been refined.
johnc@5078 76 // If we failed to reserve/commit the counts table, return 0.
johnc@5078 77 // If card_ptr is beyond the committed end of the counts table,
johnc@5078 78 // return 0.
johnc@5078 79 // Otherwise return the actual count.
johnc@5078 80 // Unless G1ConcRSHotCardLimit has been set appropriately,
johnc@5078 81 // returning 0 will result in the card being considered
johnc@5078 82 // cold and will be refined immediately.
johnc@5078 83 uint count = 0;
johnc@5078 84 if (has_count_table()) {
johnc@5078 85 size_t card_num = ptr_2_card_num(card_ptr);
tschatzl@7051 86 assert(card_num < _reserved_max_card_num,
tschatzl@7051 87 err_msg("Card "SIZE_FORMAT" outside of card counts table (max size "SIZE_FORMAT")",
tschatzl@7051 88 card_num, _reserved_max_card_num));
tschatzl@7051 89 count = (uint) _card_counts[card_num];
tschatzl@7051 90 if (count < G1ConcRSHotCardLimit) {
tschatzl@7051 91 _card_counts[card_num] =
tschatzl@7051 92 (jubyte)(MIN2((uintx)(_card_counts[card_num] + 1), G1ConcRSHotCardLimit));
johnc@5078 93 }
johnc@5078 94 }
johnc@5078 95 return count;
johnc@5078 96 }
johnc@5078 97
johnc@5078 98 bool G1CardCounts::is_hot(uint count) {
johnc@5078 99 return (count >= G1ConcRSHotCardLimit);
johnc@5078 100 }
johnc@5078 101
johnc@5078 102 void G1CardCounts::clear_region(HeapRegion* hr) {
tschatzl@7051 103 MemRegion mr(hr->bottom(), hr->end());
tschatzl@7051 104 clear_range(mr);
tschatzl@7051 105 }
tschatzl@7051 106
tschatzl@7051 107 void G1CardCounts::clear_range(MemRegion mr) {
johnc@5078 108 if (has_count_table()) {
tschatzl@7051 109 const jbyte* from_card_ptr = _ct_bs->byte_for_const(mr.start());
tschatzl@7051 110 // We use the last address in the range as the range could represent the
tschatzl@7051 111 // last region in the heap. In which case trying to find the card will be an
tschatzl@7051 112 // OOB access to the card table.
tschatzl@7051 113 const jbyte* last_card_ptr = _ct_bs->byte_for_const(mr.last());
johnc@5078 114
johnc@5078 115 #ifdef ASSERT
johnc@5078 116 HeapWord* start_addr = _ct_bs->addr_for(from_card_ptr);
tschatzl@7051 117 assert(start_addr == mr.start(), "MemRegion start must be aligned to a card.");
johnc@5078 118 HeapWord* last_addr = _ct_bs->addr_for(last_card_ptr);
tschatzl@7051 119 assert((last_addr + CardTableModRefBS::card_size_in_words) == mr.end(), "MemRegion end must be aligned to a card.");
johnc@5078 120 #endif // ASSERT
johnc@5078 121
johnc@5078 122 // Clear the counts for the (exclusive) card range.
johnc@5078 123 size_t from_card_num = ptr_2_card_num(from_card_ptr);
johnc@5078 124 size_t to_card_num = ptr_2_card_num(last_card_ptr) + 1;
johnc@5078 125 clear_range(from_card_num, to_card_num);
johnc@5078 126 }
johnc@5078 127 }
johnc@5078 128
tschatzl@7051 129 class G1CardCountsClearClosure : public HeapRegionClosure {
tschatzl@7051 130 private:
tschatzl@7051 131 G1CardCounts* _card_counts;
tschatzl@7051 132 public:
tschatzl@7051 133 G1CardCountsClearClosure(G1CardCounts* card_counts) :
tschatzl@7051 134 HeapRegionClosure(), _card_counts(card_counts) { }
tschatzl@7051 135
tschatzl@7051 136
tschatzl@7051 137 virtual bool doHeapRegion(HeapRegion* r) {
tschatzl@7051 138 _card_counts->clear_region(r);
tschatzl@7051 139 return false;
tschatzl@7051 140 }
tschatzl@7051 141 };
tschatzl@7051 142
johnc@5078 143 void G1CardCounts::clear_all() {
johnc@5078 144 assert(SafepointSynchronize::is_at_safepoint(), "don't call this otherwise");
tschatzl@7051 145 G1CardCountsClearClosure cl(this);
tschatzl@7051 146 _g1h->heap_region_iterate(&cl);
johnc@5078 147 }

mercurial