199 static void* make_block_from_node(BufferNode *node) { 200 return (void*)node; 201 } 202 static void** make_buffer_from_block(void* p) { 203 return (void**)((char*)p + aligned_size()); 204 } 205 static void* make_block_from_buffer(void** p) { 206 return (void*)((char*)p - aligned_size()); 207 } 208 }; 209 210 // A PtrQueueSet represents resources common to a set of pointer queues. 211 // In particular, the individual queues allocate buffers from this shared 212 // set, and return completed buffers to the set. 213 // All these variables are are protected by the TLOQ_CBL_mon. XXX ??? 214 class PtrQueueSet VALUE_OBJ_CLASS_SPEC { 215 protected: 216 Monitor* _cbl_mon; // Protects the fields below. 217 BufferNode* _completed_buffers_head; 218 BufferNode* _completed_buffers_tail; 219 int _n_completed_buffers; 220 int _process_completed_threshold; 221 volatile bool _process_completed; 222 223 // This (and the interpretation of the first element as a "next" 224 // pointer) are protected by the TLOQ_FL_lock. 225 Mutex* _fl_lock; 226 BufferNode* _buf_free_list; 227 size_t _buf_free_list_sz; 228 // Queue set can share a freelist. The _fl_owner variable 229 // specifies the owner. It is set to "this" by default. 230 PtrQueueSet* _fl_owner; 231 232 // The size of all buffers in the set. 233 size_t _sz; 234 235 bool _all_active; 236 237 // If true, notify_all on _cbl_mon when the threshold is reached. 238 bool _notify_when_complete; 239 240 // Maximum number of elements allowed on completed queue: after that, 241 // enqueuer does the work itself. Zero indicates no maximum. 242 int _max_completed_queue; 243 int _completed_queue_padding; 244 245 int completed_buffers_list_length(); 246 void assert_completed_buffer_list_len_correct_locked(); 247 void assert_completed_buffer_list_len_correct(); 248 249 protected: 250 // A mutator thread does the the work of processing a buffer. 251 // Returns "true" iff the work is complete (and the buffer may be 252 // deallocated). 253 virtual bool mut_process_buffer(void** buf) { 254 ShouldNotReachHere(); 255 return false; 256 } 257 258 // Create an empty ptr queue set. 259 PtrQueueSet(bool notify_when_complete = false); 260 ~PtrQueueSet(); 261 262 // Because of init-order concerns, we can't pass these as constructor 263 // arguments. 264 void initialize(Monitor* cbl_mon, 265 Mutex* fl_lock, 266 int process_completed_threshold, 267 int max_completed_queue, 268 PtrQueueSet *fl_owner = NULL); 269 270 public: 271 272 // Return an empty array of size _sz (required to be non-zero). 273 void** allocate_buffer(); 274 275 // Return an empty buffer to the free list. The "buf" argument is 276 // required to be a pointer to the head of an array of length "_sz". 277 void deallocate_buffer(void** buf); 278 279 // Declares that "buf" is a complete buffer. 280 void enqueue_complete_buffer(void** buf, size_t index = 0); 281 282 // To be invoked by the mutator. 283 bool process_or_enqueue_complete_buffer(void** buf); 284 285 bool completed_buffers_exist_dirty() { 286 return _n_completed_buffers > 0; 287 } 288 289 bool process_completed_buffers() { return _process_completed; } 290 void set_process_completed(bool x) { _process_completed = x; } 291 292 bool is_active() { return _all_active; } 293 294 // Set the buffer size. Should be called before any "enqueue" operation 295 // can be called. And should only be called once. 296 void set_buffer_size(size_t sz); 297 298 // Get the buffer size. 299 size_t buffer_size() { return _sz; } 300 301 // Get/Set the number of completed buffers that triggers log processing. 302 void set_process_completed_threshold(int sz) { _process_completed_threshold = sz; } 303 int process_completed_threshold() const { return _process_completed_threshold; } 304 305 // Must only be called at a safe point. Indicates that the buffer free 306 // list size may be reduced, if that is deemed desirable. 307 void reduce_free_list(); 308 309 int completed_buffers_num() { return _n_completed_buffers; } 310 311 void merge_bufferlists(PtrQueueSet* src); 312 313 void set_max_completed_queue(int m) { _max_completed_queue = m; } 314 int max_completed_queue() { return _max_completed_queue; } 315 316 void set_completed_queue_padding(int padding) { _completed_queue_padding = padding; } 317 int completed_queue_padding() { return _completed_queue_padding; } 318 319 // Notify the consumer if the number of buffers crossed the threshold 320 void notify_if_necessary(); 321 }; 322 323 #endif // SHARE_VM_GC_G1_PTRQUEUE_HPP | 199 static void* make_block_from_node(BufferNode *node) { 200 return (void*)node; 201 } 202 static void** make_buffer_from_block(void* p) { 203 return (void**)((char*)p + aligned_size()); 204 } 205 static void* make_block_from_buffer(void** p) { 206 return (void*)((char*)p - aligned_size()); 207 } 208 }; 209 210 // A PtrQueueSet represents resources common to a set of pointer queues. 211 // In particular, the individual queues allocate buffers from this shared 212 // set, and return completed buffers to the set. 213 // All these variables are are protected by the TLOQ_CBL_mon. XXX ??? 214 class PtrQueueSet VALUE_OBJ_CLASS_SPEC { 215 protected: 216 Monitor* _cbl_mon; // Protects the fields below. 217 BufferNode* _completed_buffers_head; 218 BufferNode* _completed_buffers_tail; 219 size_t _n_completed_buffers; 220 size_t _process_completed_threshold; 221 volatile bool _process_completed; 222 223 // This (and the interpretation of the first element as a "next" 224 // pointer) are protected by the TLOQ_FL_lock. 225 Mutex* _fl_lock; 226 BufferNode* _buf_free_list; 227 size_t _buf_free_list_sz; 228 // Queue set can share a freelist. The _fl_owner variable 229 // specifies the owner. It is set to "this" by default. 230 PtrQueueSet* _fl_owner; 231 232 // The size of all buffers in the set. 233 size_t _sz; 234 235 bool _all_active; 236 237 // If true, notify_all on _cbl_mon when the threshold is reached. 238 bool _notify_when_complete; 239 240 // Maximum number of elements allowed on completed queue: after that, 241 // enqueuer does the work itself. Zero indicates no maximum. 242 size_t _max_completed_queue; 243 size_t _completed_queue_padding; 244 245 size_t completed_buffers_list_length(); 246 void assert_completed_buffer_list_len_correct_locked(); 247 void assert_completed_buffer_list_len_correct(); 248 249 protected: 250 // A mutator thread does the the work of processing a buffer. 251 // Returns "true" iff the work is complete (and the buffer may be 252 // deallocated). 253 virtual bool mut_process_buffer(void** buf) { 254 ShouldNotReachHere(); 255 return false; 256 } 257 258 // Create an empty ptr queue set. 259 PtrQueueSet(bool notify_when_complete = false); 260 ~PtrQueueSet(); 261 262 // Because of init-order concerns, we can't pass these as constructor 263 // arguments. 264 void initialize(Monitor* cbl_mon, 265 Mutex* fl_lock, 266 size_t process_completed_threshold, 267 size_t max_completed_queue, 268 PtrQueueSet *fl_owner = NULL); 269 270 public: 271 272 // Return an empty array of size _sz (required to be non-zero). 273 void** allocate_buffer(); 274 275 // Return an empty buffer to the free list. The "buf" argument is 276 // required to be a pointer to the head of an array of length "_sz". 277 void deallocate_buffer(void** buf); 278 279 // Declares that "buf" is a complete buffer. 280 void enqueue_complete_buffer(void** buf, size_t index = 0); 281 282 // To be invoked by the mutator. 283 bool process_or_enqueue_complete_buffer(void** buf); 284 285 bool completed_buffers_exist_dirty() { 286 return _n_completed_buffers > 0; 287 } 288 289 bool process_completed_buffers() { return _process_completed; } 290 void set_process_completed(bool x) { _process_completed = x; } 291 292 bool is_active() { return _all_active; } 293 294 // Set the buffer size. Should be called before any "enqueue" operation 295 // can be called. And should only be called once. 296 void set_buffer_size(size_t sz); 297 298 // Get the buffer size. 299 size_t buffer_size() { return _sz; } 300 301 // Get/Set the number of completed buffers that triggers log processing. 302 void set_process_completed_threshold(size_t sz) { _process_completed_threshold = sz; } 303 size_t process_completed_threshold() const { return _process_completed_threshold; } 304 305 // Must only be called at a safe point. Indicates that the buffer free 306 // list size may be reduced, if that is deemed desirable. 307 void reduce_free_list(); 308 309 size_t completed_buffers_num() { return _n_completed_buffers; } 310 311 void merge_bufferlists(PtrQueueSet* src); 312 313 void set_max_completed_queue(size_t m) { _max_completed_queue = m; } 314 size_t max_completed_queue() { return _max_completed_queue; } 315 316 void set_completed_queue_padding(size_t padding) { _completed_queue_padding = padding; } 317 size_t completed_queue_padding() { return _completed_queue_padding; } 318 319 // Notify the consumer if the number of buffers crossed the threshold 320 void notify_if_necessary(); 321 }; 322 323 #endif // SHARE_VM_GC_G1_PTRQUEUE_HPP |