Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp @ 2181:d25d4ca69222
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Wed, 16 Feb 2011 13:47:20 +0100 |
parents | f95d63e2154a |
children | 02f49b66361a |
rev | line source |
---|---|
342 | 1 /* |
1705 | 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
342 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1282
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1282
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1282
diff
changeset
|
21 * questions. |
342 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTG1REFINE_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTG1REFINE_HPP | |
27 | |
28 #include "memory/allocation.hpp" | |
29 #include "memory/cardTableModRefBS.hpp" | |
30 #include "runtime/thread.hpp" | |
31 #include "utilities/globalDefinitions.hpp" | |
32 | |
342 | 33 // Forward decl |
34 class ConcurrentG1RefineThread; | |
35 class G1RemSet; | |
36 | |
549
fe3d7c11b4b7
6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents:
342
diff
changeset
|
37 class ConcurrentG1Refine: public CHeapObj { |
794 | 38 ConcurrentG1RefineThread** _threads; |
39 int _n_threads; | |
1111 | 40 int _n_worker_threads; |
41 /* | |
42 * The value of the update buffer queue length falls into one of 3 zones: | |
43 * green, yellow, red. If the value is in [0, green) nothing is | |
44 * done, the buffers are left unprocessed to enable the caching effect of the | |
45 * dirtied cards. In the yellow zone [green, yellow) the concurrent refinement | |
46 * threads are gradually activated. In [yellow, red) all threads are | |
47 * running. If the length becomes red (max queue length) the mutators start | |
48 * processing the buffers. | |
49 * | |
1282 | 50 * There are some interesting cases (when G1UseAdaptiveConcRefinement |
51 * is turned off): | |
1111 | 52 * 1) green = yellow = red = 0. In this case the mutator will process all |
53 * buffers. Except for those that are created by the deferred updates | |
54 * machinery during a collection. | |
55 * 2) green = 0. Means no caching. Can be a good way to minimize the | |
56 * amount of time spent updating rsets during a collection. | |
57 */ | |
58 int _green_zone; | |
59 int _yellow_zone; | |
60 int _red_zone; | |
61 | |
62 int _thread_threshold_step; | |
63 | |
64 // Reset the threshold step value based of the current zone boundaries. | |
65 void reset_threshold_step(); | |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
66 |
342 | 67 // The cache for card refinement. |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
68 bool _use_cache; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
69 bool _def_use_cache; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
70 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
71 size_t _n_periods; // Used as clearing epoch |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
72 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
73 // An evicting cache of the number of times each card |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
74 // is accessed. Reduces, but does not eliminate, the amount |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
75 // of duplicated processing of dirty cards. |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
76 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
77 enum SomePrivateConstants { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
78 epoch_bits = 32, |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
79 card_num_shift = epoch_bits, |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
80 epoch_mask = AllBits, |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
81 card_num_mask = AllBits, |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
82 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
83 // The initial cache size is approximately this fraction |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
84 // of a maximal cache (i.e. the size needed for all cards |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
85 // in the heap) |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
86 InitialCacheFraction = 512 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
87 }; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
88 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
89 const static julong card_num_mask_in_place = |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
90 (julong) card_num_mask << card_num_shift; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
91 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
92 typedef struct { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
93 julong _value; // | card_num | epoch | |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
94 } CardEpochCacheEntry; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
95 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
96 julong make_epoch_entry(unsigned int card_num, unsigned int epoch) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
97 assert(0 <= card_num && card_num < _max_n_card_counts, "Bounds"); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
98 assert(0 <= epoch && epoch <= _n_periods, "must be"); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
99 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
100 return ((julong) card_num << card_num_shift) | epoch; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
101 } |
342 | 102 |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
103 unsigned int extract_epoch(julong v) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
104 return (v & epoch_mask); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
105 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
106 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
107 unsigned int extract_card_num(julong v) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
108 return (v & card_num_mask_in_place) >> card_num_shift; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
109 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
110 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
111 typedef struct { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
112 unsigned char _count; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
113 unsigned char _evict_count; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
114 } CardCountCacheEntry; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
115 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
116 CardCountCacheEntry* _card_counts; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
117 CardEpochCacheEntry* _card_epochs; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
118 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
119 // The current number of buckets in the card count cache |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
120 unsigned _n_card_counts; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
121 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
122 // The max number of buckets required for the number of |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
123 // cards for the entire reserved heap |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
124 unsigned _max_n_card_counts; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
125 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
126 // Possible sizes of the cache: odd primes that roughly double in size. |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
127 // (See jvmtiTagMap.cpp). |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
128 static int _cc_cache_sizes[]; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
129 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
130 // The index in _cc_cache_sizes corresponding to the size of |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
131 // _card_counts. |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
132 int _cache_size_index; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
133 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
134 bool _expand_card_counts; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
135 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
136 const jbyte* _ct_bot; |
889 | 137 |
138 jbyte** _hot_cache; | |
139 int _hot_cache_size; | |
140 int _n_hot; | |
141 int _hot_cache_idx; | |
142 | |
143 int _hot_cache_par_chunk_size; | |
144 volatile int _hot_cache_par_claimed_idx; | |
342 | 145 |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
146 // Needed to workaround 6817995 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
147 CardTableModRefBS* _ct_bs; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
148 G1CollectedHeap* _g1h; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
149 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
150 // Expands the array that holds the card counts to the next size up |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
151 void expand_card_count_cache(); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
152 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
153 // hash a given key (index of card_ptr) with the specified size |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
154 static unsigned int hash(size_t key, int size) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
155 return (unsigned int) key % size; |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
156 } |
342 | 157 |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
158 // hash a given key (index of card_ptr) |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
159 unsigned int hash(size_t key) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
160 return hash(key, _n_card_counts); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
161 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
162 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
163 unsigned ptr_2_card_num(jbyte* card_ptr) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
164 return (unsigned) (card_ptr - _ct_bot); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
165 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
166 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
167 jbyte* card_num_2_ptr(unsigned card_num) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
168 return (jbyte*) (_ct_bot + card_num); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
169 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
170 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
171 // Returns the count of this card after incrementing it. |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
172 jbyte* add_card_count(jbyte* card_ptr, int* count, bool* defer); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
173 |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
174 // Returns true if this card is in a young region |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
175 bool is_young_card(jbyte* card_ptr); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
176 |
342 | 177 public: |
178 ConcurrentG1Refine(); | |
179 ~ConcurrentG1Refine(); | |
180 | |
181 void init(); // Accomplish some initialization that has to wait. | |
794 | 182 void stop(); |
342 | 183 |
1111 | 184 void reinitialize_threads(); |
185 | |
794 | 186 // Iterate over the conc refine threads |
187 void threads_do(ThreadClosure *tc); | |
342 | 188 |
189 // If this is the first entry for the slot, writes into the cache and | |
190 // returns NULL. If it causes an eviction, returns the evicted pointer. | |
191 // Otherwise, its a cache hit, and returns NULL. | |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
889
diff
changeset
|
192 jbyte* cache_insert(jbyte* card_ptr, bool* defer); |
342 | 193 |
194 // Process the cached entries. | |
1705 | 195 void clean_up_cache(int worker_i, G1RemSet* g1rs, DirtyCardQueue* into_cset_dcq); |
342 | 196 |
889 | 197 // Set up for parallel processing of the cards in the hot cache |
198 void clear_hot_cache_claimed_index() { | |
199 _hot_cache_par_claimed_idx = 0; | |
200 } | |
201 | |
342 | 202 // Discard entries in the hot cache. |
203 void clear_hot_cache() { | |
204 _hot_cache_idx = 0; _n_hot = 0; | |
205 } | |
206 | |
207 bool hot_cache_is_empty() { return _n_hot == 0; } | |
208 | |
209 bool use_cache() { return _use_cache; } | |
210 void set_use_cache(bool b) { | |
211 if (b) _use_cache = _def_use_cache; | |
212 else _use_cache = false; | |
213 } | |
214 | |
215 void clear_and_record_card_counts(); | |
795
215f81b4d9b3
6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents:
794
diff
changeset
|
216 |
1111 | 217 static int thread_num(); |
1019 | 218 |
219 void print_worker_threads_on(outputStream* st) const; | |
1111 | 220 |
221 void set_green_zone(int x) { _green_zone = x; } | |
222 void set_yellow_zone(int x) { _yellow_zone = x; } | |
223 void set_red_zone(int x) { _red_zone = x; } | |
224 | |
225 int green_zone() const { return _green_zone; } | |
226 int yellow_zone() const { return _yellow_zone; } | |
227 int red_zone() const { return _red_zone; } | |
228 | |
229 int total_thread_num() const { return _n_threads; } | |
230 int worker_thread_num() const { return _n_worker_threads; } | |
231 | |
232 int thread_threshold_step() const { return _thread_threshold_step; } | |
342 | 233 }; |
1972 | 234 |
235 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTG1REFINE_HPP |