author | stefank |
Mon, 25 Nov 2019 12:33:15 +0100 | |
changeset 59252 | 623722a6aeb9 |
parent 59249 | 29b0d0b61615 |
child 59319 | 9ee940f1de90 |
permissions | -rw-r--r-- |
17327 | 1 |
/* |
53747
13acc8e38a29
8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents:
51332
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, 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" |
|
55752
8ae33203d600
8162929: Enqueuing dirty cards into a single DCQS during GC does not scale
kbarrett
parents:
54110
diff
changeset
|
26 |
#include "gc/g1/g1CardTableEntryClosure.hpp" |
30764 | 27 |
#include "gc/g1/g1CollectedHeap.inline.hpp" |
53747
13acc8e38a29
8218089: Rename DirtyCardQueue et al to follow usual G1 naming conventions
kbarrett
parents:
51332
diff
changeset
|
28 |
#include "gc/g1/g1DirtyCardQueue.hpp" |
30764 | 29 |
#include "gc/g1/g1HotCardCache.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
37057
diff
changeset
|
30 |
#include "runtime/atomic.hpp" |
17327 | 31 |
|
32 |
G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h): |
|
51332 | 33 |
_g1h(g1h), _use_cache(false), _card_counts(g1h), |
34 |
_hot_cache(NULL), _hot_cache_size(0), _hot_cache_par_chunk_size(0), |
|
35 |
_hot_cache_idx(0), _hot_cache_par_claimed_idx(0) |
|
36 |
{} |
|
17327 | 37 |
|
26160 | 38 |
void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) { |
17327 | 39 |
if (default_use_cache()) { |
40 |
_use_cache = true; |
|
41 |
||
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
42 |
_hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize; |
54110 | 43 |
_hot_cache = ArrayAllocator<CardValue*>::allocate(_hot_cache_size, mtGC); |
17327 | 44 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
45 |
reset_hot_cache_internal(); |
17327 | 46 |
|
47 |
// 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
|
48 |
_hot_cache_par_chunk_size = ClaimChunkSize; |
17327 | 49 |
_hot_cache_par_claimed_idx = 0; |
50 |
||
26160 | 51 |
_card_counts.initialize(card_counts_storage); |
17327 | 52 |
} |
53 |
} |
|
54 |
||
55 |
G1HotCardCache::~G1HotCardCache() { |
|
56 |
if (default_use_cache()) { |
|
57 |
assert(_hot_cache != NULL, "Logic"); |
|
54110 | 58 |
ArrayAllocator<CardValue*>::free(_hot_cache, _hot_cache_size); |
29203
5024f7b3322c
8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents:
28831
diff
changeset
|
59 |
_hot_cache = NULL; |
17327 | 60 |
} |
61 |
} |
|
62 |
||
54110 | 63 |
CardTable::CardValue* G1HotCardCache::insert(CardValue* card_ptr) { |
17327 | 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 |
// Otherwise, the card is hot. |
|
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
71 |
size_t index = Atomic::add(&_hot_cache_idx, 1u) - 1; |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
72 |
size_t masked_index = index & (_hot_cache_size - 1); |
54110 | 73 |
CardValue* current_ptr = _hot_cache[masked_index]; |
17327 | 74 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
75 |
// 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
|
76 |
// 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
|
77 |
// 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
|
78 |
// 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
|
79 |
// 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
|
80 |
// this ever happens. |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
81 |
CardValue* previous_ptr = Atomic::cmpxchg(&_hot_cache[masked_index], |
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
82 |
current_ptr, |
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
83 |
card_ptr); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
84 |
return (previous_ptr == current_ptr) ? previous_ptr : card_ptr; |
17327 | 85 |
} |
86 |
||
58264
4e96939a5746
8231189: Rename worker_i parameters to worker_id
tschatzl
parents:
58033
diff
changeset
|
87 |
void G1HotCardCache::drain(G1CardTableEntryClosure* cl, uint worker_id) { |
36374 | 88 |
assert(default_use_cache(), "Drain only necessary if we use the hot card cache."); |
17327 | 89 |
|
90 |
assert(_hot_cache != NULL, "Logic"); |
|
91 |
assert(!use_cache(), "cache should be disabled"); |
|
92 |
||
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
93 |
while (_hot_cache_par_claimed_idx < _hot_cache_size) { |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
94 |
size_t end_idx = Atomic::add(&_hot_cache_par_claimed_idx, |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
95 |
_hot_cache_par_chunk_size); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
96 |
size_t start_idx = end_idx - _hot_cache_par_chunk_size; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
97 |
// 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
|
98 |
end_idx = MIN2(end_idx, _hot_cache_size); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
99 |
for (size_t i = start_idx; i < end_idx; i++) { |
54110 | 100 |
CardValue* card_ptr = _hot_cache[i]; |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
101 |
if (card_ptr != NULL) { |
58264
4e96939a5746
8231189: Rename worker_i parameters to worker_id
tschatzl
parents:
58033
diff
changeset
|
102 |
cl->do_card_ptr(card_ptr, worker_id); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
103 |
} else { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
104 |
break; |
17327 | 105 |
} |
106 |
} |
|
107 |
} |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
108 |
|
17327 | 109 |
// The existing entries in the hot card cache, which were just refined |
110 |
// above, are discarded prior to re-enabling the cache near the end of the GC. |
|
111 |
} |
|
112 |
||
113 |
void G1HotCardCache::reset_card_counts(HeapRegion* hr) { |
|
114 |
_card_counts.clear_region(hr); |
|
115 |
} |