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