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/dirtyCardQueue.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1HotCardCache.hpp"
29 #include "gc_implementation/g1/g1RemSet.hpp"
30 #include "gc_implementation/g1/heapRegion.hpp"
31 #include "runtime/atomic.inline.hpp"
32
33 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
34 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
35
36 void G1HotCardCache::initialize() {
37 if (default_use_cache()) {
38 _use_cache = true;
39
40 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
41 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
42
43 _n_hot = 0;
44 _hot_cache_idx = 0;
45
46 // For refining the cards in the hot cache in parallel
47 uint n_workers = (ParallelGCThreads > 0 ?
48 _g1h->workers()->total_workers() : 1);
49 _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / (int)n_workers);
50 _hot_cache_par_claimed_idx = 0;
51
52 _card_counts.initialize();
53 }
54 }
55
56 G1HotCardCache::~G1HotCardCache() {
57 if (default_use_cache()) {
58 assert(_hot_cache != NULL, "Logic");
59 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache, mtGC);
60 }
61 }
62
63 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
64 uint count = _card_counts.add_card_count(card_ptr);
65 if (!_card_counts.is_hot(count)) {
66 // The card is not hot so do not store it in the cache;
67 // return it for immediate refining.
68 return card_ptr;
69 }
70
71 // Otherwise, the card is hot.
72 jbyte* res = NULL;
118 // that we use for such cards.
119 //
120 // The only time we care about recording cards that contain
121 // references that point into the collection set is during
122 // RSet updating while within an evacuation pause.
123 // In this case worker_i should be the id of a GC worker thread
124 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
125 assert(worker_i < (ParallelGCThreads == 0 ? 1 : ParallelGCThreads),
126 err_msg("incorrect worker id: %u", worker_i));
127
128 into_cset_dcq->enqueue(card_ptr);
129 }
130 }
131 }
132 }
133 }
134 // The existing entries in the hot card cache, which were just refined
135 // above, are discarded prior to re-enabling the cache near the end of the GC.
136 }
137
138 void G1HotCardCache::resize_card_counts(size_t heap_capacity) {
139 _card_counts.resize(heap_capacity);
140 }
141
142 void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
143 _card_counts.clear_region(hr);
144 }
145
146 void G1HotCardCache::reset_card_counts() {
147 _card_counts.clear_all();
148 }
|
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/dirtyCardQueue.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1HotCardCache.hpp"
29 #include "gc_implementation/g1/g1RemSet.hpp"
30 #include "gc_implementation/g1/heapRegion.hpp"
31 #include "runtime/atomic.inline.hpp"
32
33 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
34 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
35
36 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
37 if (default_use_cache()) {
38 _use_cache = true;
39
40 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
41 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
42
43 _n_hot = 0;
44 _hot_cache_idx = 0;
45
46 // For refining the cards in the hot cache in parallel
47 uint n_workers = (ParallelGCThreads > 0 ?
48 _g1h->workers()->total_workers() : 1);
49 _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / (int)n_workers);
50 _hot_cache_par_claimed_idx = 0;
51
52 _card_counts.initialize(card_counts_storage);
53 }
54 }
55
56 G1HotCardCache::~G1HotCardCache() {
57 if (default_use_cache()) {
58 assert(_hot_cache != NULL, "Logic");
59 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache, mtGC);
60 }
61 }
62
63 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
64 uint count = _card_counts.add_card_count(card_ptr);
65 if (!_card_counts.is_hot(count)) {
66 // The card is not hot so do not store it in the cache;
67 // return it for immediate refining.
68 return card_ptr;
69 }
70
71 // Otherwise, the card is hot.
72 jbyte* res = NULL;
118 // that we use for such cards.
119 //
120 // The only time we care about recording cards that contain
121 // references that point into the collection set is during
122 // RSet updating while within an evacuation pause.
123 // In this case worker_i should be the id of a GC worker thread
124 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
125 assert(worker_i < (ParallelGCThreads == 0 ? 1 : ParallelGCThreads),
126 err_msg("incorrect worker id: %u", worker_i));
127
128 into_cset_dcq->enqueue(card_ptr);
129 }
130 }
131 }
132 }
133 }
134 // The existing entries in the hot card cache, which were just refined
135 // above, are discarded prior to re-enabling the cache near the end of the GC.
136 }
137
138 void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
139 assert(!hr->isHumongous(), "Should have been cleared");
140 _card_counts.clear_region(hr);
141 }
142
143 void G1HotCardCache::reset_card_counts() {
144 _card_counts.clear_all();
145 }
|