src/share/vm/gc_implementation/g1/ptrQueue.cpp

Print this page




  90   _completed_buffers_tail(NULL),
  91   _n_completed_buffers(0),
  92   _process_completed_threshold(0), _process_completed(false),
  93   _buf_free_list(NULL), _buf_free_list_sz(0)
  94 {
  95   _fl_owner = this;
  96 }
  97 
  98 void** PtrQueueSet::allocate_buffer() {
  99   assert(_sz > 0, "Didn't set a buffer size.");
 100   MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
 101   if (_fl_owner->_buf_free_list != NULL) {
 102     void** res = _fl_owner->_buf_free_list;
 103     _fl_owner->_buf_free_list = (void**)_fl_owner->_buf_free_list[0];
 104     _fl_owner->_buf_free_list_sz--;
 105     // Just override the next pointer with NULL, just in case we scan this part
 106     // of the buffer.
 107     res[0] = NULL;
 108     return res;
 109   } else {
 110     return NEW_C_HEAP_ARRAY(void*, _sz);
 111   }
 112 }
 113 
 114 void PtrQueueSet::deallocate_buffer(void** buf) {
 115   assert(_sz > 0, "Didn't set a buffer size.");
 116   MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
 117   buf[0] = (void*)_fl_owner->_buf_free_list;
 118   _fl_owner->_buf_free_list = buf;
 119   _fl_owner->_buf_free_list_sz++;
 120 }
 121 
 122 void PtrQueueSet::reduce_free_list() {
 123   // For now we'll adopt the strategy of deleting half.
 124   MutexLockerEx x(_fl_lock, Mutex::_no_safepoint_check_flag);
 125   size_t n = _buf_free_list_sz / 2;
 126   while (n > 0) {
 127     assert(_buf_free_list != NULL, "_buf_free_list_sz must be wrong.");
 128     void** head = _buf_free_list;
 129     _buf_free_list = (void**)_buf_free_list[0];
 130     FREE_C_HEAP_ARRAY(void*,head);

 131     n--;
 132   }
 133 }
 134 
 135 void PtrQueueSet::enqueue_complete_buffer(void** buf, size_t index, bool ignore_max_completed) {
 136   // I use explicit locking here because there's a bailout in the middle.
 137   _cbl_mon->lock_without_safepoint_check();
 138 
 139   Thread* thread = Thread::current();
 140   assert( ignore_max_completed ||
 141           thread->is_Java_thread() ||
 142           SafepointSynchronize::is_at_safepoint(),
 143           "invariant" );
 144   ignore_max_completed = ignore_max_completed || !thread->is_Java_thread();
 145 
 146   if (!ignore_max_completed && _max_completed_queue > 0 &&
 147       _n_completed_buffers >= (size_t) _max_completed_queue) {
 148     _cbl_mon->unlock();
 149     bool b = mut_process_buffer(buf);
 150     if (b) {




  90   _completed_buffers_tail(NULL),
  91   _n_completed_buffers(0),
  92   _process_completed_threshold(0), _process_completed(false),
  93   _buf_free_list(NULL), _buf_free_list_sz(0)
  94 {
  95   _fl_owner = this;
  96 }
  97 
  98 void** PtrQueueSet::allocate_buffer() {
  99   assert(_sz > 0, "Didn't set a buffer size.");
 100   MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
 101   if (_fl_owner->_buf_free_list != NULL) {
 102     void** res = _fl_owner->_buf_free_list;
 103     _fl_owner->_buf_free_list = (void**)_fl_owner->_buf_free_list[0];
 104     _fl_owner->_buf_free_list_sz--;
 105     // Just override the next pointer with NULL, just in case we scan this part
 106     // of the buffer.
 107     res[0] = NULL;
 108     return res;
 109   } else {
 110     return (void**) NEW_C_HEAP_ARRAY(char, _sz);
 111   }
 112 }
 113 
 114 void PtrQueueSet::deallocate_buffer(void** buf) {
 115   assert(_sz > 0, "Didn't set a buffer size.");
 116   MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
 117   buf[0] = (void*)_fl_owner->_buf_free_list;
 118   _fl_owner->_buf_free_list = buf;
 119   _fl_owner->_buf_free_list_sz++;
 120 }
 121 
 122 void PtrQueueSet::reduce_free_list() {
 123   // For now we'll adopt the strategy of deleting half.
 124   MutexLockerEx x(_fl_lock, Mutex::_no_safepoint_check_flag);
 125   size_t n = _buf_free_list_sz / 2;
 126   while (n > 0) {
 127     assert(_buf_free_list != NULL, "_buf_free_list_sz must be wrong.");
 128     void** head = _buf_free_list;
 129     _buf_free_list = (void**)_buf_free_list[0];
 130     FREE_C_HEAP_ARRAY(char, head);
 131     _buf_free_list_sz --;
 132     n--;
 133   }
 134 }
 135 
 136 void PtrQueueSet::enqueue_complete_buffer(void** buf, size_t index, bool ignore_max_completed) {
 137   // I use explicit locking here because there's a bailout in the middle.
 138   _cbl_mon->lock_without_safepoint_check();
 139 
 140   Thread* thread = Thread::current();
 141   assert( ignore_max_completed ||
 142           thread->is_Java_thread() ||
 143           SafepointSynchronize::is_at_safepoint(),
 144           "invariant" );
 145   ignore_max_completed = ignore_max_completed || !thread->is_Java_thread();
 146 
 147   if (!ignore_max_completed && _max_completed_queue > 0 &&
 148       _n_completed_buffers >= (size_t) _max_completed_queue) {
 149     _cbl_mon->unlock();
 150     bool b = mut_process_buffer(buf);
 151     if (b) {