author | kbarrett |
Wed, 15 Apr 2015 12:16:01 -0400 | |
changeset 30182 | 1c980a880941 |
parent 29203 | 5024f7b3322c |
permissions | -rw-r--r-- |
17327 | 1 |
/* |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, 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/dirtyCardQueue.hpp" |
|
27 |
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
|
28 |
#include "gc_implementation/g1/g1HotCardCache.hpp" |
|
29 |
#include "gc_implementation/g1/g1RemSet.hpp" |
|
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
23858
diff
changeset
|
30 |
#include "runtime/atomic.inline.hpp" |
17327 | 31 |
|
32 |
G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h): |
|
33 |
_g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {} |
|
34 |
||
26160 | 35 |
void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) { |
17327 | 36 |
if (default_use_cache()) { |
37 |
_use_cache = true; |
|
38 |
||
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
39 |
_hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize; |
29203
5024f7b3322c
8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents:
28831
diff
changeset
|
40 |
_hot_cache = _hot_cache_memory.allocate(_hot_cache_size); |
17327 | 41 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
42 |
reset_hot_cache_internal(); |
17327 | 43 |
|
44 |
// For refining the cards in the hot cache in parallel |
|
27251
7d667f91ec8d
6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents:
26830
diff
changeset
|
45 |
_hot_cache_par_chunk_size = ClaimChunkSize; |
17327 | 46 |
_hot_cache_par_claimed_idx = 0; |
47 |
||
26160 | 48 |
_card_counts.initialize(card_counts_storage); |
17327 | 49 |
} |
50 |
} |
|
51 |
||
52 |
G1HotCardCache::~G1HotCardCache() { |
|
53 |
if (default_use_cache()) { |
|
54 |
assert(_hot_cache != NULL, "Logic"); |
|
29203
5024f7b3322c
8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents:
28831
diff
changeset
|
55 |
_hot_cache_memory.free(); |
5024f7b3322c
8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents:
28831
diff
changeset
|
56 |
_hot_cache = NULL; |
17327 | 57 |
} |
58 |
} |
|
59 |
||
60 |
jbyte* G1HotCardCache::insert(jbyte* card_ptr) { |
|
61 |
uint count = _card_counts.add_card_count(card_ptr); |
|
62 |
if (!_card_counts.is_hot(count)) { |
|
63 |
// The card is not hot so do not store it in the cache; |
|
64 |
// return it for immediate refining. |
|
65 |
return card_ptr; |
|
66 |
} |
|
67 |
// Otherwise, the card is hot. |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
68 |
size_t index = Atomic::add(1, &_hot_cache_idx) - 1; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
69 |
size_t masked_index = index & (_hot_cache_size - 1); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
70 |
jbyte* current_ptr = _hot_cache[masked_index]; |
17327 | 71 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
72 |
// Try to store the new card pointer into the cache. Compare-and-swap to guard |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
73 |
// against the unlikely event of a race resulting in another card pointer to |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
74 |
// have already been written to the cache. In this case we will return |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
75 |
// card_ptr in favor of the other option, which would be starting over. This |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
76 |
// should be OK since card_ptr will likely be the older card already when/if |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
77 |
// this ever happens. |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
78 |
jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr, |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
79 |
&_hot_cache[masked_index], |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
80 |
current_ptr); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
81 |
return (previous_ptr == current_ptr) ? previous_ptr : card_ptr; |
17327 | 82 |
} |
83 |
||
23855
c4574075402c
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
17327
diff
changeset
|
84 |
void G1HotCardCache::drain(uint worker_i, |
17327 | 85 |
G1RemSet* g1rs, |
86 |
DirtyCardQueue* into_cset_dcq) { |
|
87 |
if (!default_use_cache()) { |
|
88 |
assert(_hot_cache == NULL, "Logic"); |
|
89 |
return; |
|
90 |
} |
|
91 |
||
92 |
assert(_hot_cache != NULL, "Logic"); |
|
93 |
assert(!use_cache(), "cache should be disabled"); |
|
94 |
||
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
95 |
while (_hot_cache_par_claimed_idx < _hot_cache_size) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
96 |
size_t end_idx = Atomic::add(_hot_cache_par_chunk_size, |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
97 |
&_hot_cache_par_claimed_idx); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
98 |
size_t start_idx = end_idx - _hot_cache_par_chunk_size; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
99 |
// The current worker has successfully claimed the chunk [start_idx..end_idx) |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
100 |
end_idx = MIN2(end_idx, _hot_cache_size); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
101 |
for (size_t i = start_idx; i < end_idx; i++) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
102 |
jbyte* card_ptr = _hot_cache[i]; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
103 |
if (card_ptr != NULL) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
104 |
if (g1rs->refine_card(card_ptr, worker_i, true)) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
105 |
// The part of the heap spanned by the card contains references |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
106 |
// that point into the current collection set. |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
107 |
// We need to record the card pointer in the DirtyCardQueueSet |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
108 |
// that we use for such cards. |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
109 |
// |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
110 |
// The only time we care about recording cards that contain |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
111 |
// references that point into the collection set is during |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
112 |
// RSet updating while within an evacuation pause. |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
113 |
// In this case worker_i should be the id of a GC worker thread |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
114 |
assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
115 |
assert(worker_i < ParallelGCThreads, |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
116 |
err_msg("incorrect worker id: %u", worker_i)); |
17327 | 117 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
118 |
into_cset_dcq->enqueue(card_ptr); |
17327 | 119 |
} |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
120 |
} else { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
121 |
break; |
17327 | 122 |
} |
123 |
} |
|
124 |
} |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
125 |
|
17327 | 126 |
// The existing entries in the hot card cache, which were just refined |
127 |
// above, are discarded prior to re-enabling the cache near the end of the GC. |
|
128 |
} |
|
129 |
||
130 |
void G1HotCardCache::reset_card_counts(HeapRegion* hr) { |
|
131 |
_card_counts.clear_region(hr); |
|
132 |
} |
|
133 |
||
134 |
void G1HotCardCache::reset_card_counts() { |
|
135 |
_card_counts.clear_all(); |
|
136 |
} |