author | kbarrett |
Tue, 12 Jun 2018 18:12:59 -0400 | |
changeset 50532 | a18c60527166 |
parent 47885 | 5caa1d5f74c1 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
17327 | 1 |
/* |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
37057
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, 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 |
||
30764 | 25 |
#ifndef SHARE_VM_GC_G1_G1HOTCARDCACHE_HPP |
26 |
#define SHARE_VM_GC_G1_G1HOTCARDCACHE_HPP |
|
17327 | 27 |
|
30764 | 28 |
#include "gc/g1/g1CardCounts.hpp" |
29 |
#include "gc/g1/g1_globals.hpp" |
|
17327 | 30 |
#include "memory/allocation.hpp" |
31 |
#include "runtime/safepoint.hpp" |
|
30175 | 32 |
#include "runtime/thread.hpp" |
17327 | 33 |
#include "utilities/globalDefinitions.hpp" |
34 |
||
33204
b8a3901ac5b3
8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents:
30764
diff
changeset
|
35 |
class CardTableEntryClosure; |
17327 | 36 |
class DirtyCardQueue; |
37 |
class G1CollectedHeap; |
|
38 |
class HeapRegion; |
|
39 |
||
40 |
// An evicting cache of cards that have been logged by the G1 post |
|
41 |
// write barrier. Placing a card in the cache delays the refinement |
|
42 |
// of the card until the card is evicted, or the cache is drained |
|
43 |
// during the next evacuation pause. |
|
44 |
// |
|
45 |
// The first thing the G1 post write barrier does is to check whether |
|
46 |
// the card containing the updated pointer is already dirty and, if |
|
47 |
// so, skips the remaining code in the barrier. |
|
48 |
// |
|
49 |
// Delaying the refinement of a card will make the card fail the |
|
50 |
// first is_dirty check in the write barrier, skipping the remainder |
|
51 |
// of the write barrier. |
|
52 |
// |
|
53 |
// This can significantly reduce the overhead of the write barrier |
|
54 |
// code, increasing throughput. |
|
55 |
||
56 |
class G1HotCardCache: public CHeapObj<mtGC> { |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
57 |
|
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
58 |
G1CollectedHeap* _g1h; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
59 |
|
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
60 |
bool _use_cache; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
61 |
|
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
62 |
G1CardCounts _card_counts; |
17327 | 63 |
|
29203
5024f7b3322c
8058446: G1 Hot card cache should use ArrayAllocator to allocate the cache array
tschatzl
parents:
28831
diff
changeset
|
64 |
|
17327 | 65 |
// The card cache table |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
66 |
jbyte** _hot_cache; |
17327 | 67 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
68 |
size_t _hot_cache_size; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
69 |
|
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
37057
diff
changeset
|
70 |
size_t _hot_cache_par_chunk_size; |
17327 | 71 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
72 |
// Avoids false sharing when concurrently updating _hot_cache_idx or |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
73 |
// _hot_cache_par_claimed_idx. These are never updated at the same time |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
74 |
// thus it's not necessary to separate them as well |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
75 |
char _pad_before[DEFAULT_CACHE_LINE_SIZE]; |
17327 | 76 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
77 |
volatile size_t _hot_cache_idx; |
17327 | 78 |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
79 |
volatile size_t _hot_cache_par_claimed_idx; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
80 |
|
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
81 |
char _pad_after[DEFAULT_CACHE_LINE_SIZE]; |
17327 | 82 |
|
26830
e67193c2ceda
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
26160
diff
changeset
|
83 |
// The number of cached cards a thread claims when flushing the cache |
e67193c2ceda
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
26160
diff
changeset
|
84 |
static const int ClaimChunkSize = 32; |
e67193c2ceda
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
26160
diff
changeset
|
85 |
|
33204
b8a3901ac5b3
8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents:
30764
diff
changeset
|
86 |
public: |
b8a3901ac5b3
8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents:
30764
diff
changeset
|
87 |
static bool default_use_cache() { |
17327 | 88 |
return (G1ConcRSLogCacheSize > 0); |
89 |
} |
|
90 |
||
91 |
G1HotCardCache(G1CollectedHeap* g1h); |
|
92 |
~G1HotCardCache(); |
|
93 |
||
26160 | 94 |
void initialize(G1RegionToSpaceMapper* card_counts_storage); |
17327 | 95 |
|
96 |
bool use_cache() { return _use_cache; } |
|
97 |
||
98 |
void set_use_cache(bool b) { |
|
99 |
_use_cache = (b ? default_use_cache() : false); |
|
100 |
} |
|
101 |
||
102 |
// Returns the card to be refined or NULL. |
|
103 |
// |
|
104 |
// Increments the count for given the card. if the card is not 'hot', |
|
105 |
// it is returned for immediate refining. Otherwise the card is |
|
106 |
// added to the hot card cache. |
|
107 |
// If there is enough room in the hot card cache for the card we're |
|
108 |
// adding, NULL is returned and no further action in needed. |
|
109 |
// If we evict a card from the cache to make room for the new card, |
|
110 |
// the evicted card is then returned for refinement. |
|
111 |
jbyte* insert(jbyte* card_ptr); |
|
112 |
||
113 |
// Refine the cards that have delayed as a result of |
|
114 |
// being in the cache. |
|
33204
b8a3901ac5b3
8069330: Adjustment of concurrent refinement thresholds does not take hot card cache into account
tschatzl
parents:
30764
diff
changeset
|
115 |
void drain(CardTableEntryClosure* cl, uint worker_i); |
17327 | 116 |
|
117 |
// Set up for parallel processing of the cards in the hot cache |
|
118 |
void reset_hot_cache_claimed_index() { |
|
119 |
_hot_cache_par_claimed_idx = 0; |
|
120 |
} |
|
121 |
||
122 |
// Resets the hot card cache and discards the entries. |
|
123 |
void reset_hot_cache() { |
|
124 |
assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); |
|
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33204
diff
changeset
|
125 |
assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); |
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
126 |
if (default_use_cache()) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
127 |
reset_hot_cache_internal(); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
128 |
} |
17327 | 129 |
} |
130 |
||
131 |
// Zeros the values in the card counts table for the given region |
|
132 |
void reset_card_counts(HeapRegion* hr); |
|
28831
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
133 |
|
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
134 |
private: |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
135 |
void reset_hot_cache_internal() { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
136 |
assert(_hot_cache != NULL, "Logic"); |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
137 |
_hot_cache_idx = 0; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
138 |
for (size_t i = 0; i < _hot_cache_size; i++) { |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
139 |
_hot_cache[i] = NULL; |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
140 |
} |
454224c7e3ba
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
26830
diff
changeset
|
141 |
} |
17327 | 142 |
}; |
143 |
||
30764 | 144 |
#endif // SHARE_VM_GC_G1_G1HOTCARDCACHE_HPP |