92 _cbl_mon(NULL), _fl_lock(NULL), 93 _notify_when_complete(notify_when_complete), 94 _sz(0), 95 _completed_buffers_head(NULL), 96 _completed_buffers_tail(NULL), 97 _n_completed_buffers(0), 98 _process_completed_threshold(0), _process_completed(false), 99 _buf_free_list(NULL), _buf_free_list_sz(0) 100 { 101 _fl_owner = this; 102 } 103 104 PtrQueueSet::~PtrQueueSet() { 105 // There are presently only a couple (derived) instances ever 106 // created, and they are permanent, so no harm currently done by 107 // doing nothing here. 108 } 109 110 void PtrQueueSet::initialize(Monitor* cbl_mon, 111 Mutex* fl_lock, 112 int process_completed_threshold, 113 int max_completed_queue, 114 PtrQueueSet *fl_owner) { 115 _max_completed_queue = max_completed_queue; 116 _process_completed_threshold = process_completed_threshold; 117 _completed_queue_padding = 0; 118 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); 119 _cbl_mon = cbl_mon; 120 _fl_lock = fl_lock; 121 _fl_owner = (fl_owner != NULL) ? fl_owner : this; 122 } 123 124 void** PtrQueueSet::allocate_buffer() { 125 assert(_sz > 0, "Didn't set a buffer size."); 126 MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag); 127 if (_fl_owner->_buf_free_list != NULL) { 128 void** res = BufferNode::make_buffer_from_node(_fl_owner->_buf_free_list); 129 _fl_owner->_buf_free_list = _fl_owner->_buf_free_list->next(); 130 _fl_owner->_buf_free_list_sz--; 131 return res; 132 } else { 133 // Allocate space for the BufferNode in front of the buffer. 231 } 232 // The buffer will be enqueued. The caller will have to get a new one. 233 enqueue_complete_buffer(buf); 234 return false; 235 } 236 237 void PtrQueueSet::enqueue_complete_buffer(void** buf, size_t index) { 238 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); 239 BufferNode* cbn = BufferNode::new_from_buffer(buf); 240 cbn->set_index(index); 241 if (_completed_buffers_tail == NULL) { 242 assert(_completed_buffers_head == NULL, "Well-formedness"); 243 _completed_buffers_head = cbn; 244 _completed_buffers_tail = cbn; 245 } else { 246 _completed_buffers_tail->set_next(cbn); 247 _completed_buffers_tail = cbn; 248 } 249 _n_completed_buffers++; 250 251 if (!_process_completed && _process_completed_threshold >= 0 && 252 _n_completed_buffers >= _process_completed_threshold) { 253 _process_completed = true; 254 if (_notify_when_complete) 255 _cbl_mon->notify(); 256 } 257 DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked()); 258 } 259 260 int PtrQueueSet::completed_buffers_list_length() { 261 int n = 0; 262 BufferNode* cbn = _completed_buffers_head; 263 while (cbn != NULL) { 264 n++; 265 cbn = cbn->next(); 266 } 267 return n; 268 } 269 270 void PtrQueueSet::assert_completed_buffer_list_len_correct() { 271 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); 272 assert_completed_buffer_list_len_correct_locked(); 273 } 274 275 void PtrQueueSet::assert_completed_buffer_list_len_correct_locked() { 276 guarantee(completed_buffers_list_length() == _n_completed_buffers, 277 "Completed buffer length is wrong."); 278 } 279 280 void PtrQueueSet::set_buffer_size(size_t sz) { | 92 _cbl_mon(NULL), _fl_lock(NULL), 93 _notify_when_complete(notify_when_complete), 94 _sz(0), 95 _completed_buffers_head(NULL), 96 _completed_buffers_tail(NULL), 97 _n_completed_buffers(0), 98 _process_completed_threshold(0), _process_completed(false), 99 _buf_free_list(NULL), _buf_free_list_sz(0) 100 { 101 _fl_owner = this; 102 } 103 104 PtrQueueSet::~PtrQueueSet() { 105 // There are presently only a couple (derived) instances ever 106 // created, and they are permanent, so no harm currently done by 107 // doing nothing here. 108 } 109 110 void PtrQueueSet::initialize(Monitor* cbl_mon, 111 Mutex* fl_lock, 112 size_t process_completed_threshold, 113 size_t max_completed_queue, 114 PtrQueueSet *fl_owner) { 115 _max_completed_queue = max_completed_queue; 116 _process_completed_threshold = process_completed_threshold; 117 _completed_queue_padding = 0; 118 assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?"); 119 _cbl_mon = cbl_mon; 120 _fl_lock = fl_lock; 121 _fl_owner = (fl_owner != NULL) ? fl_owner : this; 122 } 123 124 void** PtrQueueSet::allocate_buffer() { 125 assert(_sz > 0, "Didn't set a buffer size."); 126 MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag); 127 if (_fl_owner->_buf_free_list != NULL) { 128 void** res = BufferNode::make_buffer_from_node(_fl_owner->_buf_free_list); 129 _fl_owner->_buf_free_list = _fl_owner->_buf_free_list->next(); 130 _fl_owner->_buf_free_list_sz--; 131 return res; 132 } else { 133 // Allocate space for the BufferNode in front of the buffer. 231 } 232 // The buffer will be enqueued. The caller will have to get a new one. 233 enqueue_complete_buffer(buf); 234 return false; 235 } 236 237 void PtrQueueSet::enqueue_complete_buffer(void** buf, size_t index) { 238 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); 239 BufferNode* cbn = BufferNode::new_from_buffer(buf); 240 cbn->set_index(index); 241 if (_completed_buffers_tail == NULL) { 242 assert(_completed_buffers_head == NULL, "Well-formedness"); 243 _completed_buffers_head = cbn; 244 _completed_buffers_tail = cbn; 245 } else { 246 _completed_buffers_tail->set_next(cbn); 247 _completed_buffers_tail = cbn; 248 } 249 _n_completed_buffers++; 250 251 if (!_process_completed && 252 _n_completed_buffers >= _process_completed_threshold) { 253 _process_completed = true; 254 if (_notify_when_complete) { 255 _cbl_mon->notify(); 256 } 257 } 258 DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked()); 259 } 260 261 size_t PtrQueueSet::completed_buffers_list_length() { 262 int n = 0; 263 BufferNode* cbn = _completed_buffers_head; 264 while (cbn != NULL) { 265 n++; 266 cbn = cbn->next(); 267 } 268 return n; 269 } 270 271 void PtrQueueSet::assert_completed_buffer_list_len_correct() { 272 MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); 273 assert_completed_buffer_list_len_correct_locked(); 274 } 275 276 void PtrQueueSet::assert_completed_buffer_list_len_correct_locked() { 277 guarantee(completed_buffers_list_length() == _n_completed_buffers, 278 "Completed buffer length is wrong."); 279 } 280 281 void PtrQueueSet::set_buffer_size(size_t sz) { |