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