Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/g1/ptrQueue.hpp @ 1111:44f61c24ddab
6862387: tune concurrent refinement further
Summary: Reworked the concurrent refinement: threads activation, feedback-based threshold adjustment, other miscellaneous fixes.
Reviewed-by: apetrusenko, tonyp
author | iveresov |
---|---|
date | Wed, 16 Dec 2009 15:12:51 -0800 |
parents | 7bb995fbd3c0 |
children | d4197f8d516a |
comparison
equal
deleted
inserted
replaced
1104:27f9477e879b | 1111:44f61c24ddab |
---|---|
25 // There are various techniques that require threads to be able to log | 25 // There are various techniques that require threads to be able to log |
26 // addresses. For example, a generational write barrier might log | 26 // addresses. For example, a generational write barrier might log |
27 // the addresses of modified old-generation objects. This type supports | 27 // the addresses of modified old-generation objects. This type supports |
28 // this operation. | 28 // this operation. |
29 | 29 |
30 // The definition of placement operator new(size_t, void*) in the <new>. | |
31 #include <new> | |
32 | |
30 class PtrQueueSet; | 33 class PtrQueueSet; |
31 | |
32 class PtrQueue VALUE_OBJ_CLASS_SPEC { | 34 class PtrQueue VALUE_OBJ_CLASS_SPEC { |
33 | 35 |
34 protected: | 36 protected: |
35 // The ptr queue set to which this queue belongs. | 37 // The ptr queue set to which this queue belongs. |
36 PtrQueueSet* _qset; | 38 PtrQueueSet* _qset; |
75 void enqueue(void* ptr) { | 77 void enqueue(void* ptr) { |
76 if (!_active) return; | 78 if (!_active) return; |
77 else enqueue_known_active(ptr); | 79 else enqueue_known_active(ptr); |
78 } | 80 } |
79 | 81 |
80 inline void handle_zero_index(); | 82 void handle_zero_index(); |
81 void locking_enqueue_completed_buffer(void** buf); | 83 void locking_enqueue_completed_buffer(void** buf); |
82 | 84 |
83 void enqueue_known_active(void* ptr); | 85 void enqueue_known_active(void* ptr); |
84 | 86 |
85 size_t size() { | 87 size_t size() { |
124 } | 126 } |
125 static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); } | 127 static ByteSize byte_width_of_active() { return in_ByteSize(sizeof(bool)); } |
126 | 128 |
127 }; | 129 }; |
128 | 130 |
131 class BufferNode { | |
132 size_t _index; | |
133 BufferNode* _next; | |
134 public: | |
135 BufferNode() : _index(0), _next(NULL) { } | |
136 BufferNode* next() const { return _next; } | |
137 void set_next(BufferNode* n) { _next = n; } | |
138 size_t index() const { return _index; } | |
139 void set_index(size_t i) { _index = i; } | |
140 | |
141 // Align the size of the structure to the size of the pointer | |
142 static size_t aligned_size() { | |
143 static const size_t alignment = round_to(sizeof(BufferNode), sizeof(void*)); | |
144 return alignment; | |
145 } | |
146 | |
147 // BufferNode is allocated before the buffer. | |
148 // The chunk of memory that holds both of them is a block. | |
149 | |
150 // Produce a new BufferNode given a buffer. | |
151 static BufferNode* new_from_buffer(void** buf) { | |
152 return new (make_block_from_buffer(buf)) BufferNode; | |
153 } | |
154 | |
155 // The following are the required conversion routines: | |
156 static BufferNode* make_node_from_buffer(void** buf) { | |
157 return (BufferNode*)make_block_from_buffer(buf); | |
158 } | |
159 static void** make_buffer_from_node(BufferNode *node) { | |
160 return make_buffer_from_block(node); | |
161 } | |
162 static void* make_block_from_node(BufferNode *node) { | |
163 return (void*)node; | |
164 } | |
165 static void** make_buffer_from_block(void* p) { | |
166 return (void**)((char*)p + aligned_size()); | |
167 } | |
168 static void* make_block_from_buffer(void** p) { | |
169 return (void*)((char*)p - aligned_size()); | |
170 } | |
171 }; | |
172 | |
129 // A PtrQueueSet represents resources common to a set of pointer queues. | 173 // A PtrQueueSet represents resources common to a set of pointer queues. |
130 // In particular, the individual queues allocate buffers from this shared | 174 // In particular, the individual queues allocate buffers from this shared |
131 // set, and return completed buffers to the set. | 175 // set, and return completed buffers to the set. |
132 // All these variables are are protected by the TLOQ_CBL_mon. XXX ??? | 176 // All these variables are are protected by the TLOQ_CBL_mon. XXX ??? |
133 class PtrQueueSet VALUE_OBJ_CLASS_SPEC { | 177 class PtrQueueSet VALUE_OBJ_CLASS_SPEC { |
134 | |
135 protected: | 178 protected: |
136 | |
137 class CompletedBufferNode: public CHeapObj { | |
138 public: | |
139 void** buf; | |
140 size_t index; | |
141 CompletedBufferNode* next; | |
142 CompletedBufferNode() : buf(NULL), | |
143 index(0), next(NULL){ } | |
144 }; | |
145 | |
146 Monitor* _cbl_mon; // Protects the fields below. | 179 Monitor* _cbl_mon; // Protects the fields below. |
147 CompletedBufferNode* _completed_buffers_head; | 180 BufferNode* _completed_buffers_head; |
148 CompletedBufferNode* _completed_buffers_tail; | 181 BufferNode* _completed_buffers_tail; |
149 size_t _n_completed_buffers; | 182 int _n_completed_buffers; |
150 size_t _process_completed_threshold; | 183 int _process_completed_threshold; |
151 volatile bool _process_completed; | 184 volatile bool _process_completed; |
152 | 185 |
153 // This (and the interpretation of the first element as a "next" | 186 // This (and the interpretation of the first element as a "next" |
154 // pointer) are protected by the TLOQ_FL_lock. | 187 // pointer) are protected by the TLOQ_FL_lock. |
155 Mutex* _fl_lock; | 188 Mutex* _fl_lock; |
156 void** _buf_free_list; | 189 BufferNode* _buf_free_list; |
157 size_t _buf_free_list_sz; | 190 size_t _buf_free_list_sz; |
158 // Queue set can share a freelist. The _fl_owner variable | 191 // Queue set can share a freelist. The _fl_owner variable |
159 // specifies the owner. It is set to "this" by default. | 192 // specifies the owner. It is set to "this" by default. |
160 PtrQueueSet* _fl_owner; | 193 PtrQueueSet* _fl_owner; |
161 | 194 |
168 bool _notify_when_complete; | 201 bool _notify_when_complete; |
169 | 202 |
170 // Maximum number of elements allowed on completed queue: after that, | 203 // Maximum number of elements allowed on completed queue: after that, |
171 // enqueuer does the work itself. Zero indicates no maximum. | 204 // enqueuer does the work itself. Zero indicates no maximum. |
172 int _max_completed_queue; | 205 int _max_completed_queue; |
206 int _completed_queue_padding; | |
173 | 207 |
174 int completed_buffers_list_length(); | 208 int completed_buffers_list_length(); |
175 void assert_completed_buffer_list_len_correct_locked(); | 209 void assert_completed_buffer_list_len_correct_locked(); |
176 void assert_completed_buffer_list_len_correct(); | 210 void assert_completed_buffer_list_len_correct(); |
177 | 211 |
189 PtrQueueSet(bool notify_when_complete = false); | 223 PtrQueueSet(bool notify_when_complete = false); |
190 | 224 |
191 // Because of init-order concerns, we can't pass these as constructor | 225 // Because of init-order concerns, we can't pass these as constructor |
192 // arguments. | 226 // arguments. |
193 void initialize(Monitor* cbl_mon, Mutex* fl_lock, | 227 void initialize(Monitor* cbl_mon, Mutex* fl_lock, |
194 int max_completed_queue = 0, | 228 int process_completed_threshold, |
229 int max_completed_queue, | |
195 PtrQueueSet *fl_owner = NULL) { | 230 PtrQueueSet *fl_owner = NULL) { |
196 _max_completed_queue = max_completed_queue; | 231 _max_completed_queue = max_completed_queue; |
232 _process_completed_threshold = process_completed_threshold; | |
233 _completed_queue_padding = 0; | |
197 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); | 234 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); |
198 _cbl_mon = cbl_mon; | 235 _cbl_mon = cbl_mon; |
199 _fl_lock = fl_lock; | 236 _fl_lock = fl_lock; |
200 _fl_owner = (fl_owner != NULL) ? fl_owner : this; | 237 _fl_owner = (fl_owner != NULL) ? fl_owner : this; |
201 } | 238 } |
206 // Return an empty buffer to the free list. The "buf" argument is | 243 // Return an empty buffer to the free list. The "buf" argument is |
207 // required to be a pointer to the head of an array of length "_sz". | 244 // required to be a pointer to the head of an array of length "_sz". |
208 void deallocate_buffer(void** buf); | 245 void deallocate_buffer(void** buf); |
209 | 246 |
210 // Declares that "buf" is a complete buffer. | 247 // Declares that "buf" is a complete buffer. |
211 void enqueue_complete_buffer(void** buf, size_t index = 0, | 248 void enqueue_complete_buffer(void** buf, size_t index = 0); |
212 bool ignore_max_completed = false); | 249 |
250 // To be invoked by the mutator. | |
251 bool process_or_enqueue_complete_buffer(void** buf); | |
213 | 252 |
214 bool completed_buffers_exist_dirty() { | 253 bool completed_buffers_exist_dirty() { |
215 return _n_completed_buffers > 0; | 254 return _n_completed_buffers > 0; |
216 } | 255 } |
217 | 256 |
218 bool process_completed_buffers() { return _process_completed; } | 257 bool process_completed_buffers() { return _process_completed; } |
258 void set_process_completed(bool x) { _process_completed = x; } | |
219 | 259 |
220 bool active() { return _all_active; } | 260 bool active() { return _all_active; } |
221 | 261 |
222 // Set the buffer size. Should be called before any "enqueue" operation | 262 // Set the buffer size. Should be called before any "enqueue" operation |
223 // can be called. And should only be called once. | 263 // can be called. And should only be called once. |
224 void set_buffer_size(size_t sz); | 264 void set_buffer_size(size_t sz); |
225 | 265 |
226 // Get the buffer size. | 266 // Get the buffer size. |
227 size_t buffer_size() { return _sz; } | 267 size_t buffer_size() { return _sz; } |
228 | 268 |
229 // Set the number of completed buffers that triggers log processing. | 269 // Get/Set the number of completed buffers that triggers log processing. |
230 void set_process_completed_threshold(size_t sz); | 270 void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; } |
271 int process_completed_threshold() const { return _process_completed_threshold; } | |
231 | 272 |
232 // Must only be called at a safe point. Indicates that the buffer free | 273 // Must only be called at a safe point. Indicates that the buffer free |
233 // list size may be reduced, if that is deemed desirable. | 274 // list size may be reduced, if that is deemed desirable. |
234 void reduce_free_list(); | 275 void reduce_free_list(); |
235 | 276 |
236 size_t completed_buffers_num() { return _n_completed_buffers; } | 277 int completed_buffers_num() { return _n_completed_buffers; } |
237 | 278 |
238 void merge_bufferlists(PtrQueueSet* src); | 279 void merge_bufferlists(PtrQueueSet* src); |
239 void merge_freelists(PtrQueueSet* src); | 280 |
281 void set_max_completed_queue(int m) { _max_completed_queue = m; } | |
282 int max_completed_queue() { return _max_completed_queue; } | |
283 | |
284 void set_completed_queue_padding(int padding) { _completed_queue_padding = padding; } | |
285 int completed_queue_padding() { return _completed_queue_padding; } | |
286 | |
287 // Notify the consumer if the number of buffers crossed the threshold | |
288 void notify_if_necessary(); | |
240 }; | 289 }; |