< prev index next >
src/share/vm/gc/g1/ptrQueue.cpp
Print this page
rev 9216 : imported patch rename_perm
rev 9217 : imported patch rename_debug_only
rev 9219 : [mq]: access
rev 9221 : [mq]: simplify_loops
*** 28,55 ****
#include "memory/allocation.inline.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/thread.inline.hpp"
! PtrQueue::PtrQueue(PtrQueueSet* qset, bool perm, bool active) :
_qset(qset), _buf(NULL), _index(0), _sz(0), _active(active),
! _perm(perm), _lock(NULL)
{}
PtrQueue::~PtrQueue() {
! assert(_perm || (_buf == NULL), "queue must be flushed before delete");
}
void PtrQueue::flush_impl() {
! if (!_perm && _buf != NULL) {
if (_index == _sz) {
// No work to do.
qset()->deallocate_buffer(_buf);
} else {
// We must NULL out the unused entries, then enqueue.
! for (size_t i = 0; i < _index; i += oopSize) {
! _buf[byte_index_to_index((int)i)] = NULL;
}
qset()->enqueue_complete_buffer(_buf);
}
_buf = NULL;
_index = 0;
--- 28,56 ----
#include "memory/allocation.inline.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/thread.inline.hpp"
! PtrQueue::PtrQueue(PtrQueueSet* qset, bool permanent, bool active) :
_qset(qset), _buf(NULL), _index(0), _sz(0), _active(active),
! _permanent(permanent), _lock(NULL)
{}
PtrQueue::~PtrQueue() {
! assert(_permanent || (_buf == NULL), "queue must be flushed before delete");
}
void PtrQueue::flush_impl() {
! if (!_permanent && _buf != NULL) {
if (_index == _sz) {
// No work to do.
qset()->deallocate_buffer(_buf);
} else {
// We must NULL out the unused entries, then enqueue.
! size_t limit = byte_index_to_index(_index);
! for (size_t i = 0; i < limit; ++i) {
! _buf[i] = NULL;
}
qset()->enqueue_complete_buffer(_buf);
}
_buf = NULL;
_index = 0;
*** 64,75 ****
while (_index == 0) {
handle_zero_index();
}
assert(_index > 0, "postcondition");
! _index -= oopSize;
! _buf[byte_index_to_index((int)_index)] = ptr;
assert(_index <= _sz, "Invariant.");
}
void PtrQueue::locking_enqueue_completed_buffer(void** buf) {
assert(_lock->owned_by_self(), "Required.");
--- 65,76 ----
while (_index == 0) {
handle_zero_index();
}
assert(_index > 0, "postcondition");
! _index -= sizeof(void*);
! _buf[byte_index_to_index(_index)] = ptr;
assert(_index <= _sz, "Invariant.");
}
void PtrQueue::locking_enqueue_completed_buffer(void** buf) {
assert(_lock->owned_by_self(), "Required.");
*** 98,107 ****
--- 99,128 ----
_buf_free_list(NULL), _buf_free_list_sz(0)
{
_fl_owner = this;
}
+ PtrQueueSet::~PtrQueueSet() {
+ // There are presently only a couple (derived) instances ever
+ // created, and they are permanent, so no harm currently done by
+ // doing nothing here.
+ }
+
+ void PtrQueueSet::initialize(Monitor* cbl_mon,
+ Mutex* fl_lock,
+ int process_completed_threshold,
+ int max_completed_queue,
+ PtrQueueSet *fl_owner) {
+ _max_completed_queue = max_completed_queue;
+ _process_completed_threshold = process_completed_threshold;
+ _completed_queue_padding = 0;
+ assert(cbl_mon != NULL && fl_lock != NULL, "Init order issue?");
+ _cbl_mon = cbl_mon;
+ _fl_lock = fl_lock;
+ _fl_owner = (fl_owner != NULL) ? fl_owner : this;
+ }
+
void** PtrQueueSet::allocate_buffer() {
assert(_sz > 0, "Didn't set a buffer size.");
MutexLockerEx x(_fl_owner->_fl_lock, Mutex::_no_safepoint_check_flag);
if (_fl_owner->_buf_free_list != NULL) {
void** res = BufferNode::make_buffer_from_node(_fl_owner->_buf_free_list);
*** 231,241 ****
_n_completed_buffers >= _process_completed_threshold) {
_process_completed = true;
if (_notify_when_complete)
_cbl_mon->notify();
}
! debug_only(assert_completed_buffer_list_len_correct_locked());
}
int PtrQueueSet::completed_buffers_list_length() {
int n = 0;
BufferNode* cbn = _completed_buffers_head;
--- 252,262 ----
_n_completed_buffers >= _process_completed_threshold) {
_process_completed = true;
if (_notify_when_complete)
_cbl_mon->notify();
}
! DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked());
}
int PtrQueueSet::completed_buffers_list_length() {
int n = 0;
BufferNode* cbn = _completed_buffers_head;
*** 256,266 ****
"Completed buffer length is wrong.");
}
void PtrQueueSet::set_buffer_size(size_t sz) {
assert(_sz == 0 && sz > 0, "Should be called only once.");
! _sz = sz * oopSize;
}
// Merge lists of buffers. Notify the processing threads.
// The source queue is emptied as a result. The queues
// must share the monitor.
--- 277,287 ----
"Completed buffer length is wrong.");
}
void PtrQueueSet::set_buffer_size(size_t sz) {
assert(_sz == 0 && sz > 0, "Should be called only once.");
! _sz = sz * sizeof(void*);
}
// Merge lists of buffers. Notify the processing threads.
// The source queue is emptied as a result. The queues
// must share the monitor.
< prev index next >