Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/g1HotCardCache.hpp @ 22903:b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
Reviewed-by: tschatzl, mgerdin
author | redestad |
---|---|
date | Thu, 29 Jan 2015 15:05:25 +0100 |
parents | ae374055ebce |
children |
rev | line source |
---|---|
10246 | 1 /* |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
10246 | 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP | |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP | |
27 | |
28 #include "gc_implementation/g1/g1_globals.hpp" | |
29 #include "gc_implementation/g1/g1CardCounts.hpp" | |
30 #include "memory/allocation.hpp" | |
31 #include "runtime/safepoint.hpp" | |
32 #include "runtime/thread.inline.hpp" | |
33 #include "utilities/globalDefinitions.hpp" | |
34 | |
35 class DirtyCardQueue; | |
36 class G1CollectedHeap; | |
37 class G1RemSet; | |
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> { | |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
57 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
58 G1CollectedHeap* _g1h; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
59 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
60 bool _use_cache; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
61 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
62 G1CardCounts _card_counts; |
10246 | 63 |
64 // The card cache table | |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
65 jbyte** _hot_cache; |
10246 | 66 |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
67 size_t _hot_cache_size; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
68 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
69 int _hot_cache_par_chunk_size; |
10246 | 70 |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
71 // Avoids false sharing when concurrently updating _hot_cache_idx or |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
72 // _hot_cache_par_claimed_idx. These are never updated at the same time |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
73 // thus it's not necessary to separate them as well |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
74 char _pad_before[DEFAULT_CACHE_LINE_SIZE]; |
10246 | 75 |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
76 volatile size_t _hot_cache_idx; |
10246 | 77 |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
78 volatile size_t _hot_cache_par_claimed_idx; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
79 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
80 char _pad_after[DEFAULT_CACHE_LINE_SIZE]; |
10246 | 81 |
22902
ae374055ebce
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
20337
diff
changeset
|
82 // The number of cached cards a thread claims when flushing the cache |
ae374055ebce
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
20337
diff
changeset
|
83 static const int ClaimChunkSize = 32; |
ae374055ebce
8053998: Hot card cache flush chunk size too coarse grained
mlarsson
parents:
20337
diff
changeset
|
84 |
10246 | 85 bool default_use_cache() const { |
86 return (G1ConcRSLogCacheSize > 0); | |
87 } | |
88 | |
89 public: | |
90 G1HotCardCache(G1CollectedHeap* g1h); | |
91 ~G1HotCardCache(); | |
92 | |
20337 | 93 void initialize(G1RegionToSpaceMapper* card_counts_storage); |
10246 | 94 |
95 bool use_cache() { return _use_cache; } | |
96 | |
97 void set_use_cache(bool b) { | |
98 _use_cache = (b ? default_use_cache() : false); | |
99 } | |
100 | |
101 // Returns the card to be refined or NULL. | |
102 // | |
103 // Increments the count for given the card. if the card is not 'hot', | |
104 // it is returned for immediate refining. Otherwise the card is | |
105 // added to the hot card cache. | |
106 // If there is enough room in the hot card cache for the card we're | |
107 // adding, NULL is returned and no further action in needed. | |
108 // If we evict a card from the cache to make room for the new card, | |
109 // the evicted card is then returned for refinement. | |
110 jbyte* insert(jbyte* card_ptr); | |
111 | |
112 // Refine the cards that have delayed as a result of | |
113 // being in the cache. | |
17844
8847586c9037
8016302: Change type of the number of GC workers to unsigned int (2)
vkempik
parents:
10246
diff
changeset
|
114 void drain(uint worker_i, G1RemSet* g1rs, DirtyCardQueue* into_cset_dcq); |
10246 | 115 |
116 // Set up for parallel processing of the cards in the hot cache | |
117 void reset_hot_cache_claimed_index() { | |
118 _hot_cache_par_claimed_idx = 0; | |
119 } | |
120 | |
121 // Resets the hot card cache and discards the entries. | |
122 void reset_hot_cache() { | |
123 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); | |
124 assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); | |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
125 if (default_use_cache()) { |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
126 reset_hot_cache_internal(); |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
127 } |
10246 | 128 } |
129 | |
130 // Zeros the values in the card counts table for entire committed heap | |
131 void reset_card_counts(); | |
132 | |
133 // Zeros the values in the card counts table for the given region | |
134 void reset_card_counts(HeapRegion* hr); | |
22903
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
135 |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
136 private: |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
137 void reset_hot_cache_internal() { |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
138 assert(_hot_cache != NULL, "Logic"); |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
139 _hot_cache_idx = 0; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
140 for (size_t i = 0; i < _hot_cache_size; i++) { |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
141 _hot_cache[i] = NULL; |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
142 } |
b6a1bf5222c5
8069273: Decrease Hot Card Cache Lock contention
redestad
parents:
22902
diff
changeset
|
143 } |
10246 | 144 }; |
145 | |
146 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP |