author | tschatzl |
Fri, 29 Nov 2019 10:20:14 +0100 | |
changeset 59319 | 9ee940f1de90 |
parent 59252 | 623722a6aeb9 |
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), |
|
59319
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
35 |
_hot_cache_idx(0), _hot_cache_par_claimed_idx(0), _cache_wrapped_around(false) |
51332 | 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 |
||
59319
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
51 |
_cache_wrapped_around = false; |
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
52 |
|
26160 | 53 |
_card_counts.initialize(card_counts_storage); |
17327 | 54 |
} |
55 |
} |
|
56 |
||
57 |
G1HotCardCache::~G1HotCardCache() { |
|
58 |
if (default_use_cache()) { |
|
59 |
assert(_hot_cache != NULL, "Logic"); |
|
54110 | 60 |
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
|
61 |
_hot_cache = NULL; |
17327 | 62 |
} |
63 |
} |
|
64 |
||
54110 | 65 |
CardTable::CardValue* G1HotCardCache::insert(CardValue* card_ptr) { |
17327 | 66 |
uint count = _card_counts.add_card_count(card_ptr); |
67 |
if (!_card_counts.is_hot(count)) { |
|
68 |
// The card is not hot so do not store it in the cache; |
|
69 |
// return it for immediate refining. |
|
70 |
return card_ptr; |
|
71 |
} |
|
72 |
// Otherwise, the card is hot. |
|
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
73 |
size_t index = Atomic::add(&_hot_cache_idx, 1u) - 1; |
59319
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
74 |
if (index == _hot_cache_size) { |
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
75 |
// Can use relaxed store because all racing threads are writing the same |
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
76 |
// value and there aren't any concurrent readers. |
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
77 |
Atomic::store(&_cache_wrapped_around, true); |
9ee940f1de90
8227739: Merge cost predictions for scanning cards and log buffer entries
tschatzl
parents:
59252
diff
changeset
|
78 |
} |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
79 |
size_t masked_index = index & (_hot_cache_size - 1); |
54110 | 80 |
CardValue* current_ptr = _hot_cache[masked_index]; |
17327 | 81 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
82 |
// 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
|
83 |
// 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
|
84 |
// 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
|
85 |
// 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
|
86 |
// 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
|
87 |
// this ever happens. |
59252
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
88 |
CardValue* previous_ptr = Atomic::cmpxchg(&_hot_cache[masked_index], |
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
89 |
current_ptr, |
623722a6aeb9
8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents:
59249
diff
changeset
|
90 |
card_ptr); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
91 |
return (previous_ptr == current_ptr) ? previous_ptr : card_ptr; |
17327 | 92 |
} |
93 |
||
58264
4e96939a5746
8231189: Rename worker_i parameters to worker_id
tschatzl
parents:
58033
diff
changeset
|
94 |
void G1HotCardCache::drain(G1CardTableEntryClosure* cl, uint worker_id) { |
36374 | 95 |
assert(default_use_cache(), "Drain only necessary if we use the hot card cache."); |
17327 | 96 |
|
97 |
assert(_hot_cache != NULL, "Logic"); |
|
98 |
assert(!use_cache(), "cache should be disabled"); |
|
99 |
||
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
100 |
while (_hot_cache_par_claimed_idx < _hot_cache_size) { |
59249
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
101 |
size_t end_idx = Atomic::add(&_hot_cache_par_claimed_idx, |
29b0d0b61615
8234737: Harmonize parameter order in Atomic - add
stefank
parents:
58264
diff
changeset
|
102 |
_hot_cache_par_chunk_size); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
103 |
size_t start_idx = end_idx - _hot_cache_par_chunk_size; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
104 |
// 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
|
105 |
end_idx = MIN2(end_idx, _hot_cache_size); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
106 |
for (size_t i = start_idx; i < end_idx; i++) { |
54110 | 107 |
CardValue* card_ptr = _hot_cache[i]; |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
108 |
if (card_ptr != NULL) { |
58264
4e96939a5746
8231189: Rename worker_i parameters to worker_id
tschatzl
parents:
58033
diff
changeset
|
109 |
cl->do_card_ptr(card_ptr, worker_id); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
110 |
} else { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
111 |
break; |
17327 | 112 |
} |
113 |
} |
|
114 |
} |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
27880
diff
changeset
|
115 |
|
17327 | 116 |
// The existing entries in the hot card cache, which were just refined |
117 |
// above, are discarded prior to re-enabling the cache near the end of the GC. |
|
118 |
} |
|
119 |
||
120 |
void G1HotCardCache::reset_card_counts(HeapRegion* hr) { |
|
121 |
_card_counts.clear_region(hr); |
|
122 |
} |